[Home] [By Thread] [By Date] [Recent Entries]
Hi,
Sibling recursion would work for this, but so would this, I think. Plus it might (or might not) be easier to maintain: <xsl:template match="p">
<p>
<xsl:call-template name="merge-spans"/>
</p>
</xsl:template><xsl:template name="merge-spans">
<xsl:for-each-group select="node()" group-adjacent="m:class(.)">
<xsl:choose>
<xsl:when test="string(current-grouping-key())">
<span class="{current-grouping-key()}">
<xsl:apply-templates
select="current-group()" mode="merged"/>
</span>
</xsl:when>
<xsl:otherwise>
<xsl:apply-templates select="current-group()"/>
</xsl:otherwise>
</xsl:choose>
</xsl:for-each-group>
</xsl:template><xsl:function name="m:class" as="xs:string">
<!-- returns a class value for a span, or the class value of an
immediately preceding span for whitespace-only text,
comment or PI nodes -->
<xsl:param name="s" as="node()"/>
<xsl:sequence select="($s/self::span/@class,
$s/(self::text()[not(normalize-space())] |
self::comment() |
self::processing-instruction() )/
preceding-sibling::*[1][self::span]/@class,
'')[1]"/>
</xsl:function><xsl:template match="node()" mode="merged"> <xsl:apply-templates select="."/> </xsl:template> <xsl:template match="span[@class]" mode="merged"> <xsl:apply-templates/> </xsl:template> Cheers, Wendell On 10/27/2011 4:13 AM, Nic Gibson wrote:
|

Cart



