W3C home > Mailing lists > Public > www-xsl-fo@w3.org > December 2003

Re: To Remove White after the End of Element for Each CDATA element !!!

From: David Carlisle <davidc@nag.co.uk>
Date: Thu, 18 Dec 2003 14:04:20 GMT
Message-Id: <200312181404.OAA19242@penguin.nag.co.uk>
To: sguy_chennai@yahoo.co.in
Cc: www-xsl-fo@w3.org


Note CDATA sections are not elements, and XSLT does not see them, so
your input is equivalent to the input below which does not use
CDATA. This would be much easier in XSLT2, but in XSLT1 you just need a
small recursive loop to strip off the trailing space.



<x>
<WOOD>
        <WORK>
            <DONE>A B FL  3432
                     </DONE>
        </WORK>
</WOOD>
<WOOD>
        <WORK>
            <DONE>C C FT  1111
                     </DONE>
        </WORK>
</WOOD>
<WOOD>
        <WORK>
            <DONE>T T RT  2323
                     </DONE>
        </WORK>
</WOOD>
</x>




<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0"
>

<xsl:template match="/">
<xsl:apply-templates select="/x/WOOD/WORK/DONE"/>
</xsl:template>

<xsl:template match="DONE">
<xsl:text>
[</xsl:text>
<xsl:call-template name="x"/>
<xsl:text>]</xsl:text>
</xsl:template>

<xsl:template name="x">
<xsl:param name="s" select="."/>
<xsl:variable name="l" select="substring($s,string-length($s))"/>
<xsl:choose>
<xsl:when test="$l=' ' or $l='&#10;'">
<xsl:call-template name="x">
  <xsl:with-param name="s"
  select="substring($s,1,string-length($s)-1)"/>
</xsl:call-template>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="$s"/>
</xsl:otherwise>
</xsl:choose>
</xsl:template>

</xsl:stylesheet>




$ saxon wood.xml wood.xsl
<?xml version="1.0" encoding="utf-8"?>
[A B FL  3432]
[C C FT  1111]
[T T RT  2323]



-- 
http://www.dcarlisle.demon.co.uk/matthew

________________________________________________________________________
This e-mail has been scanned for all viruses by Star Internet. The
service is powered by MessageLabs. For more information on a proactive
anti-virus service working around the clock, around the globe, visit:
http://www.star.net.uk
________________________________________________________________________
Received on Thursday, 18 December 2003 09:07:59 GMT

This archive was generated by hypermail 2.2.0+W3C-0.50 : Wednesday, 3 October 2007 16:06:11 GMT