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

Re: dynamic sort using attributes

Subject: Re: dynamic sort using attributes
From: Florent Georges <darkman_spam@xxxxxxxx>
Date: Tue, 5 Dec 2006 11:09:24 +0100 (CET)
dynamic sort
L P wrote:

  Hi

>   <reminders>
>     <reminder category="Test" nm="XXX" description="foobar"/>
>   <reminder category="Test12" nm="yyy" description="barfoo"/>
>    </reminders>

> I would like to sort the xml file based on the attribute
> which will be supplied as a parameter.

  If I understand correctly, the user give the name of an attribute as
parameter, and this name is used to identify the attribute to use to
sort.  For example:

  If it is correct, you can look at the following.  Be aware this is
not namespace-aware!  Depending on your requirements and how you launch
the transformation, you can use a xs:QName instead of a xs:string.

    (drkm)[119] ~/xslt/tests$ cat lp.xsl
    <xsl:stylesheet
        xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
        xmlns:xs="http://www.w3.org/2001/XMLSchema"
        version="2.0">

      <xsl:output omit-xml-declaration="yes" indent="yes"/>

      <xsl:param name="sort.attribute.name" as="xs:string"
                 select="'description'"/>

      <xsl:template match="node()|@*">
        <xsl:copy>
          <xsl:apply-templates select="node()|@*"/>
        </xsl:copy>
      </xsl:template>

      <xsl:template match="reminders">
        <xsl:copy>
          <xsl:apply-templates select="reminder">
            <xsl:sort select="
                @*[local-name() eq $sort.attribute.name]"/>
          </xsl:apply-templates>
        </xsl:copy>
      </xsl:template>

    </xsl:stylesheet>

    (drkm)[120] ~/xslt/tests$ cat lp.xml
    <reminders>
      <reminder category="Test" nm="XXX" description="foobar"/>
      <reminder category="Test12" nm="yyy" description="barfoo"/>
      <reminder category="01Test" nm="xxx" description="foofoo"/>
    </reminders>

    (drkm)[121] ~/xslt/tests$ saxon lp.xml lp.xsl
    <reminders>
       <reminder category="Test12" nm="yyy" description="barfoo"/>
       <reminder category="Test" nm="XXX" description="foobar"/>
       <reminder category="01Test" nm="xxx" description="foofoo"/>
    </reminders>

    (drkm)[122] ~/xslt/tests$ saxon lp.xml lp.xsl \
                                sort.attribute.name=nm
    <reminders>
       <reminder category="Test" nm="XXX" description="foobar"/>
       <reminder category="01Test" nm="xxx" description="foofoo"/>
       <reminder category="Test12" nm="yyy" description="barfoo"/>
    </reminders>

    (drkm)[123] ~/xslt/tests$ saxon lp.xml lp.xsl \
                                sort.attribute.name=category
    <reminders>
       <reminder category="01Test" nm="xxx" description="foofoo"/>
       <reminder category="Test" nm="XXX" description="foobar"/>
       <reminder category="Test12" nm="yyy" description="barfoo"/>
    </reminders>

    (drkm)[124] ~/xslt/tests$

  Regards,

--drkm
























	

	
		
___________________________________________________________________________ 
Yahoo! Mail riinvente le mail ! Dicouvrez le nouveau Yahoo! Mail et son interface rivolutionnaire.
http://fr.mail.yahoo.com

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