Answer the question
In order to leave comments, you need to log in
How to loop through a non-nested XML structure?
How in XSL to display such a set of tags one by one through a loop? Tags can be unlimited.
<main>
<tag ROWNUM="1">Олег</tag>
<tag ROWNUM="2">Виктор</tag>
<tag ROWNUM="3">Денис</tag>
<tag ROWNUM="4">Кирилл</tag>
<tag ROWNUM="1">Олегович</tag>
<tag ROWNUM="2">Викторович</tag>
<tag ROWNUM="3">Денисович3</tag>
<tag ROWNUM="4">Кириллович</tag>
</main>
Answer the question
In order to leave comments, you need to log in
I asked myself - I answered it myself =) With stackoverflow
XSLT 1.0. Three options.
Following-sibling is used twice, which is ugly and wasteful.
<xsl:for-each select="//tag[@ROWNUM = following-sibling::tag/@ROWNUM]">
<name>
<xsl:value-of select="."/>
<xsl:variable name="rownum" select="@ROWNUM"/>
<xsl:value-of select="./following-sibling::tag[@ROWNUM = $rownum]"/>
</name>
</xsl:for-each>
<xsl:for-each select="//tag[@ROWNUM = following-sibling::tag/@ROWNUM]/@ROWNUM">
<name>
<xsl:for-each select="key('num', .)">
<xsl:value-of select="."/>
</xsl:for-each>
</name>
</xsl:for-each>
<xsl:for-each select="//tag[@ROWNUM = following-sibling::tag/@ROWNUM]/@ROWNUM">
<name>
<xsl:value-of select="key('num', .)[1]"/>
<xsl:value-of select="key('num', .)[2]"/>
</name>
</xsl:for-each>
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question