XML structure that I'm currently dealing with :
<A>
<B>
<C>
<D attribute1="testAttr1" attribute2="testAttr2"/>
<D attribute1="testAttr1_2" attribute2="testAttr2_2"/>
<D attribute1="testAttr1_3" attribute2="testAttr2_3"/>
</C>
</B>
</A>
I haveto write XSL:if
condition which should be passed if any of the D child nodes attribute2 contains a string "Attr" something like below :
<xsl:if test="contains(A/B/C/*D/@attribute2,'Attr')">
</xsl:if>
Above condition isn't working. If I remove * and try xsl:if test="contains(A/B/C/D/@attribute2,'Attr')"
It will work only if first D child attribute2 contains the given String.
How to make it work even if any of the D child attribute2 contains the string ( say 2nd D or 3rd) .
CodePudding user response:
Use e.g. <xsl:if test="//D[contains(@attribute2, 'Attr')]">
or <xsl:if test="//D/@attribute2[contains(., 'Attr')]">
.