Reputation: 87
I have an xml file with a certain node ( parentNode in this case ) and I want to know how many specialNode has no childNode having a certain attribute.
Example:
<parentNode>
<specialNode>
<childNode attrib=true />
<childNode attrib=false />
</specialNode>
<specialNode>
<childNode attrib=true />
<childNode attrib=true />
</specialNode>
<specialNode>
<childNode attrib=false />
</specialNode>
</parentNode>
I would like to call something like :
<xsl:variable="foo" select="count( not( */specialNode/childNode[ attrib="true" ] ) ) />
... and to have foo = 1 because there is only one specialNode where all its child node has attrib = false.
Is there a way to do this?
Upvotes: 1
Views: 464
Reputation: 808
count(/parentNode/specialNode[not(childNode[@attrib='true'])])
Here is the corrected XML
<parentNode>
<specialNode>
<childNode attrib="false"/>
<childNode attrib="false"/>
</specialNode>
<specialNode>
<childNode attrib="true"/>
<childNode attrib="true"/>
</specialNode>
<specialNode>
<childNode attrib="false"/>
</specialNode>
</parentNode>
Upvotes: 1