Altova Mailing List Archives>Archive Index >microsoft.public.xsl Archive Home >Recent entries >Thread Prev - Re: Help required in Grouping by category >Thread Next - Re: Help required in Grouping by category Re: Help required in Grouping by categoryTo: 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/
| ||||||
| Company | Legal | Press | Partners | Careers | Sitemap | Contact Us | Altova Blog | Mobile | Full Site | |||
|
