Wrox Programmer Forums
Go Back   Wrox Programmer Forums > XML > XML
|
XML General XML discussions.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the XML 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 September 20th, 2005, 09:31 AM
Authorized User
 
Join Date: Jun 2003
Posts: 57
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to Kabe
Default sorting xml (database output)

hi

have this xml:

<TR>
<TD height="20">ABC Categories</TD>
<TD>VASC_Customer_Orders_Production</TD>
</TR>

<TR>
<TD height="20">ABC Categories</TD>
<TD>VASC_Product_HistoryAndForecast</TD>
</TR>

<TR>
<TD height="20">ABC Categories replacing</TD>
<TD>PASC_Supersessions</TD>
</TR>

<TR>
<TD height="20">Absence</TD>
<TD>Rental Europe Universe</TD>
</TR>

<TR>
<TD height="20">Absence</TD>
<TD>REO_SELA</TD>
</TR>

<TR>
<TD height="20">Absence / day</TD>
<TD>Rental Europe Universe</TD>
</TR>

how to get an output sorted on the first TD?
Thus result should be:

ABC Categories:
-VASC_Customer_Orders_Production
-VASC_Product_HistoryAndForecast

ABC Categories replacing:
-PASC_Supersessions

Absence:
-Rental Europe Universe
-REO_SELA

Absence / day:
-Rental Europe Universe
 
Old September 20th, 2005, 06:24 PM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

Use something like

<xsl:for-each select="TR">
  <xsl:sort select="TD[1]"/>
  <xsl:value-of select="TD[1]"/>:
  <xsl:value-of select="TD[2]"/>
</xsl:for-each>

There's no guarantee that "ABC" will sort before "absence" - this depends on the collating sequence used by the processor. XSLT 1.0 gives you very little control over this, XSLT 2.0 gives you more but the details are processor-dependent.

Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference
 
Old September 21st, 2005, 03:17 AM
Authorized User
 
Join Date: Jun 2003
Posts: 57
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to Kabe
Default

the muenchian method helped me better. found it after looking around for a while.

for those who don't know Muenchian sorting method:
http://www.jenitennison.com/xslt/gro...muenchian.html

grzz, kristof





Similar Threads
Thread Thread Starter Forum Replies Last Post
how to see xml output in IE? anboss XSLT 1 August 29th, 2008 05:16 PM
Sorting XML in a dropdown list Hughesie78 ADO.NET 1 November 23rd, 2007 08:09 AM
Sorting DataTable output EaglePM ASP.NET 2.0 Basics 1 May 18th, 2006 10:42 PM
XML output prashantnair XML 6 June 9th, 2004 12:22 AM
XML to HTML Table with Sorting and Distinct VictorMk XSLT 4 April 23rd, 2004 06:29 PM





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