<node>
<node1><node11/></node1>
<node2/>
</node>
I want my XSLT to check
<xsl:if test="If at least 1 child node exists">
Only node1 can pass the if condition
</xsl:if>
Thanks for any reply.
Firstly, be careful with your terminology here. Do you mean "node" or do you mean "element". A node can be an element, comment, text or processing-instruction.
Anyway, if you do mean element here, to check at least one child element exists, you can just do this (assuming you are positioned on the node element in this case.
<xsl:if test="*">
Your comment suggests only "node1" can pass the if condition, so to check the existence of a specific element, do this
<xsl:if test="node1">
In the context of the node you are testing, this should work to test whether a node has child elements:
<xsl:if test="*">
Only node1 can pass the if condition
</xsl:if>
If you actually meant nodes (which would include text nodes), then this would work to include text nodes:
<xsl:if test="node()">
Only node1 can pass the if condition
</xsl:if>
But <node>
would also pass this test (<node2>
wouldn't). I assumed you were only speaking in the context of <node>
's child nodes, but perhaps not?
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With