Subject: [xsl] 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) |
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/>     <xsl:text>Property </xsl:text><xsl:value-of select="@name"/> <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"/>     <xsl:text>Property </xsl:text><xsl:value-of select="@name"/> <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"/>     <xsl:text>Property </xsl:text><xsl:value-of select="@name"/> <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 |
---|
|
<- Previous | Index | Next -> |
---|---|---|
RE: [xsl] Empty text area issue, Passin, Tom | Thread | Re: [xsl] Muenchian grouping not wo, Mukul Gandhi |
Re: [xsl] OMR (Optical Mark Recogni, G. Ken Holman | Date | RE: [xsl] XSL : Numbers to Words, Josh Canfield |
Month |