Altova Mailing List Archives>Archive Index >microsoft.public.xsl Archive Home >Recent entries >Thread Prev - Newbie (Parse and substring). >Thread Next - Re: Newbie (Parse and substring). Re: Newbie (Parse and substring).To: NULL Date: 3/6/2007 1:53:00 PM Stan wrote: > I have to transform a XML file formated like that : > > <main> > <smain> > <code>Book 0</code> > <category>book/thriller/conelly</category> > </smain> > <smain> > <code>Book 1</code> > <category>book/computer/asp</category> > <smain> > <smain> > <code>Book 2</code> > <category>book/thriller/coben</category> > </smain> > </main> > > > > I have to group the node by category. Here is an example XSLT 1.0 stylesheet that use a key for grouping and also sorts the result: <?xml version="1.0" encoding="UTF-8"?> <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0"> <xsl:output method="html" indent="yes"/> <xsl:key name="smain-by-category" match="smain" use="substring-before(substring-after(category, '/'), '/')"/> <xsl:template match="/"> <html> <head> <title>grouping example</title> </head> <body> <xsl:apply-templates select="main/smain[generate-id() = generate-id(key('smain-by-category', substring-before(substring-after(category, '/'), '/'))[1])]" mode="group"> <xsl:sort select="substring-before(substring-after(category, '/'), '/')" data-type="text" order="ascending"/> </xsl:apply-templates> </body> </html> </xsl:template> <xsl:template match="smain" mode="group"> <div class="csscategory"> <h1><xsl:value-of select="substring-before(substring-after(category, '/'), '/')"/></h1> <ul> <xsl:apply-templates select="key('smain-by-category', substring-before(substring-after(category, '/'), '/'))"/> </ul> </div> </xsl:template> <xsl:template match="smain"> <li><xsl:value-of select="code"/></li> </xsl:template> </xsl:stylesheet> -- Martin Honnen --- MVP XML http://JavaScript.FAQTs.com/ | ||||||
| Company | Legal | Press | Partners | Careers | Sitemap | Contact Us | Altova Blog | Mobile | Full Site | |||
|
