From: ªL ¤lªä <minikittygo@hotmail.com>
Reply-To: xsl-list@lists.mulberrytech.com
To: xsl-list@lists.mulberrytech.com
Subject: [xsl] grouping data
Date: Fri, 05 Jul 2002 00:24:50 +0000
hi, i was wander anyone could help me on this topic
i have a structure like this:
<books>
<book isbn="1">
<author>
<name>author1</name>
<brithday>13/2/1965</brithday>
<description>...</description>
</author>
<type>adventure</type>
<name>bookName</name>
</book>
<book isbn="2">
<author>
<name>author2</name>
<brithday>13/2/1965</brithday>
<description>...something else </description>
</author>
<type>sci-fi</type>
<name>bookName</name>
</book>
<book isbn="3">
<author>
<name>author1</name>
<brithday>13/2/1965</brithday>
<description>...something else again </description>
</author>
<type>sci-fi</type>
<name>bookName</name>
</book>
<book isbn="4">
<author>
<name>author3</name>
<brithday>02/11/1975</brithday>
<description>...something else </description>
</author>
<type>novel</type>
<name>bookName</name>
</book>
...
</books>
i wish to group them in few way: first by the name of the author, then by
type, with the following result output:
<list>
<authors>
<author name="author1">
<isbn>1</isbn> <!-- the attribute of its parents-->
<isbn>3</isbn>
</author>
<author name="author2">
<isbn>2</isbn>
</author>
...
</authors>
<booktype>
<type name="sci-fi">
<book>
<isbn>2</isbn>
<name>bookname</name>
</book>
<book>
<isbn>3</isbn>
<name>bookname</name>
</book>
...
</booktype>
...
</list>
i was i wondering how it could be achieve it.
i have try to set the following keys up:
xsl:key name="sort_author_name" match="author" use="name"/>
<xsl:key name="sort_booktype" match="book" use="type"/>
and sort them with the following template:
...
<xsl:template match="books">
<list>
<!-- for the sort by author name part -->
<authors>
<xsl:for-each
select="book/author[generate-id()=generate-id(key(sort_author_name,
name[1])]">
<unit><xsl:attribute name="name"><xsl:value-of
select="name"/></xsl:attribute>
<isbn><xsl:value-of select="../@isbn"/></isbn>
</xsl:for-each>
</authors>
...
</list>
</xsl:template>
however, i could not get anything out of it, can somebody comment on my
code, to see what went wrong?
Many thanks
regards
Kit
_________________________________________________________________
¨Ï¥Î¥þ²y³Ì¦h¤H¨Ï¥Îªº¹q¤l¶l¥óªA°È MSN Hotmail¡Ghttp://www.hotmail.com
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list