Re: [xsl] whitespace problem when formating to plain-text

Subject: Re: [xsl] whitespace problem when formating to plain-text
From: tcn@xxxxxxxxxxxxx (Trevor Nash)
Date: Thu, 01 Nov 2001 09:28:00 GMT
Kevin wrote:

>The normalize function will remove leading and trailing whitespace. It is
>hard to read your xml but you may have to force spaces where needed using
>something like <xsl:text>&#x20</xsl:text>.
BTW there isn't any special magic to using the character entity: you
can just as well write <xsl:text> </xsl:text>.  Its a matter of which
you think is clearer, and if the difference is worth the extra typing
(the best form of documentation is a comment of course).

I have done this kind of thing, and found that blindly adding spaces
around either the text elements or the <link> elements ends up giving
you spaces you do not want (typically at the beginning and end of
sentences or where there is other puctuation).
One way to normalize the space at the ends of the text rather than
losing it is to:
  add a character (x say) at the beginning and end of the string
  use normalize-space on it
  use substring to remove the first and last character from the result
  (i.e. the x's you added to begin with)
Then if the text starts/ends with white space the result will get one

You will need to use temporary variables to do this, unless you don't
mind repeating the normalize - this is because the substring call
needs to know the length of the normalised string.

Trevor Nash
Traditional training & distance learning,
Consultancy by email

Melvaig Software Engineering Limited
voice:     +44 (0) 1445 771 271 
email:     tcn@xxxxxxxxxxxxx

 XSL-List info and archive:

Current Thread