[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message] Re: XSLT to remove characters and whitespaces
Hi Georg,
A couple of things: I'm unsure of why you are normalizing the spaces after converting CRs and tabs to spaces, and stripping line feeds, with translate() (in two separate operations). Why not simply normalize the spaces, since that takes care of line feeds and tabs? (The parser should already have normalized CRs away so they shouldn't even be there.) More basically, and this is what accounts for your problem: you are matching elements, creating new elements with the same names (any reason not to use the simpler xsl:copy instruction?), writing out their string values (i.e. all the text inside the elements) and then descending the tree to do the same. This results in your string values being written out over and over again, every time an ancestor element gets processed. So if your input were <greeting> <to>Georg</to> <from>XSL-List</from> <text>Hey, how are tricks?</text> </greeting> you'll get <greeting>GeorgXSL-ListHey, how are tricks? <to>Georg</to> <from>XSL-List</from> <text>Hey, how are tricks?</text> </greeting> since the greeting element gets its text value copied before its own element contents are traversed. Instead of this, you only want to normalize values of the *text* nodes, letting element nodes take care of themselves ... so: <xsl:template match="text()"/> <xsl:value-of select="normalize-space()"/> </xsl:template> <xsl:template match="*"> <xsl:copy> <xsl:copy-of select="@*"/> <xsl:apply-templates/> </xsl:copy> </xsl:template> ... as you can see, fairly simple, and a garden-variety near-identity transform. Cheers, Wendell At 06:33 AM 7/7/2006, you wrote: Hello,
|
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
|