Microsoft
Software
Hardware
Network
Question : Why does this xslt sort not work?
HI,
I have an XSLT that was succesfully sorting an xml file I had created by hand. However, now I am manipulating the XML in code (C#, Net framework 3.5), and when I apply the XSLT transformation, the sort no longer works. I suspect its something to do with the encoding Im using (?). Can anyone shed any light?
the XML:
<ROOT ID="1" TYPE="TUTORIAL" TITLE="Darren test tutorial" IMAGE="./images/TUTORIAL.g
if"
POSITION="0"><ITEM ID="2" TYPE="TOPIC" TITLE="Topic 2" IMAGE="./images/TOPIC.gif"
POSITION="1"></ITEM><ITEM ID="1" TYPE="TOPIC" TITLE="Topic 1" IMAGE="./images/TOPIC.gif"
POSITION="0"><ITEM ID="1" TYPE="PAGE" TITLE="New Page" IMAGE="./images/PAGE.gif"
POSITION="0"></ITEM><ITEM ID="1" TYPE="QPAGE" TITLE="A Question" IMAGE="./images/QPAGE.gif"
POSITION="1"></ITEM></ITEM
></ROOT>
The XSLT:
<?xml version="1.0" encoding="utf-16"?>
<xsl:stylesheet xmlns:xsl="
http://www.w3.o
rg/1999/XS
L/Transfor
m
"
version="1.0">
<xsl:template match="ROOT">
<ROOT>
<xsl:attribute name="ID">
<xsl:value-of select="@ID"/>
</xsl:attribute>
<xsl:attribute name="TYPE">
<xsl:value-of select="@TYPE"/>
</xsl:attribute>
<xsl:attribute name="TITLE">
<xsl:value-of select="@TITLE"/>
</xsl:attribute>
<xsl:attribute name="IMAGE">
<xsl:value-of select="@IMAGE"/>
</xsl:attribute>
<xsl:attribute name="POSITION">
<xsl:value-of select="@POSITION"/>
</xsl:attribute>
<xsl:apply-templates mode="getItems" >
<xsl:sort select="@position" data-type="number" order="ascending"/>
</xsl:apply-templates>
</ROOT>
</xsl:template>
<xsl:template match="ITEM" mode="getItems">
<ITEM>
<xsl:attribute name="ID">
<xsl:value-of select="@ID"/>
</xsl:attribute>
<xsl:attribute name="TYPE">
<xsl:value-of select="@TYPE"/>
</xsl:attribute>
<xsl:attribute name="TITLE">
<xsl:value-of select="@TITLE"/>
</xsl:attribute>
<xsl:attribute name="IMAGE">
<xsl:value-of select="@IMAGE"/>
</xsl:attribute>
<xsl:attribute name="POSITION">
<xsl:value-of select="@POSITION"/>
</xsl:attribute>
<xsl:apply-templates mode="getItems" >
<xsl:sort select="@position" data-type="number" order="ascending"/>
</xsl:apply-templates>
</ITEM>
</xsl:template>
</xsl:stylesheet>
Answer : Why does this xslt sort not work?
XSLT is case-sensitive language. Since the attribute POSITION is uppercased in the XML it should be uppercased in the XSLT:
<xsl:sort select="@POSITION" data-type="number" order="ascending"/>
Random Solutions
Need excel formula
Changing the Install Dir in a MST\MSI
Internal communication of VirtualPC 2007
Dropdown box background-color not working only on Safari on MAC
php and mysql
Error Opening VBScript Connection to MySQL DB
How do I fix a slightly blurry TV 2709W?
SQL Connection error
Need help get introduced to Developer Tools inside IE8
Trouble with the dependesnt select boxs