[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: "Michael Kay" <mike@xxxxxxxxxxxx>
Date: Thu, 11 Dec 2008 10:32:47 -0000
RE:  removing trailing space for all the elements
>  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>

You've actually removed two leading spacs there (before "Say" and "data",
and you have left one leading/trailing space alone (in the text node that
follows the </a> end tag. I assume what you actually want to do is not to
remove trailing spaces, but to apply normalize-space to each text node.

The easiest way to achieve that is

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

and then make sure you are outputting all text using <xsl:apply-templates/>
rather than <xsl:value-of/>
> 
> 
> Tried Coding:
> 
> <xsl:template match="*|@*">
> <xsl:copy>
> <xsl:apply-templates select="normalize-space(*)"/> 
> </xsl:copy> </xsl:template>
> 
> For the above style sheet I'm getting error "apply-templates 
> expected node()" and I'm using saxon version 8.

I hope you have some understanding of what you've done wrong there. If not,
that suggests you really haven't yet understood what apply-templates does,
and rather than give you a terse explanation here, I'd suggest you curl up
with a good book for a couple of hours...

Michael Kay
http://www.saxonica.com/

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.