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 |
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.
David
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="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="p">
<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>
<xsl:copy-of select="@*"/>
<xsl:variable name="x">
<xsl:apply-templates select="current-group()" mode="g"/>
</xsl:variable>
<xsl:value-of select="replace($x,'\s+',' ')"/>
</xsl:copy>
</xsl:for-each-group>
</p>
</xsl:template>
</xsl:stylesheet>
David
-- Matthieu Ricaud IGS-CP Service Livre numirique
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
Re: [xsl] Grouping "span" with same, David Carlisle | Thread | Re: [xsl] Grouping "span" with same, David Carlisle |
Re: [xsl] flat xml tree to indent o, Matthieu Ricaud-Duss | Date | Re: [xsl] Grouping "span" with same, David Carlisle |
Month |