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
Windows Server 2008 Creating Folders Issue
Insert into ... where problems
Background image trick with frames isn't working for me!
print only certain rows in Excel 2003
Migrating WSUS repository directory into different drive
Selecting VBA Frame changes Parent Frame Scroll position
Search onLoad events in entire organization
Exchange and iPhone
Natting
Hide submit button if datalist control is empty