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(_at_)CraneSoftwrights(_dot_)com
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