[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Re: Grouping "span" with same @class within mixed cont

Subject: Re: Grouping "span" with same @class within mixed content element
From: David Carlisle <davidc@xxxxxxxxx>
Date: Tue, 21 Dec 2010 12:27:59 +0000
Re:  Grouping "span" with same @class within mixed cont
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


Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.