Reputation: 1448
I have following xml
<?xml version="1.0"?>
<root>
<element>
<prop>
<value>1</value>
</prop>
<prop>
<value>1</value>
</prop>
<prop>
<value>2</value>
</prop>
</element>
</root>
How can I refer to ANY <prop>
element in match?
I can do for example something like
<xsl:template match="element[prop[3][value != 2]]"/>
but I need something like
<xsl:template match="element[prop[ANY][value != 2]]"/>
UPD
Example:
<root>
<Product>
<somefield>123</somefield>
<ProductIdentifier>
<ProductIDType>01</ProductIDType>
<IDTypeName>Some ID</IDTypeName>
<IDValue>964067</IDValue>
</ProductIdentifier>
<ProductIdentifier>
<ProductIDType>01</ProductIDType>
<IDTypeName>Good</IDTypeName>
<IDValue>25</IDValue>
</ProductIdentifier>
</Product>
<Product>
<somefield>123</somefield>
<ProductIdentifier>
<ProductIDType>01</ProductIDType>
<IDTypeName>Some ID</IDTypeName>
<IDValue>964067</IDValue>
</ProductIdentifier>
<ProductIdentifier>
<ProductIDType>01</ProductIDType>
<IDTypeName>Good</IDTypeName>
<IDValue>11</IDValue>
</ProductIdentifier>
</Product>
<Product>
<somefield>123</somefield>
<ProductIdentifier>
<ProductIDType>01</ProductIDType>
<IDTypeName>Some ID</IDTypeName>
<IDValue>964067</IDValue>
</ProductIdentifier>
<ProductIdentifier>
<ProductIDType>01</ProductIDType>
<IDTypeName>Good</IDTypeName>
<IDValue>26</IDValue>
</ProductIdentifier>
</Product>
</root>
As can be seen there are few ProductIdentifier tags in Product. I want to get ONLY products with IDValue = 25 OR IDValue = 26 in IDTypeName = Good
So the result xml will be
<root>
<Product>
<somefield>123</somefield>
<ProductIdentifier>
<ProductIDType>01</ProductIDType>
<IDTypeName>Some ID</IDTypeName>
<IDValue>964067</IDValue>
</ProductIdentifier>
<ProductIdentifier>
<ProductIDType>01</ProductIDType>
<IDTypeName>Good</IDTypeName>
<IDValue>25</IDValue>
</ProductIdentifier>
</Product>
<Product>
<somefield>123</somefield>
<ProductIdentifier>
<ProductIDType>01</ProductIDType>
<IDTypeName>Some ID</IDTypeName>
<IDValue>964067</IDValue>
</ProductIdentifier>
<ProductIdentifier>
<ProductIDType>01</ProductIDType>
<IDTypeName>Good</IDTypeName>
<IDValue>26</IDValue>
</ProductIdentifier>
</Product>
</root>
Upvotes: 1
Views: 119
Reputation: 117165
I want to get ONLY products with IDValue = 25 OR IDValue = 26 in IDTypeName = Good
As you have learned in your other question, it is best to start with the indentity transform template, and exclude the nodes that do not satisfy the condition:
XSLT 1.0
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/>
<xsl:strip-space elements="*"/>
<!-- identity transform -->
<xsl:template match="@*|node()">
<xsl:copy>
<xsl:apply-templates select="@*|node()"/>
</xsl:copy>
</xsl:template>
<xsl:template match="Product[not(ProductIdentifier[(IDValue=25 or IDValue=26) and IDTypeName='Good'])]"/>
</xsl:stylesheet>
Upvotes: 1