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 July 28th, 2009, 07:33 AM
Authorized User
 
Join Date: Jan 2009
Posts: 36
Thanks: 3
Thanked 0 Times in 0 Posts
Default sorting issue

I am trying to sort an xml file except one particular node which should always appear on the top.

Example input xml

<Data>
<object>1</object>
<a></a>
<c></c>
<l>
 
Old July 28th, 2009, 07:39 AM
Authorized User
 
Join Date: Jan 2009
Posts: 36
Thanks: 3
Thanked 0 Times in 0 Posts
Default

sorry didn't post the question in full.

Input xml

<Data>
<object>1</object>
<agent>C</agent>
<productCode>S</productCode>
<dateRequired>0</dateRequired>
<
paymentMethod>
<object>131</object>
<paymentTypeId/>
<numberOfInstallments>0</numberOfInstallments>
</paymentMethod>
</Data>

Output xml should be

<Data>
<object>1</object>
<agent>C</agent>
<dateRequired>0</dateRequired>
<paymentMethod>
<object>131</object>
<numberOfInstallments>0</numberOfInstallments>
<paymentTypeId/>
</paymentMethod>
<productCode>S</productCode>
</Data>

all the nodes should be sorted except objectID

any ideas ?

Thanks
 
Old July 28th, 2009, 07:39 AM
Friend of Wrox
 
Join Date: Nov 2007
Posts: 1,243
Thanks: 0
Thanked 245 Times in 244 Posts
Default

Consider to post some sample input XML and the corresponding output XML you want the stylesheet to create.
That "example input xml" you have shown is too short and has nothing but one element with data (<object>1</object>) that at least I have no idea which data you want to sort and which not.
__________________
Martin Honnen
Microsoft MVP (XML, Data Platform Development) 2005/04 - 2013/03
My blog
 
Old July 28th, 2009, 07:45 AM
Friend of Wrox
 
Join Date: Nov 2007
Posts: 1,243
Thanks: 0
Thanked 245 Times in 244 Posts
Default

Here is a sample stylesheet that sorts all child elements except the 'object' element on the element name:
Code:
<xsl:stylesheet
  xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  version="1.0">
  
  <xsl:output indent="yes"/>
  
  <xsl:template match="*[*]">
    <xsl:copy>
      <xsl:copy-of select="object"/>
      <xsl:apply-templates select="*[not(self::object)]">
        <xsl:sort select="name()"/>
      </xsl:apply-templates>
    </xsl:copy>
  </xsl:template>
  
  <xsl:template match="*[not(*)]">
    <xsl:copy-of select="."/>
  </xsl:template>

</xsl:stylesheet>
__________________
Martin Honnen
Microsoft MVP (XML, Data Platform Development) 2005/04 - 2013/03
My blog
The Following User Says Thank You to Martin Honnen For This Useful Post:
nguna (July 28th, 2009)





Similar Threads
Thread Thread Starter Forum Replies Last Post
sorting issue JohnBampton XSLT 10 February 23rd, 2009 08:13 AM
sorting issue moin.khan Struts 0 June 21st, 2007 09:37 AM
SORTING pallone XSLT 3 October 29th, 2006 08:45 AM
Sorting sunny76 Excel VBA 2 September 19th, 2005 09:31 PM
Datagrid sorting by non alphabetical sorting? LLAndy VS.NET 2002/2003 1 July 15th, 2004 01:20 AM





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