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

RE: Using a reference in a sort

Subject: RE: Using a reference in a sort
From: Américo Albuquerque <melinor@xxxxxxx>
Date: Tue, 29 Jul 2003 16:59:51 +0100
xsl sort variable
Hi.

> -----Original Message-----
> From: owner-xsl-list@xxxxxxxxxxxxxxxxxxxxxx 
> [mailto:owner-xsl-list@xxxxxxxxxxxxxxxxxxxxxx] On Behalf Of 
> Jesse M. Heines
> Sent: Tuesday, July 29, 2003 11:45 AM
> To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
> Subject:  Using a reference in a sort
> 
> 
> I am trying to sort data based on an externally referred to 
> value.  My main XML file looks like this:
> 
>     <task>
>       <person id="p001">
>         ...
>       </person>
>     </task>
> 
> p001 refers to a person in another file structured like this:
> 
>     <people>
>       <person id="p001" last="Heines" first="Jesse">
>         ...
>       </person>
>     </people>
> 
> I can get at that person's last name by defining a variable 
> to point to the file:
> 
>     <xsl:variable name="filePeople" select="string('people.xml')" />
> 
> and then using that variable inside a template using an xsl:value-of:
> 
>   <xsl:value-of 
> select="document($filePeople)/people/person[@id=$strPersonID]/
> @last" />
> 
> (where $strPersonID is the ID extracted from the main XML file).
> 
> What I can't seem to be able to do is sort using this field.
> 
>     <xsl:apply-templates select="tasks/task">
>       <xsl:sort 
>  
> select="document($filePeople)/people/person[@id=$strPersonID]/@last" 
>           order="descending" />

Try <xsl:sort
select="document($filePeople)/people/person[@id=current()/person/@id]/@last"
order="descending"/> instead

>     </xsl:apply-templates>> 
> The problem is that one must use variables due to the context 
> node switching in this long XPath statement, but XSL won't 
> let me use xsl:variable inside an xsl:apply-templates 
> statement.  The variable must be defined inside the 
> xsl:apply-templates tag so that it changes with each recursion.
> 
> I tried using xsl:for-each, which does allow xsl:variable 
> inside it, but only *after* xsl:sort, so that doesn't work either.
> 
> I would appreciate any suggestions anyone can make to address 
> these issues.
> 
> Thank you,
> Jesse Heines, heines@xxxxxxxxxx
> UMass Lowell Computer Science
> 
> 
> 
> 
>  XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
> 
> 
> 



 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.