whitespace is always a stumbling block, but if you look at what you've
written:

  <xsl:otherwise>
    isn't three
  </xsl:otherwise>

You have a CR/LF, some spaces, the chars 'isn't three', and then another
CR/LF... and thats what is making it through into the output.  Your
'presentational whitespace' is actually part of your output.

There are three ways to handle literal text:

1. Dont use presentational whitespace (ie no indenting of code)
  <xsl:otherwise>isn't three</xsl:otherwise> 

2. Use <xsl:text> (all whitespace only nodes are ignored)
  <xsl:otherwise>
    <xsl:text>isn't three</xsl:text>
  </xsl:otherwise>

3. Use a combination:
  <xsl:otherwise>isn't three<xsl:text/>
  </xsl:otherwise>

Its all down to taste, really.

cheers
andrew

> -----Original Message-----
> From: Thomas B�rkel [mailto:[EMAIL PROTECTED]
> Sent: 15 November 2002 12:46
> To: Xalan Mailinglist
> Subject: Handling of whitespaces
> 
> 
> HI!
> 
> Suppose you have this XML:
> 
> <root>
>   <one>1</one>
>   <two>2</two>
>   <three>4</three>
> </root>
> 
> 
> And this XSL:
> 
> <xsl:stylesheet 
> xmlns:xsl="http://www.w3.org/1999/XSL/Transform"; version="1.0">
> 
>   <xsl:template match="root">
>     <xsl:value-of select="one" />
>     <xsl:value-of select="two" />
>     <xsl:choose>
>       <xsl:when test="three='3'">
>         <xsl:value-of select="three" />
>       </xsl:when>
>       <xsl:otherwise>
>         isn't three
>       </xsl:otherwise>
>     </xsl:choose>
>   </xsl:template>
> 
> </xsl:stylesheet>
> 
> 
> Now, if you apply the XSL to the XML, you get:
> 
> 12
>         isn't three
> 
> 
> The "1" and "2" are being appended without spaces or LFs, the 
> text is not. This is inconsistent. Now change the value of 
> <three> to "3" in the XML. Now you get:
> 
> 123
> 
> So, this time no spaces or LFs.
> 
> Is this supposed to be that way or is it a bug?
> 
> Using Xerces 2.2.0 and Xalan 2.3.1 with JDK 1.4.1.
> 
> Regards,
> Thomas
> 
> 
> 

Reply via email to