Monday, 29 September 2014



I am trying to use to sort nodes based on a particular element that can be at any lower level within the XML tree.


Say I have the following XML structure:



<Concepts>
<Concept>
<Type>C</Type>
</Concept>

<Concept>
<Type>A</Type>
</Concept>

<Concept>
<OR>
<Type>B</Type>
</OR>
<OR>
<Type>B</Type>
</OR>
</Concept>
</Concepts>


Note that any <Type> within a <Concept> will be of the same value, as in the case of <Type>B</Type>.


I tried to use the following XSLT1.0 code, but to no avail:



<xsl:template match="/">
<ul>
<xsl:for-each select="Concepts/Concept">
<xsl:sort select="//Type"/>
<li><xsl:value-of select="."/></li>
</xsl:for-each>
</ul>
</xsl:template>


The resulting output is:



  • C

  • A

  • B B


and I was hoping for:



  • A

  • B B

  • C


No comments:

Post a Comment