[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message] Re: How to split text element to separate spans?
Given your input document, the following 2.0 stylesheet produces the desired output: <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="2.0"> <xsl:output method="xml" indent="yes" /> <xsl:template match="p"> <p> <xsl:copy-of select="@*" /> <xsl:apply-templates select="span" /> </p> </xsl:template> <xsl:template match="span"> <xsl:variable name="attrs" select="@*" /> <xsl:for-each-group select="text() | *" group-starting-with="br"> <xsl:choose> <xsl:when test="not(normalize-space(string(string-join(current-group(),''))) = '')"> <span> <xsl:copy-of select="$attrs" /> <xsl:copy-of select="normalize-space(string(string-join(current-group(),' ')))" /> </span> <br/> </xsl:when> <xsl:otherwise> <xsl:if test="position() != last()"> <br/> </xsl:if> </xsl:otherwise> </xsl:choose> </xsl:for-each-group> </xsl:template> </xsl:stylesheet> On Sun, Jun 6, 2010 at 9:12 PM, Israel Viente <israel.viente@xxxxxxxxx> wrote: > Hi, > I have a problem splitting spans with text elements separated by br, > to different spans with br in between them. > > Example Input: > > <p dir="ltr"><span class="smaller">text1 > B B B B B B <br /> > B B B B B B text2 > B B B B B B text3. > B B B B B B <br /> > B B B B B B </span> <span class="smalleritalic">no</span> <span > class="smaller">problems. > B B B B B B <br /> > > > B B B B B B <br /> > B B B B B B </span></p> > > Desired output: > > <p dir="ltr"><span class="smaller">text1</span> > B B B B B B <br /> > B B B B B B <span class="smaller">text2 text3.</span> > B B B B B B <br /> > B B B B B B <span class="smalleritalic">no</span> <span > class="smaller">problems.</span> > B B B B B B <br /> > B B B B B B <br /> > B B B B B B </p> > B Note: I need to create new span and preserve the span class when br > breaks inside a span. > > Thanks for any idea. > Israel -- Regards, Mukul Gandhi
|
PURCHASE STYLUS STUDIO ONLINE TODAY!Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced! Download The World's Best XML IDE!Accelerate XML development with our award-winning XML IDE - Download a free trial today! Subscribe in XML format
|