[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message] 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/
|
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
|