You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@xalan.apache.org by Noah Green <nj...@rcn.com> on 2000/10/16 15:33:18 UTC

How to stop blank line output? - with example

Hi,
Thanks for writing back.  I'm not using <xsl:text> tags at all.  What seems
to be happening is that wherever, because of the templates, XSL is ignoring
some element in the source, a blank line gets output.  Here is an example
that I just tested:
------------------------
Source:
<AAA>
<BBB/>
<CCC/>
<DDD/>
</AAA>

Stylesheet:
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="DDD">
         <xsl:value-of select="name()">
</xsl:template>
</xsl:stylesheet>

Output:
<?xml version="1.0" encoding="ISO-8859-1"?>



DDD
------------------------
Notice the 3 blank lines between the XML processing directive and the 
DDD?  Those
would correspond, I think, to the unprocessed <AAA>,<BBB>,<CCC> tags.  How
can I get rid of those lines?  Does it have something to do with the 
default templates
in Xalan?

thanks
noah



At 12:14 PM 10/16/00 +0100, you wrote:
>By default, all whitespace-only characters between element tags are 
>removed, so that
>
><p>
>         <b> Hello</b> <i>
>World</i></p>
>
>would become
>
><p><b> Hello</b><i>
>World</i></p>.
>
>Xalan shouldn't be inserting extra space in other situations, without 
>explicit stylesheet directives.  I suspect you have cases like the above, 
>perhaps
>
>
><xsl:text>Frankie:</xsl:text>
><xsl:text>
>         O-err missus
></xsl:text>
><xsl:text>Matron:</xsl:text>
>
>which be rendered as
>
>Frankie:
>         O-err missus
>Matron:
>
>
>At 06:52 16/10/00 -0400, Noah Green wrote:
>>Hi,
>>I know this is a dev list, while my question is more of a user question.
>>I've browsed all the faqs, archives, etc. and couldn't find anything on this,
>>so I'm hoping you can help.  My problem is that Xalan seems to output
>>a whole lot of blank lines - it looks like wherever you instruct it with
>>templates not to produce output, it creates these blanks.  Is there a way
>>to stop this?  Or might it have something to do with the XSL I've written
>>(don't want to post that because it'll make this message huge.)  It seems
>>like this might come up a lot, any advice?
>>
>>thanks
>>noah
>
>--
>Fergus Gallagher
>Orbis
>http://www.orbisuk.com/
>+44-(0)20-8987 0717


Re: How to stop blank line output? - with example

Posted by Gary L Peskin <ga...@firstech.com>.
Noah Green wrote:
> 
> Hi,
> Thanks for writing back.  I'm not using <xsl:text> tags at all.  What seems
> to be happening is that wherever, because of the templates, XSL is ignoring
> some element in the source, a blank line gets output.  Here is an example
> that I just tested:
> ------------------------
> Source:
> <AAA>
> <BBB/>
> <CCC/>
> <DDD/>
> </AAA>
> 
> Stylesheet:
> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
> <xsl:template match="DDD">
>          <xsl:value-of select="name()">
> </xsl:template>
> </xsl:stylesheet>
> 
> Output:
> <?xml version="1.0" encoding="ISO-8859-1"?>
> 
> DDD
> ------------------------
> Notice the 3 blank lines between the XML processing directive and the
> DDD?  Those
> would correspond, I think, to the unprocessed <AAA>,<BBB>,<CCC> tags.  How
> can I get rid of those lines?  Does it have something to do with the
> default templates
> in Xalan?

Yes.  By default, whitespace only text nodes are not stripped in XSLT. 
The default template for a text node copies the text through to the
result tree.  In this case, the children of AAA are:
  whitespace-text-node
  BBB
  whitespace-text-node
  CCC
  whitespace-text-node
  DDD
  whitespace-text-node

You can eliminate this with a
  <xsl:strip-space elements="AAA"/>
element just after your xsl:stylesheet element.

Gary

Re: How to stop blank line output? - with example

Posted by Jim Melton <ja...@cylogix.com>.
Yes, you are getting the whitespace from the default template rule for
text nodes, which simply echoes the text. Here is a solution which
replaces the default rule with one that removes surrounding whitespace
from the text:

<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="DDD">
	<xsl:value-of select="name()"/>
</xsl:template>
<xsl:template match="text()">
	<xsl:value-of select="normalize-space()"/>
</xsl:template>
</xsl:stylesheet>


Noah Green wrote:
> 
> Here is an example
> that I just tested:
> ------------------------
> Source:
> <AAA>
> <BBB/>
> <CCC/>
> <DDD/>
> </AAA>
> 
> Stylesheet:
> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
> <xsl:template match="DDD">
>          <xsl:value-of select="name()">
> </xsl:template>
> </xsl:stylesheet>
> 
> Output:
> <?xml version="1.0" encoding="ISO-8859-1"?>
> 
> 
> 
> DDD
> ------------------------
> Notice the 3 blank lines between the XML processing directive and the
> DDD?  Those
> would correspond, I think, to the unprocessed <AAA>,<BBB>,<CCC> tags.  How
> can I get rid of those lines?  Does it have something to do with the
> default templates
> in Xalan?
> 
> thanks
> noah
> 

-- 
James Melton
CyLogix, Inc. 
(609) 750-5190 
http://www.cylogix.com