<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[(_at_)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[(_at_)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
________________________________________________________________________
--~------------------------------------------------------------------
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--