[XSL-LIST Mailing List Archive Home] [By Thread] [By Date]

Re: [xsl] regrouping split elements


Subject: Re: [xsl] regrouping split elements
From: Martin Honnen <Martin.Honnen@xxxxxx>
Date: Mon, 21 Dec 2009 18:24:09 +0100

James Cummings wrote:

But to get this first step done, I've started out a number of
different ways before hitting stumbling blocks with
previous/following-sibling.  Is the right approach (in XSLT2) instead
to do something like xsl:for-each-group on the value of hi/@rend
inside each 'p'?

To fix the output you have I think you could use


<xsl:stylesheet
  xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  version="2.0">

<xsl:strip-space elements="p"/>

<xsl:template match="p">
<xsl:copy>
<xsl:for-each-group select="node()" group-adjacent="boolean(self::hi)">
<xsl:choose>
<xsl:when test="current-grouping-key()">
<xsl:for-each-group select="current-group()" group-adjacent="@rend">
<hi rend="{current-grouping-key()}">
<xsl:copy-of select="current-group()/node()"/>
</hi>
</xsl:for-each-group>
</xsl:when>
<xsl:otherwise>
<xsl:copy-of select="current-group()"/>
</xsl:otherwise>
</xsl:choose>
</xsl:for-each-group>
</xsl:copy>
</xsl:template>


</xsl:stylesheet>

but you might rather not produce the wrong output at all and instead fix the stylesheet that produces the wrong output.
--


	Martin Honnen
	http://msmvps.com/blogs/martin_honnen/


Current Thread