Subject: Re: [xsl] remove 'invisable' white spaces From: Jeni Tennison <mail@xxxxxxxxxxxxxxxx> Date: Mon, 2 Apr 2001 17:59:35 +0100 |
Hi Kristof, > tried several elements and functions with goal to remove invisable > white spaces, but don't succeeded. Ahh... your problem is here: > <script language="Javascript"> > <xsl:for-each select="Information/Body/Block"> > label<xsl:value-of select="position()"/> = new > Label('<xsl:apply-templates select="."/>') > </xsl:for-each> > </script> When an XML document (like the XSLT stylesheet) is parsed and made into a nice tree, all the text nodes that have any non-whitespace characters in them are kept. As it's an XSLT stylesheet, then all the whitespace-only text nodes aside from those in xsl:text are ignored automatically. So in the above, the node tree looks like (with \n = newline): +- (element) script +- (element) xsl:for-each +- (text) "\n label" +- (element) xsl:value-of +- (text) " = new Label('" +- (element) xsl:apply-templates +- (text) "')\n " You don't want all that whitespace before 'label' and after the closing bracket. To get rid of it, you can enclose the text that you want to output in xsl:text elements: <script language="Javascript"> <xsl:for-each select="Information/Body/Block"> <xsl:text>label</xsl:text> <xsl:value-of select="position()"/> = new Label('<xsl:apply-templates select="."/> <xsl:text>')</xsl:text> </xsl:for-each> </script> This makes the tree look like: +- (element) script +- (element) xsl:for-each +- (element) xsl:text | +- (text) "label" +- (element) xsl:value-of +- (text) " = new Label('" +- (element) xsl:apply-templates +- (element) xsl:text +- (text) "')" Or you could use the Allouche method, which is to place an empty xsl:text element at the beginning of the significant text - essentially this turns the whitespace that you're not interested in into a whitespace-only text node, which is automatically stripped from the tree: <script language="Javascript"> <xsl:for-each select="Information/Body/Block"> <xsl:text />label<xsl:value-of select="position()"/> = new Label('<xsl:apply-templates select="."/>')<xsl:text /> </xsl:for-each> </script> This results in a tree that looks like: +- (element) script +- (element) xsl:for-each +- (element) xsl:text +- (text) "label" +- (element) xsl:value-of +- (text) " = new Label('" +- (element) xsl:apply-templates +- (text) "')" +- (element) xsl:text I hope that helps, Jeni --- Jeni Tennison http://www.jenitennison.com/ XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
[xsl] remove 'invisable' white spac, Kristof Bernaert | Thread | [xsl] Going back to Xalan: what do , Matthias O. Will |
Re: [xsl] XML Update Client-Side to, Robert Koberg | Date | Re: [xsl] position(), David Carlisle |
Month |