[XQuery Talk Mailing List Archive Home] [By Date] [By Thread] [By Subject] [By Author] [Recent Entries] [Reply To This Message]

reversing element ordering, with a caveat

G. Ken Holman gkholman at CraneSoftwrights.com
Mon Mar 16 08:37:32 PST 2009


  reversing element ordering
At 2009-03-15 18:04 -0700, Howard Katz wrote:
>I'd be happy to see a solution either in XQuery or in XSLT. Here's some
>sample input and the output.

Below, Howard, is a solution in XSLT.  Note that the XSLT 
specification defaults access to the source node tree in document 
order, so there is no need for the portable provisions I commented on 
regarding XQuery.

I hope this helps.

. . . . . . . . . Ken

t:\ftemp>type howard.xml
<library>
         <book pubYear='1942' catid='1' >
                 <otherStuff /></book>
         <book pubYear='1942' catid='2' >
                 <otherStuff /></book>
         <book pubYear='1942' catid=' 3 ' >
                 <otherStuff /></book>
         ...

         <book pubYear='2009' catid=' 2011' >
                 <otherStuff /></book>
         <book pubYear='2009' catid=' 2012 ' >
                 <otherStuff /></book>
         <book pubYear='2009' catid=' 2013 ' >
                 <otherStuff /></book>
</library>

t:\ftemp>xslt howard.xml howard.xsl
<?xml version="1.0" encoding="utf-8"?>
<library>
    <book pubYear="2009" catid=" 2011">

       <otherStuff/>
    </book>
    <book pubYear="2009" catid=" 2012 ">

       <otherStuff/>
    </book>
    <book pubYear="2009" catid=" 2013 ">

       <otherStuff/>
    </book>
    <book pubYear="1942" catid="1">

       <otherStuff/>
    </book>
    <book pubYear="1942" catid="2">

       <otherStuff/>
    </book>
    <book pubYear="1942" catid=" 3 ">

       <otherStuff/>
    </book>
</library>
t:\ftemp>type howard.xsl
<?xml version="1.0" encoding="US-ASCII"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
                 version="2.0">

<xsl:output indent="yes"/>

<xsl:template match="/">
   <library>
     <xsl:for-each select="library/book">
       <xsl:sort select="@pubYear" order="descending"/>
       <xsl:copy-of select="."/>
     </xsl:for-each>
   </library>
</xsl:template>

</xsl:stylesheet>

t:\ftemp>

--
XQuery/XSLT/XSL-FO training in Los Angeles (New dates!) 2009-06-08
Training tools: Comprehensive interactive XSLT/XPath 1.0/2.0 video
Video lesson:    http://www.youtube.com/watch?v=PrNjJCh7Ppg&fmt=18
Video overview:  http://www.youtube.com/watch?v=VTiodiij6gE&fmt=18
G. Ken Holman                 mailto:http://x-query.com/mailman/listinfo/talk
Crane Softwrights Ltd.          http://www.CraneSoftwrights.com/q/
Male Cancer Awareness Nov'07  http://www.CraneSoftwrights.com/q/bc
Legal business disclaimers:  http://www.CraneSoftwrights.com/legal



PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2007 All Rights Reserved.