Wrox Programmer Forums
Go Back   Wrox Programmer Forums > XML > XSLT
|
XSLT General questions and answers about XSLT. For issues strictly specific to the book XSLT 1.1 Programmers Reference, please post to that forum instead.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the XSLT section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old February 24th, 2010, 05:01 PM
Registered User
 
Join Date: Apr 2009
Posts: 9
Thanks: 2
Thanked 0 Times in 0 Posts
Question Sort Descending?

Hi Folks -

I'm trying to get my head around sorting in XSL but I'm obviously doing something wrong. I've looked at a BUNCH of examples in books as well as on the web to no avail. I have the following sample XML document with 3 identifiers that need to be sorted in descending order as though they were numeric:

Code:
<OrderResponse xmlns="urn:cidx:names:specification:ces:schema:all:5:0" Version="5.0">
<ResponseStatus>
<ResponseStatusReasonIdentifier Agency="RAPIDResponseRejectionTable">091</ResponseStatusReasonIdentifier>
<ResponseStatusReasonDescription></ResponseStatusReasonDescription>
</ResponseStatus>
<ResponseStatus>
<ResponseStatusReasonIdentifier Agency="RAPIDResponseRejectionTable">092</ResponseStatusReasonIdentifier>
<ResponseStatusReasonDescription></ResponseStatusReasonDescription>
</ResponseStatus>
<ResponseStatus>
<ResponseStatusReasonIdentifier Agency="RAPIDResponseRejectionTable">099</ResponseStatusReasonIdentifier>
<ResponseStatusReasonDescription></ResponseStatusReasonDescription>
</ResponseStatus>
</OrderResponse>
My stylesheet is the following:
Code:
<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="text"/>
<xsl:template match="OrderResponse">
<xsl:for-each select="ResponseStatus">
<xsl:sort select="ResponseStatusReasonIdentifier" data-type="number" order="descending"/>
<xsl:copy-of select="."/>
</xsl:for-each>
</xsl:template>
</xsl:stylesheet>


What I expected to happen was for the transformation to output 099,092,091 - what I get is 091,092,099 which is document order. What have I screwed up?

Thanks!
 
Old February 24th, 2010, 05:22 PM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

Are you sure your template is even being invoked? Because your input elements are in a namespace, and you make no attempt to match the namespace. Google for XSLT default namespace. I suspect the stylesheet is just applying the default template rules, which output the text nodes from the source document. That wouldn't account for the commas in your output but I can't see where they are supposed to come from anyway.
__________________
Michael Kay
http://www.saxonica.com/
Author, XSLT 2.0 and XPath 2.0 Programmer\'s Reference
The Following User Says Thank You to mhkay For This Useful Post:
BobSSC (February 25th, 2010)
 
Old February 25th, 2010, 03:53 PM
Registered User
 
Join Date: Apr 2009
Posts: 9
Thanks: 2
Thanked 0 Times in 0 Posts
Default Sort Descending?

Thanks Michael -

I did get quite an education in namespaces and understand why my sort wouldn't work. Removing the namespace declaration from the XML snippet allowed the sort process to work correctly.

Sorry about the commas - they weren't meant to confuse. I thought it might be clearer to list the current and expected output as comma separated values but I can see how adding the commas might create some confusion.

Thanks Again For Your Help -

Bob





Similar Threads
Thread Thread Starter Forum Replies Last Post
Dynamic sort order or sort datatype kapy_kal XSLT 2 September 18th, 2007 02:10 PM
how to sort cross tab.sort based on row total joxa83 Crystal Reports 7 March 2nd, 2006 09:12 AM
Unable to sort using xsl sort command sly_jimmy_boy XSLT 3 June 17th, 2005 05:15 AM
Sort ascending and descending bertcox XSLT 1 May 17th, 2004 05:36 AM
Descending order Query problem dssachdeva SQL Language 1 September 17th, 2003 11:44 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.