I have been trying to solve one problem in XSLT, which is reaching the child node of a particular parent node, regardless of it is order in that parent.
lets imagine that we have an xml file:
<book>
<id>
<type>
<name name="something">
--SomeText
</name>
</type>
<id>
</book>
<book>
<name name="something">
<name>
<id>
--SomeNodes--
</id>
<number>
</number>
</book>
The idea here is that I have many of these node set and each of them have different order of the <name>
node.
What I want is, regardless of this order, each time I match with book node, I should be able to get the value of <name>
node.
XSLT:
<xsl:template match="book">
<xsl:param name="rule" select="//name[1]>
<xsl:copy>
<xsl:apply-templates select="@* | node()"/>
</xsl:copy>
<xsl:if test=name/@name>
<xsl:comment><xsl:value-of select="concat('some text', substring($rule,2,4))"/>
</xsl:if>
</xsl:template>
So, with this approach obviously I get the all results of node because of "//".
If I change it to name[1] without "//" then, It only finds the first name element right after the book, but not the others.
How to get recursively each time when I match with and exact same node value and write it's value as a comment after the template.
NOTE: I give you the example as XML but I am transforming from XSLT-XSLT.