Given the following input:
XML
<root> <tfLink01>Link #2</tfLink01> <mOrder>2</mOrder> <tfText01 /> <cfSM1>false</cfSM1> <tf1SLink01 /> <tf1SText01 /> <tf2SLink01 /> <tf2SText01 /> <tf3SLink01 /> <tf3SText01 /> <tfLink02>Link #1</tfLink02> <mOrder>1</mOrder> <tfText02 /> <cfSM2>false</cfSM2> <tf1SLink02 /> <tf1SText02 /> <tf2SLink02 /> <tf2SText02 /> <tf3SLink02 /> <tf3SText02 /> <tfLink03>Link #3</tfLink03> <mOrder>3</mOrder> <tfText03 /> <cfSM3>false</cfSM3> <tf1SLink03 /> <tf1SText03 /> <tf2SLink03 /> <tf2SText03 /> <tf3SLink03 /> <tf3SText03 /> </root>
following style:
XSLT 1.0
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl:output method="xml" omit-xml-declaration="yes" version="1.0" encoding="utf-8" indent="yes"/> <xsl:template match="/root"> <ul> <xsl:for-each select="mOrder"> <xsl:sort/> <li> <xsl:value-of select="preceding-sibling::*[1]"/> </li> </xsl:for-each> </ul> </xsl:template> </xsl:stylesheet>
will return:
<ul> <li>Link #1</li> <li>Link #2</li> <li>Link #3</li> </ul>
Note :
You can write the serial number in a variable, for example:
<xsl:variable name="ordinal" select="substring-after(name(preceding-sibling::*[1]), 'tfLink')" />
and use it to address additional nodes by their name, and not by their position in the "block".
Added:
For input, where the mOrder nodes mOrder also numbered, that is:
XML
<root> <tfLink01>Link #2</tfLink01> <mOrder1>2</mOrder1> <tfText01 /> <cfSM1>false</cfSM1> <tf1SLink01 /> <tf1SText01 /> <tf2SLink01 /> <tf2SText01 /> <tf3SLink01 /> <tf3SText01 /> <tfLink02>Link #1</tfLink02> <mOrder2>1</mOrder2> <tfText02 /> <cfSM2>false</cfSM2> <tf1SLink02 /> <tf1SText02 /> <tf2SLink02 /> <tf2SText02 /> <tf3SLink02 /> <tf3SText02 /> <tfLink03>Link #3</tfLink03> <mOrder3>3</mOrder3> <tfText03 /> <cfSM3>false</cfSM3> <tf1SLink03 /> <tf1SText03 /> <tf2SLink03 /> <tf2SText03 /> <tf3SLink03 /> <tf3SText03 /> </root>
you can use:
<xsl:template match="/root"> <ul> <xsl:for-each select="*[starts-with(name(), 'tfLink')]"> <xsl:sort select="following-sibling::*[1]"/> <li> <xsl:value-of select="."/> </li> </xsl:for-each> </ul> </xsl:template>
source share