[XSL-LIST Mailing List Archive Home]
[By Thread]
[By Date]
[xsl] Re: Re: sorting on data referenced with document()??
Subject: [xsl] Re: Re: sorting on data referenced with document()?? From: Dimitre Novatchev <dnovatchev@xxxxxxxxx> Date: Tue, 17 Sep 2002 02:56:18 -0700 (PDT) |
Joerg Heinicke <joerg dot heinicke at gmx dot de> wrote: > Yes, this is exactly what I meant by swithcing the context to > document 2, but I think it can not really be suggested, because you > can not switch back to the cat without rewriting the code. > Furthermore <xsl:sort select="*[name() = $sortparam]"/> is not > possible. It is possible without re-writing code and without creating an intermediate RTF: <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl:output omit-xml-declaration="yes" indent="yes"/> <xsl:param name="sortBy" select="'turtle'"/> <xsl:template match="/"> <xsl:variable name="firstPersons" select="people/person"/> <xsl:variable name="secndPersons" select="document('person2.xml')/people/person"/> <xsl:for-each select="$firstPersons[*[name() = $sortBy]] | $secndPersons[*[name() = $sortBy]]"> <xsl:sort select="*[name() = $sortBy]"/> person: <xsl:value-of select="@name"/> <xsl:text>$#xA;</xsl:text> <xsl:for-each select="$firstPersons [@name = current()/@name ]/*"> <xsl:value-of select="concat(., ' ')"/> </xsl:for-each> <xsl:for-each select="$secndPersons [@name = current()/@name ]/*"> <xsl:value-of select="concat(., ' ')"/> </xsl:for-each> </xsl:for-each> </xsl:template> </xsl:stylesheet> When applied to the original source xml: persons1.xml: ------------ <people> <person name="george"> <cat>cat-zoro</cat> <dog>dog-butch</dog> <fish>fish-jaws</fish> </person> <person name="jennifer"> <cat>cat-felix</cat> <dog>dog-fido</dog> <fish>fish-moby</fish> </person> <person name="simon"> <cat>cat-tom</cat> <dog>dog-scooby</dog> <fish>fish-conroy</fish> </person> </people> and the file persons2.xml: ------------ <people> <person name="george"> <turtle>turtle-greeny</turtle> </person> <person name="jennifer"> <turtle>turtle-browny</turtle> </person> <person name="simon"> <turtle>turtle-red</turtle> </person> </people> The result is: person: jennifer cat-felix dog-fido fish-moby turtle-browny person: george cat-zoro dog-butch fish-jaws turtle-greeny person: simon cat-tom dog-scooby fish-conroy turtle-red Note that the name of the child on which to sort is specified as a xsl:param and in this example it is 'turtle'. When I simply change this to 'cat', the result now is: person: jennifer cat-felix dog-fido fish-moby turtle-browny person: simon cat-tom dog-scooby fish-conroy turtle-red person: george cat-zoro dog-butch fish-jaws turtle-greeny ===== Cheers, Dimitre Novatchev. http://fxsl.sourceforge.net/ -- the home of FXSL __________________________________________________ Do you Yahoo!? Yahoo! News - Today's headlines http://news.yahoo.com XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
RE: [xsl] RE: Search Engine, Bryan Tulloch | Thread | [xsl] Off Topic - forum for DHTML/ , aruniima . chakrabar |
RE: [xsl] RE: Search Engine, Bryan Tulloch | Date | Re: [xsl] RE: Search Engine, David Carlisle |
Month |