xsl-list
[Top] [All Lists]

Re: XML grouping by attribute using Muenchian method?

2003-11-26 03:17:13
hi,

As I have just recently struggled with the similar task I give you my
version of xslt thatr does about that here:
----------------------------------------------
<xsl:stylesheet version = '1.0'
     xmlns:xsl='http://www.w3.org/1999/XSL/Transform'

<xsl:key name="contacts-by-shelf" match="//book" use="@type" />
<xsl:template match="bookshelf">

<html>
<head>
<title>Shelfs</title>
</head>
<body>
<h1>Index (fi)</h1>
<table border="1">
<tr><td align="left">Shelf</td><td align="left">Book</td></tr>

 <xsl:for-each select="//book[count(. | key('contacts-by-shelf', @type)[1])
= 1]">
  <xsl:sort select="@type" lang="fi"/>


 <tr><td align="left" valign="top"><xsl:apply-templates select="@type"/>
 </td><td>
  <xsl:for-each select="key('contacts-by-shelf',@type)">
<xsl:value-of select="@title" /><br/>

  </xsl:for-each>
 </td></tr>
 </xsl:for-each>

</table>
</body>
</html>

</xsl:template>

</xsl:stylesheet>
--------------------------------------

regards
Kaarle Kaila
--
Kaarle Kaila
email: kaarle dot kaila at iki dot fi
www.iki.fi/kaila

----- Original Message ----- 
From: <nicolas(_dot_)m(_at_)eurorscg(_dot_)be>
To: <XSL-List(_at_)lists(_dot_)mulberrytech(_dot_)com>
Sent: Wednesday, November 26, 2003 11:10 AM
Subject: [xsl] XML grouping by attribute using Muenchian method?


Hi

This is my XML

<bookshelf>
  <book type="myshelf" title="some book" />
  <book type="yourshelf" title="some other book" />
  <book type="myshelf" title="yet some other book" />
</bookshelf>

I want to group these books by attribute "type" e.g. looking like this

myshelf
        some book
        yet some other book
yourshelf
        some other book

I've been messing around with keys but I can't get the desired result...

Thanks
Nicolas


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



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