RE: [xsl] Using a reference in a sort

Subject: RE: [xsl] Using a reference in a sort
From: Américo Albuquerque <melinor@xxxxxxx>
Date: Tue, 29 Jul 2003 16:59:51 +0100
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: [xsl] 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