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
Printing Tab Forms
Formating Columns in SQL Server 2005
Cisco Unity Call Handlers
Multiple <html> Tags in Page?
VMware VCenter 4.0 inline upgrade into 4.1 in production
Calling Events and Event Handlers in Java
What is a "standard" tv dvd extension?
What is the best and safe way to change network IP range
C# raw classes
Why is IE not processing my CSS?