473,395 Members | 1,495 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

xsl:sort - where am I going wrong??

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
1 4150
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Jarle Presttun | last post by:
Hi, Sometimes I display values by combining information from different sections in the xml, like I do with gradeText in the student template bellow. Is it possible to sort on gradeText when I...
1
by: Derek Tinney | last post by:
Hi, I'm having difficulty building an XLST file that allows me to sort a list of log records. I put together an XSL file that allows me to output a copy of the input file and then I attempted...
2
by: R | last post by:
Hello everybody. I was sorting all my XML data with for-each and sort. But there were few cases that I didn't want to sort my data. so I added nosort attribute - if given and set to '1' don't...
6
by: Mark Miller | last post by:
I have a scheduled job that uses different XSL templates to transform XML and save it to disk. I am having problems with the code below. The problem shows up on both my development machine (Windows...
1
by: aerotops | last post by:
Hi, I am trying to sort something using XSLT. I am going to give examples. Original.xml <Root> <Car> <Name>Ford</Name> <DealerRating>3</DealerRating>
2
by: jobooker | last post by:
I'm having issues sorting. The short description is, how do I set the select attribute of xsl:sort to be the value of an xsl:variable? The longer description follows: What I want to do is to be...
3
by: davisford | last post by:
Hi, If I have something like this: <parents> <parent name="foo"> <children> <child>fred</child> <child>barney</child> <child>wilma</child>
2
by: ajc308 | last post by:
I have an XML document that looks like the following: <root name="PlanRepository"> <directory name="connoraj"> <directory name="single_run1"> <file>insidebox.txt</file> ...
7
by: otis | last post by:
Hi all, This is a small issue to make things prettier, but we all know how important that can be! I had an xsl:if to check if a node was the last one in a collection of nodes and if it was a...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.