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

Re: Problem with Sorting Elements When using "document

Subject: Re: Problem with Sorting Elements When using "document()" to bring in multiple files
From: "G. Ken Holman" <gkholman@xxxxxxxxxxxxxxxxxxxx>
Date: Wed, 03 Dec 2003 10:25:44 -0500
sorting elements in list box
At 2003-12-03 14:46 +0000, Dominic Lisi wrote:
i have this problem, when i try to sort elements which are comming from external files.

Sorting works on the current node list, so you must divine an expression in which all of the nodes to be sorted are selected *at one time* into the current node list.


i have a masterfile.xml which contains multiple tags like the following:

<taxpayer file="A004.xml" id="A004"/>

the file reference links to an XML file which contains all the individuals data for example:

<taxpayer id="A004">
   <name>
       <family>Random_1</family>
       <given>Made_Uo_Dude</given>
   </name>
</taxpayer>

Not a problem with the above, except that your stylesheet approach you described did not consider the current node list. Also, you are resolving your relative URI values in the document() function relative to your stylesheet, and I'm guessing you want them resolved relative to your data, so I changed that as well.


Try the following:

   <xsl:template match="/">
      <alpha-list>
         <xsl:apply-templates select="document( list/taxpayer/@file, . )/
                                      taxpayer">
           <xsl:sort select="name"/>
         </xsl:apply-templates/>
      </alpha-list>
   </xsl:template>

The above will push all of your individual taxpayer nodes in sorted order by the text value of the name node (the concatenation of its descendent text nodes ... that's what you implied by your post).

The reason this works is that the document function will return the root nodes of *all* of the documents addressed by *each* of the nodes passed in the first argument, thus supplying you with a single current node list with all the nodes to be sorted.

I hope this helps.

............................... Ken

--
Next public European delivery:  3-day XSLT/2-day XSL-FO 2004-01-??
Instructor-led on-site corporate, government & user group training
for XSLT and XSL-FO world-wide:  please contact us for the details

G. Ken Holman                 mailto:gkholman@xxxxxxxxxxxxxxxxxxxx
Crane Softwrights Ltd.          http://www.CraneSoftwrights.com/s/
Box 266, Kars, Ontario CANADA K0A-2E0    +1(613)489-0999 (F:-0995)
ISBN 0-13-065196-6                       Definitive XSLT and XPath
ISBN 0-13-140374-5                               Definitive XSL-FO
ISBN 1-894049-08-X   Practical Transformation Using XSLT and XPath
ISBN 1-894049-11-X               Practical Formatting Using XSL-FO
Member of the XML Guild of Practitioners:     http://XMLGuild.info
Male Breast Cancer Awareness  http://www.CraneSoftwrights.com/s/bc


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.