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

Subject: Re: [xsl] Grouping "span" with same @class within mixed content element
From: Matthieu Ricaud-Dussarget <matthieu.ricaud@xxxxxxxxx>
Date: Tue, 21 Dec 2010 15:56:25 +0100
Hmm, what a good idea to use concat as grouping key, i was sure i was missing something with this technique ;-) !

Everything is clear, and pulling the whitespace inside the span is quite ok.
I jsut did not understand what the mode="g" means as there is no other template in this mode ?
Or would it means go back to the "global" mode ?

Thanks again,


Le 21/12/2010 13:27, David Carlisle a icrit :
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+',' ')"/>



Matthieu Ricaud
Service Livre numirique

Current Thread