Home. 
.

transparent

transparent

transparent

Altova Mailing List Archives


Re: Help required in Grouping by category

From: Martin Honnen <mahotrash@-----.-->
To: NULL
Date: 5/11/2007 3:41:00 PM

RJN wrote:

> I'm going through the site, but couldn't get to
> the solution yet. Could you help me on this

Here is an example stylesheet:

<xsl:stylesheet
   xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
   xmlns:rs="http://example.com/ns1"
   xmlns:z="http://example.com/ns2"
   exclude-result-prefixes="rs z"
   version="1.0">

<xsl:output method="html" indent="yes"/>

<xsl:strip-space elements="*"/>

<xsl:key name="row-by-category" match="z:row" use="@Category"/>

<xsl:template match="/">
   <html lang="en">
     <head>
       <title>Grouping example</title>
     </head>
     <body>
       <h1>Grouping example</h1>
       <xsl:apply-templates select="rs:data/z:row[generate-id() = 
generate-id(key('row-by-category', @Category)[1])]" mode="group"/>
     </body>
   </html>
</xsl:template>

<xsl:template match="z:row" mode="group">
   <h2><xsl:value-of select="@Category"/></h2>
   <ul>
     <xsl:apply-templates select="key('row-by-category', @Category)"/>
   </ul>
</xsl:template>

<xsl:template match="z:row">
   <li><xsl:value-of select="concat(@Title, ', ', @Description)"/></li>
</xsl:template>

</xsl:stylesheet>

It transforms to HTML, you did not really indicate whether you want text 
output or HTML output but the grouping approach is the same 
nevertheless. Note that your XML sample did not show xmlns declarations 
so made them up as e.g.

<rs:data xmlns:rs="http://example.com/ns1"
          xmlns:z="http://example.com/ns2" ItemCount="4">

you need to change the stylesheet to use the real namespaces obviously.


-- 

	Martin Honnen --- MVP XML
	http://JavaScript.FAQTs.com/


transparent
Print
Mail
Like It
Disclaimer
.

These Archives are provided for informational purposes only and have been generated directly from the Altova mailing list archive system and are comprised of the lists set forth on www.altova.com/list/index.html. Therefore, Altova does not warrant or guarantee the accuracy, reliability, completeness, usefulness, non-infringement of intellectual property rights, or quality of any content on the Altova Mailing List Archive(s), regardless of who originates that content. You expressly understand and agree that you bear all risks associated with using or relying on that content. Altova will not be liable or responsible in any way for any content posted including, but not limited to, any errors or omissions in content, or for any losses or damage of any kind incurred as a result of the use of or reliance on any content. This disclaimer and limitation on liability is in addition to the disclaimers and limitations contained in the Website Terms of Use and elsewhere on the site.

.
.

transparent

transparent