Subject: Re: [xsl] xslt 2.0: grouping flat element structures to make lists From: David Carlisle <davidc@xxxxxxxxx> Date: Wed, 25 May 2005 22:29:59 +0100 |
<sect> <foo/> <xyz/> <xyz/> <par class="Listbegin">Fruit</par> <par class="Listitem">Apple</par> <par class="Listitem">Orange</par> <par class="Listitem">Pear</par> <par class="Listbegin">Colours</par> <par class="Listitem">Red</par> <par class="Listitem">Green</par> <par class="Listitem">Blue</par> <xyz/> <bar/> <par class="Listbegin">Fruit</par> <par class="Listitem">Apple</par> <par class="Listitem">Orange</par> <par class="Listitem">Pear</par> </sect> <xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" > <xsl:output indent="yes"/> <xsl:template match="*"> <xsl:copy> <xsl:copy-of select="@*"/> <xsl:apply-templates/> </xsl:copy> </xsl:template> <xsl:template match="sect"> <xsl:copy> <xsl:copy-of select="@*"/> <xsl:for-each-group group-adjacent="@class='Listitem'" select="*"> <xsl:choose> <xsl:when test="self::par[@class='Listitem']"> <list> <head><xsl:apply-templates select="preceding-sibling::par[1]/node()"/></head> <xsl:apply-templates select="current-group()"/> </list> </xsl:when> <xsl:otherwise> <xsl:apply-templates select="current-group()"/> </xsl:otherwise> </xsl:choose> </xsl:for-each-group> </xsl:copy> </xsl:template> <xsl:template match="par[@class='Listbegin']"/> </xsl:stylesheet> $ saxon8 list.xml list.xsl <?xml version="1.0" encoding="UTF-8"?> <sect> <foo/> <xyz/> <xyz/> <list> <head>Fruit</head> <par class="Listitem">Apple</par> <par class="Listitem">Orange</par> <par class="Listitem">Pear</par> </list> <list> <head>Colours</head> <par class="Listitem">Red</par> <par class="Listitem">Green</par> <par class="Listitem">Blue</par> </list> <xyz/> <bar/> <list> <head>Fruit</head> <par class="Listitem">Apple</par> <par class="Listitem">Orange</par> <par class="Listitem">Pear</par> </list> </sect> ________________________________________________________________________ This e-mail has been scanned for all viruses by Star. The service is powered by MessageLabs. For more information on a proactive anti-virus service working around the clock, around the globe, visit: http://www.star.net.uk ________________________________________________________________________
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
RE: [xsl] xslt 2.0: grouping flat e, Derek Revill | Thread | RE: [xsl] xslt 2.0: grouping flat e, Derek Revill |
RE: [xsl] xslt 2.0: grouping flat e, Derek Revill | Date | RE: [xsl] overwriting certain block, Aron Bock |
Month |