[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

RE: Strange Sort...

Subject: RE: Strange Sort...
From: "Jarno Elovirta" <jarno@xxxxxxxxxxxxxx>
Date: Thu, 20 Jul 2000 07:15:13 +0300
strange objects for sale
hi

> <bucket>
> 	<object id="first" x="35" y="10" />
> 	<object id="second" x="15" y="58" />
> 	<subbucket>
> 		<object>
> 			<id>third</id>
> 			<x>28</x>
> 			<y>145</y>
> 		</object>
> 	</subbucket>
> 	<object id="fourth" x="65" y="27" />
> </bucket>

[...]
 
> I'd like to be able to sort all four objects based on the value 
> of their "y"s, regardless of whether they are a child or an 
> attribute.  Is that possible?  Doing two sorts, with one being 

is this what you want?

[c:\temp]type nicky.xml
<?xml version="1.0" encoding="UTF-8" ?>
<bucket>
        <object id="first" x="35" y="10" />
        <object id="second" x="15" y="58" />
        <subbucket>
                <object>
                        <id>third</id>
                        <x>28</x>
                        <y>145</y>
                </object>
        </subbucket>
        <object id="fourth" x="65" y="27" />
</bucket>

[c:\temp]type nicky.xsl
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0"
                xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

<xsl:output method="xml"
            indent="yes" />

<xsl:template match="bucket">
  <xsl:copy>
    <xsl:apply-templates select="*">
      <xsl:sort select="@y | object/y" data-type="number" />
    </xsl:apply-templates>
  </xsl:copy>
</xsl:template>

<xsl:template match="object | subbucket">
  <xsl:copy-of select="." />
</xsl:template>

</xsl:stylesheet>

[c:\temp]saxon nicky.xml nicky.xsl
<?xml version="1.0" encoding="utf-8" ?>
<bucket>
   <object id="first" x="35" y="10"/>
   <object id="fourth" x="65" y="27"/>
   <object id="second" x="15" y="58"/>
   <subbucket>
      <object>
         <id>third</id>
         <x>28</x>
         <y>145</y>
      </object>
   </subbucket>
</bucket>
[c:\temp]

hope this does what you needed

--
Jarno Elovirta     jarno.elovirta@xxxxxxxxxxxxxx
CODEONLINE Ltd.    http://www.codeonline.com
P.O. Box 538 (Ukonvaaja 2 A), FIN-02130 Espoo, Finland
Mobile: +358 40 747 5572 Fax: +358 9 4393 0410

"Hoc non credo; toga mea surrepta est iterum!"


 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list


Current Thread

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-2013 All Rights Reserved.