By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,955 Members | 1,477 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,955 IT Pros & Developers. It's quick & easy.

xsl:sort - where am I going wrong??

P: n/a
I'm hoping someone can help me with what looks like a very simple problem. My
output does not sort the languages alphabetically as I would expect. Can
someone inspect my XSLT please? TIA!!
XML:
<?xml version="1.0" ?>
<Markets>
<Market name="US">
<Language name="English (US)" LCID="1033" LangCode="en-US"
PSname="English" />
</Market>
<Market name="Australia">
<Language name="English (Australia)" LCID="1033" LangCode="en-AU"
PSname="English" />
</Market>
<Market name="Canada">
<Language name="English (Canada)" LCID="1033" LangCode="en-CA"
PSname="English" />
<Language name="French (Canada)" LCID="1036" LangCode="fr-CA"
PSname="French" />
</Market>
<Market name="UK">
<Language name="English (UK)" LCID="1033" LangCode="en-GB"
PSname="English" />
</Market>
<Market name="Hong-Kong">
<Language name="English (Hong-Kong)" LCID="1033" LangCode="en-HK"
PSname="English" />
<Language name="Chinese/T (Hong-Kong)" LCID="1028" LangCode="zh-HK"
PSname="Chinese (Hong Kong)" />
</Market>
<Market name="India">
<Language name="English (India)" LCID="1033" LangCode="en-IN"
PSname="English" />
</Market>
<Market name="Indonesia">
<Language name="English (Indonesia)" LCID="1033" LangCode="en-ID"
PSname="English" />
</Market>
</Markets>

XSL:
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

<xsl:template match="Markets">
<Markets>
<xsl:apply-templates select="Market"/>
</Markets>
</xsl:template>
<xsl:template match="Market">
<xsl:apply-templates select="Language">
<xsl:sort select="@name"/>
</xsl:apply-templates>
</xsl:template>

<xsl:template match="Language">
<Language>
<xsl:attribute name="name">
<xsl:value-of select="@name"/>
</xsl:attribute>
</Language>
</xsl:template>
</xsl:stylesheet>

Output:
<?xml version="1.0" encoding="utf-8"?>
<Markets>
<Language name="English (US)" />
<Language name="English (Australia)" />
<Language name="English (Canada)" />
<Language name="French (Canada)" />
<Language name="English (UK)" />
<Language name="Chinese/T (Hong-Kong)" />
<Language name="English (Hong-Kong)" />
<Language name="English (India)" />
<Language name="English (Indonesia)" />
</Markets>
Aug 7 '07 #1
Share this Question
Share on Google+
1 Reply


P: n/a
Hi,

You're sorting the languages within a market, which since there is only one
per market, is not doing much. Try moving the sort to within
<xsl:apply-templates select="Market"/earlier on. Then sort on @name or
Language/@name depending on which name you're trying to sort on.

Hope that helps!
Priscilla
-------------------------------------------------------------------------
Priscilla Walmsley http://www.datypic.com
Author, Definitive XML Schema / XML in Office 2003
Definitive XQuery (coming in 2006)
-------------------------------------------------------------------------

"Illustris" <Il*******@discussions.microsoft.comwrote in message
news:7C**********************************@microsof t.com...
I'm hoping someone can help me with what looks like a very simple problem.
My
output does not sort the languages alphabetically as I would expect. Can
someone inspect my XSLT please? TIA!!
XML:
<?xml version="1.0" ?>
<Markets>
<Market name="US">
<Language name="English (US)" LCID="1033" LangCode="en-US"
PSname="English" />
</Market>
<Market name="Australia">
<Language name="English (Australia)" LCID="1033" LangCode="en-AU"
PSname="English" />
</Market>
<Market name="Canada">
<Language name="English (Canada)" LCID="1033" LangCode="en-CA"
PSname="English" />
<Language name="French (Canada)" LCID="1036" LangCode="fr-CA"
PSname="French" />
</Market>
<Market name="UK">
<Language name="English (UK)" LCID="1033" LangCode="en-GB"
PSname="English" />
</Market>
<Market name="Hong-Kong">
<Language name="English (Hong-Kong)" LCID="1033" LangCode="en-HK"
PSname="English" />
<Language name="Chinese/T (Hong-Kong)" LCID="1028" LangCode="zh-HK"
PSname="Chinese (Hong Kong)" />
</Market>
<Market name="India">
<Language name="English (India)" LCID="1033" LangCode="en-IN"
PSname="English" />
</Market>
<Market name="Indonesia">
<Language name="English (Indonesia)" LCID="1033" LangCode="en-ID"
PSname="English" />
</Market>
</Markets>

XSL:
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

<xsl:template match="Markets">
<Markets>
<xsl:apply-templates select="Market"/>
</Markets>
</xsl:template>
<xsl:template match="Market">
<xsl:apply-templates select="Language">
<xsl:sort select="@name"/>
</xsl:apply-templates>
</xsl:template>

<xsl:template match="Language">
<Language>
<xsl:attribute name="name">
<xsl:value-of select="@name"/>
</xsl:attribute>
</Language>
</xsl:template>
</xsl:stylesheet>

Output:
<?xml version="1.0" encoding="utf-8"?>
<Markets>
<Language name="English (US)" />
<Language name="English (Australia)" />
<Language name="English (Canada)" />
<Language name="French (Canada)" />
<Language name="English (UK)" />
<Language name="Chinese/T (Hong-Kong)" />
<Language name="English (Hong-Kong)" />
<Language name="English (India)" />
<Language name="English (Indonesia)" />
</Markets>

Aug 7 '07 #2

This discussion thread is closed

Replies have been disabled for this discussion.