I would like to sort the following XML file based on the displayposition.
I am printing the value and displayname.
Here is the XML File I have used:
<?xml version="1.0"?>
<o>
<com>
<hereyougo>
<first displayposition="4"
displayname="raman4">4</first>
<second displayposition="1"
displayname="raman1">1</second>
<third displayposition="3"
displayname="raman3">3</third>
<fourth displayposition="2"
displayname="raman2">2</fourth>
</hereyougo>
<imaycome>
<four displayposition="4"
displayname="raman4">22</four>
<five displayposition="1"
displayname="raman1">33</five>
<six displayposition="3"
displayname="raman3">44</six>
<firvi displayposition="2"
displayname="raman2">11</firvi>
</imaycome>
</com>
</o>
This is the output I expect:
raman1 1 33
raman2 2 11
raman3 3 44
raman4 4 22
The o/p I am getting:
raman1 4 22
raman2 1 33
raman3 3 44
raman4 2 11
The XSL File I used to process This :
<?xml version="1.0"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="html" indent="yes" />
<xsl:template match="/">
<table>
<xsl:variable name="y" select="o/com/*" />
<xsl:for-each select="$y[1]/*">
<xsl:sort select="@displayposition"/>
<xsl:variable name="x" select="position()" />
<tr>
<th>
<xsl:value-of select="@displayname"/>
</th>
<xsl:for-each select="$y/*[position() = $x]">
<xsl:sort select="@displayposition"/>
<td>
<xsl:value-of select="." />
</td>
</xsl:for-each>
</tr>
</xsl:for-each>
</table>
</xsl:template>
</xsl:stylesheet>
Possible Error:
<xsl:sort select="@displayposition"/> in the second <xsl:for-each > is not
working.
Pls help me out.
thanks and regards,
sundar
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list