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
VB Script: Output specific text from text file
Using a select box instead of tabs to change content of div
Nortel BCM50 wiring schematic
Simple? Visual Studio
Problem Installing Generic Text Printer
Hyperlink in Word Document
Which facility to select within Windows environment
URL Rewrite Rule
Excel VBA: isolate text in parentheses
Why do the icons on the the desktop go about a quarter inch off the monitor screen.