[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Muenchian grouping not working in my case - what am I

Subject: Muenchian grouping not working in my case - what am I doing wrong
From: Ian Lang <ianplang@xxxxxxxxx>
Date: Fri, 23 Apr 2004 10:08:46 -0700 (PDT)
muenchian grouping
I have a hierarchical document where each of the child
or container elements can have a properties element
which contains n property elements.  Each of the
property elements has a name, a value and a category. 
I am generating HTML for the document and for each
element I want to create a property table which shows
the properties by category.  For some reason grouping
using the Muenchian method does not work as I expected
but grouping the slow way (as found in the FAQ) does
work.  I strongly suspect that I am missing something
important but I cannot figure out what it is.

Here is a sample document (namespaces have been
removed for readability):
<document>
  <container>
    <properties>
      <property name=test category=Cat1
value=valueA/>
      <property name=testing category=Cat1
value=valueB/>
      <property name=test category=Cat2
value=valueC/>
      <property name=testing category=Cat2
value=valueD/>
    </properties>
    <container>
      <child>
        <properties>
          <property name=test category=Cat1
value=valueA/>
          <property name=testing category=Cat1
value=valueB/>
          <property name=test category=Cat2
value=valueC/>
          <property name=testing category=Cat2
value=valueD/>
        </properties>
      </child>
    </container
    <child>
      <properties>
        <property name=test category=Cat1
value=valueA/>
        <property name=testing category=Cat1
value=valueB/>
        <property name=test category=Cat2
value=valueC/>
        <property name=testing category=Cat2
value=valueD/>
      </properties>
    </child>
  </container>
</document>

When creating the HTML for each of the container or
child nodes I include this line at the location where
I would like the property table:
<xsl:apply-templates select="properties"/>

To create the table I have this key and template for
the properties object.  Right now I have it dump the
properties with no grouping, with Muenchian grouping
and then with the slow method of grouping as a test:
<xsl:key name="properties-by-category"
match="/*/property" use="@category"/>
  
<xsl:template match="properties">
  <h4>Properties raw</h4>
  <xsl:for-each select=" property">
    <xsl:value-of select="@ category"/><br/>
        &#160;&#160;&#160;&#160;<xsl:text>Property
</xsl:text><xsl:value-of
select="@name"/>&#160;<xsl:value-of
select="@value"/><br/>
  </xsl:for-each>

  <h4>Properties fast grouping</h4>
  <xsl:for-each select="property[count(. |
key('properties-by-category', @category)[1]) = 1]">
    <xsl:sort select="@category"/>
    <xsl:value-of select="@category"/><br/>
    <xsl:for-each
select="key('properties-by-category', @category)">
      <xsl:sort select="@name"/>
        &#160;&#160;&#160;&#160;<xsl:text>Property
</xsl:text><xsl:value-of
select="@name"/>&#160;<xsl:value-of
select="@value"/><br/>
    </xsl:for-each>
  </xsl:for-each>

  <h4>Properties slow grouping</h4>
  <xsl:for-each
select="property[not(@category=preceding-sibling::property/@category)]">
    <xsl:sort select="@category"/>
    <xsl:value-of select="@category"/><br/>
    <xsl:for-each
select=".|following-sibling::property[@category=current()/@category]">
      <xsl:sort select="@name"/>
        &#160;&#160;&#160;&#160;<xsl:text>Property
</xsl:text><xsl:value-of
select="@name"/>&#160;<xsl:value-of
select="@value"/><br/>
    </xsl:for-each>
  </xsl:for-each>
    
</xsl:template>

For each of the property tables I get something like
this:
Properties raw

Cat1
    Property test valueA
Cat1
    Property testing valueB
Cat2
    Property test valueC
Cat2
    Property testing valueD

Properties fast grouping
Cat1
Cat1
Cat2
Cat2

Properties slow grouping
Cat1
    Property test valueA
    Property testing valueB
Cat2
    Property test valueC
    Property testing valueD

As you can see the values I want are there but my
Muenchain grouping is not working as expected but the
slow method is.

Is Muenchian grouping inappropriate for my situation
or did I mess up.  Any advice would be appreciated

Thanks,

IL


	
		
__________________________________
Do you Yahoo!?
Yahoo! Photos: High-quality 4x6 digital prints for 25"
http://photos.yahoo.com/ph/print_splash

Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.