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

Re: removing trailing space for all the elements

Subject: Re: removing trailing space for all the elements
From: George Cristian Bina <george@xxxxxxxxxxxxx>
Date: Thu, 11 Dec 2008 12:07:56 +0200
Re:  removing trailing space for all the elements
Hi,

Something like below will do it:

<xsl:template match="node() | @*">
    <xsl:copy>
        <xsl:apply-templates select="node() | @*"/>
    </xsl:copy>
</xsl:template>

<xsl:template match="text()" priority="1">
<xsl:variable name="normalized" select="normalize-space(.)"/>
<xsl:variable name="firstToken" select="substring-before($normalized, ' ')"/>
<xsl:value-of select="if ($normalized='' or $firstToken!='')
then concat ($firstToken, substring-after(., $firstToken))
else concat ($normalized, substring-after(., $normalized))
"/>
</xsl:template>


Depending on your actual needs you may find that the simpler solution below also works for you:

<xsl:template match="node() | @*">
    <xsl:copy>
        <xsl:apply-templates select="node() | @*"/>
    </xsl:copy>
</xsl:template>

<xsl:template match="text()" priority="1">
    <xsl:value-of select="normalize-space(.)"/>
</xsl:template>

Best Regards,
George
--
George Cristian Bina
<oXygen/> XML Editor, Schema Editor and XSLT Editor/Debugger
http://www.oxygenxml.com

M Balaji wrote:
Hi All,

 I need to remove trailing space for all the elements. Any help
appreciated.

Input:

 <?xml version="1.0"?>
 <Toc>
 <a> Say you want display this <emph type="b"> data</emph> in the form of a
 sequentially numbered booklist.</a>
 </Toc>

Expected Output:

 <?xml version="1.0"?>
<Toc>
<a>Say you want display this <emph type="b">data</emph> in the form of a
sequentially numbered booklist.</a>
</Toc>


Tried Coding:


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

<xsl:template match="*|@*">
<xsl:copy>
<xsl:apply-templates select="normalize-space(*)"/>
</xsl:copy>
</xsl:template>

</xsl:stylesheet>


For the above style sheet I'm getting error "apply-templates expected node()" and I'm using saxon version 8.


Thanks in advance, Balaji. M

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.