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

Re: Re: sorting on data referenced with document()??

Subject: Re: Re: sorting on data referenced with document()??
From: Dimitre Novatchev <dnovatchev@xxxxxxxxx>
Date: Tue, 17 Sep 2002 02:56:18 -0700 (PDT)
 Re: Re: sorting on data referenced with document()??
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

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.