Re: [xsl] Grouping "span" with same @class within mixed content element

Subject: Re: [xsl] Grouping "span" with same @class within mixed content element
From: David Carlisle <davidc@xxxxxxxxx>
Date: Tue, 21 Dec 2010 12:27:59 +0000
On 21/12/2010 12:03, Matthieu Ricaud-Dussarget wrote:
Hi David,

In xhtml spaces are important, i think you all now the rules : only one
space is displayed even when there are more, and a line feed also
generate one space on the display screen.

yes I suspected that was the case:-)

In the simpler version that I suggested first, I changed the select not to pick up white space, but kept the simple adjacency test.

You do want to pick up the white space, but then you need a more complicated rule for testing adjacency.

Something like this, which doesn't quite handle white space as you asked (as it always pulls it into the grouped span) but may get you started.


bash-3.2$ saxon9 spgr.xml spgr.xsl
<?xml version="1.0" encoding="UTF-8"?><p id="foo"><span class="foo1">text1 text2 text3 </span><span class="foo2">text4 text5 text6</span><span class="foo1">text7 text8 </span></p>

<xsl:stylesheet version="2.0" xmlns:xsl="";>

<xsl:template match="p">
<xsl:copy-of select="@*"/>
<xsl:for-each-group select="node()" group-adjacent="concat(@class,self::text()[not(normalize-space())]/preceding-sibling::node()[1]/@class)">
<xsl:copy-of select="@*"/>
<xsl:variable name="x">
<xsl:apply-templates select="current-group()" mode="g"/>
<xsl:value-of select="replace($x,'\s+',' ')"/>



Current Thread