xsl-list
[Top] [All Lists]

Re: [xsl] sort elements in external document

2007-05-15 05:53:18
On 5/15/07, Vaduvoiu Tiberiu <vaduvoiutibi(_at_)yahoo(_dot_)com> wrote:
I want to sort an xml document by data from an external document. Let me see if 
I can explain this: I have list.xml:

<list>
    <file>file1.xml</file>
    <file>file2.xml</file>
...
    <file>file100.xml</file>
<list>

each of the fileX.xml have inside a date tag: 
<date>20071015102000</date>(yyyymmddhhmmss). I want to sort the list.xml by the 
date in each file. The way I did it:
<xsl:for-each select="file">
<xsl:variable name="filename" select="file"/>
<xsl:sort order="descending" select="document($filename)/date">

   File:    <xsl:value-of select=".">     Date: <xsl:value-of 
select="document($filename)/date">
</xsl:for-each>

The variable $filename is selecting the child <file> of the <file>
element selected by the for-each, which doesn't exist so the sort
value is empty each time.  So change

<xsl:variable name="filename" select="file"/>

to:

<xsl:variable name="filename" select="."/>

...although you probably want:

<xsl:for-each select="document(file)">
 <xsl:sort select="/path/to/date"/>
 ....

as then the context node is the root of the document referenced by
document() and not the <file> element in the list.


cheers
andrew

--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--

<Prev in Thread] Current Thread [Next in Thread>