|
[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message] Re: xslt 2.0: grouping flat element structures to make
<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
________________________________________________________________________
|
PURCHASE STYLUS STUDIO ONLINE TODAY!Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced! Download The World's Best XML IDE!Accelerate XML development with our award-winning XML IDE - Download a free trial today! Subscribe in XML format
|

Cart








