xsl-list
[Top] [All Lists]

sorting on data referenced with document()??

2002-09-16 15:40:13
Hi,

I have a sorting problem when I use xsl to combine data from 2 xml files into 
one html output.

here is my xml file 1 (xml1.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>
-----------------------

here is my xml file 2 (xml2.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>
-----------------------

here is my stylesheet:
-----------------------
<?xml version="1.0" encoding="ISO-8859-1"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"; 
xmlns="http://www.w3.org/tr/REC-html40"; version="2.0">
<xsl:key name="turtleByOwner" match="//turtle" use="../@name" />
<xsl:template match="/">
<table border="1" cellspacing="0" cellpadding="0">
        <xsl:for-each select="people/person">
        <xsl:sort select="cat"/>
        <tr>
                <td colspan="7">Person: <xsl:value-of select="@name"/></td>
        </tr>
        <tr>
                <td><xsl:value-of select="cat"/></td>
                <td><xsl:value-of select="dog"/></td>
                <td><xsl:value-of select="fish"/></td>
                <xsl:variable name="ownerName" select="@name"/>
                <td>
                <xsl:for-each select="document('xml2.xml')">
                <xsl:value-of select="key('turtleByOwner', $ownerName)"
                </xsl:for-each>
                </td>
        </tr>
        </xsl:for-each>
</table>
</xsl:template>
</xsl:stylesheet>
-----------------------

this correctly produces (sorted by cat):
-----------------------
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 
-----------------------


but I want to sort by turtle (I want this output):
-----------------------
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 
-----------------------

I changed the sort line to be:
<xsl:sort select="turtle"/>
but it doesn't work, my output is:
-----------------------
Person: george 
cat-zoro   dog-butch   fish-jaws   turtle-greeny 
  
Person: jennifer 
cat-felix   dog-fido   fish-moby   turtle-browny 
  
Person: simon 
cat-tom   dog-scooby   fish-conroy   turtle-red 
-----------------------

how can I sort on the turtle column from the document reference?

thanks for any ideas.
will
  

 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list