This is the mail archive of the
xsl-list@mulberrytech.com
mailing list .
Re: newline white space
- To: "Lisa Rupe" <LRupe at questia dot com>
- Subject: Re: [xsl] newline white space
- From: Jeni Tennison <mail at jenitennison dot com>
- Date: Thu, 19 Jul 2001 18:39:13 +0100
- CC: xsl-list at lists dot mulberrytech dot com
- Organization: Jeni Tennison Consulting Ltd
- References: <OF82F2BE00.B5C5388C-ON86256A8E.005A293D@questia.com>
- Reply-To: xsl-list at lists dot mulberrytech dot com
Hi Lisa,
> I'm having some trouble with newline white space. I fixed this once
> before but can't remember for the life of me how!
>
> The XML looks like this:
> <p>This is a para<hyphen/><lb/>
> graph.</p>
The problem is that this XML has a line break in it after the lb
element, so the tree looks like:
+- (element) p
+- (text) This is a para
+- (element) hyphen
+- (element) lb
+- (text) 
graph.
You may want to just normalise all the text nodes to get rid of the
problem:
<xsl:template match="text()">
<xsl:value-of select="normalize-space()" />
</xsl:template>
or perhaps only those that have an lb element as their
immediately-preceding sibling.
> Ideally, there would not be a <hyphen/> tag, but ­, but I
> couldn't figure out how to do that either.
If you have:
<p>This is a para­<lb/>
graph.</p>
Then you need to check whether the last character of the text node
before the lb element is a '­' character to decide what to do.
You can get that last character using the substring() function:
<xsl:template match="lb">
<xsl:variable name="text" select="preceding-sibling::text()[1]" />
<xsl:if test="substring($text, string-length($text)) != '­'">
<fo:inline>
<xsl:text> </xsl:text><xsl:apply-templates />
</fo:inline>
</xsl:if>
</xsl:template>
(BTW, there's no point in applying templates in the lb element if it's
an empty element, as it seems to be in your example.)
I hope that helps,
Jeni
---
Jeni Tennison
http://www.jenitennison.com/
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list