[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Re: newline white space

Subject: Re: newline white space
From: Jeni Tennison <mail@xxxxxxxxxxxxxxxx>
Date: Thu, 19 Jul 2001 18:39:13 +0100
newline and space in html
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) &#xA;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 &#x00AD;, but I
> couldn't figure out how to do that either.

If you have:

<p>This is a para&#xAD;<lb/>
graph.</p>

Then you need to check whether the last character of the text node
before the lb element is a '&#xAD;' 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)) != '&#xAD;'">
    <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


Current Thread
  • newline white space
    • Lisa Rupe - Thu, 19 Jul 2001 12:40:51 -0400 (EDT)
      • Jeni Tennison - Thu, 19 Jul 2001 13:42:42 -0400 (EDT) <=
        • ram ragu - Thu, 19 Jul 2001 15:02:04 -0400 (EDT)
      • <Possible follow-ups>
      • Lisa Rupe - Thu, 19 Jul 2001 21:32:18 -0400 (EDT)

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.