[XSL-LIST Mailing List Archive Home] [By Thread] [By Date]

Re: [xsl] Grouping and filtering


Subject: Re: [xsl] Grouping and filtering
From: "Steve Muench" <Steve.Muench@xxxxxxxxxx>
Date: Wed, 3 Jul 2002 16:28:54 +0200

| 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

For this one, you can try a stylesheet like:

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
  <xsl:key name="x" match="group" use="item"/>
  <xsl:key name="y" match="item"  use="."/>
  <xsl:output method="text"/>
  <xsl:template match="/">
    <xsl:for-each select="/groups/group/item[
                            generate-id() = 
                            generate-id(key('y',.)[1])]">
      <xsl:sort select="."/>
      <xsl:variable name="curitem" select="."/>
      <xsl:value-of select="$curitem"/>
      <xsl:text>: </xsl:text>      
      <xsl:for-each select="key('x',$curitem)">
        <xsl:value-of select="@name"/>
        <xsl:if test="position() != last()"><xsl:text> </xsl:text></xsl:if>
      </xsl:for-each>
      <xsl:text>&#xa;</xsl:text>
    </xsl:for-each>
  </xsl:template>
</xsl:stylesheet>

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

For this, just add an extra predicate to the outer filter like this:

    <xsl:for-each select="/groups/group/item[
                            generate-id() = 
                            generate-id(key('y',.)[1])][contains(.,'te')]">


Hope this helps.


__________________________________________________________________
Steve Muench - Developer, Product Mgr, Java/XML Evangelist, Author
Simplify J2EE and EJB Development with BC4J
http://otn.oracle.com/products/jdev/htdocs/j2ee_bc4j.html
Building Oracle XML Apps, www.oreilly.com/catalog/orxmlapp




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



Current Thread
Keywords
xml