Re: [xsl] Grouping and filtering

Subject: Re: [xsl] Grouping and filtering
From: "Vasu Chakkera" <vasucv@xxxxxxxxxxx>
Date: Wed, 03 Jul 2002 13:56:44 +0000
Bernard..
The following code will help you..
This XSL does both the sorting which you have asked for.
1. it prints the group name based on the item
2. it prints the group name based on the items starting with a string.
The first is fairly simple and the code is self explainatory
The second accepts a String parameter as a filter_string..
and does the filtering based on parameter.
The XSL is intended to output HTML format file
the code follows

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"; version="1.0">
<xsl:key name = "groupname" match = "/groups/group" use = "item"/>
<xsl:param name="filter"/>
<xsl:template match="/">
<xsl:for-each select="/groups/group/item[not(. = preceding::item)]">
groups of item name : <xsl:value-of select="."/><br/>
<xsl:for-each select="key('groupname',.)">
<xsl:value-of select="@name"/><br/>
</xsl:for-each><hr/>
</xsl:for-each>
<hr/>
groups of item name starting from <xsl:value-of select="$filter"/><br/>
<xsl:for-each select="/groups/group/item[(not(. = preceding::item)) and (starts-with(., $filter))]">
Name:<xsl:value-of select="."/><br/>
<xsl:for-each select="key('groupname',.)">
<xsl:value-of select="@name"/><br/>
</xsl:for-each><hr/>
</xsl:for-each>
</xsl:template>
</xsl:stylesheet>


Hope this helps
Vasu

From: "Bernard Delporte" <bdelporte@xxxxxxx>
Reply-To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
To: "XSL-List@xxxxxxxxxxxxxxxxxxxxxx" <XSL-List@xxxxxxxxxxxxxxxxxxxxxx>
Subject: [xsl] Grouping and filtering
Date: Wed, 03 Jul 2002 15:08:19 +0200 (MSZ)

Hello,

Trying to use the Muenchian method on a very specific case, I was not able
to figure out how to do it. Here is a simplified version of the XML I use:

<groups>
  <group name="GR1">
    <item>any</item>
    <item>test</item>
    <item>tests</item>
    <item>zz</item>
  </group>
  <group name="GR2">
    <item>any</item>
    <item>tests</item>
    <item>value</item>
  </group>
</groups>

What I want to produce as output is as follows:

I want to list all the groups containing the item:
1. for all single items
any	GR1, GR2
test	GR1
tests	GR1, GR2
value	GR2
zz	GR1

2. for items responding to a certain filtering criteria like starting by
for instance 'te'
test	GR1
tests	GR1, GR2

Any idea ?

Thanks in advance

Bernard




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






_________________________________________________________________
MSN Photos is the easiest way to share and print your photos: http://photos.msn.com/support/worldwide.aspx



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



Current Thread