Re: [xsl] Continuing problem. &NotaWhitespace;?

Subject: Re: [xsl] Continuing problem. &NotaWhitespace;?
From: tcn@xxxxxxxxxxxxx (Trevor Nash)
Date: Thu, 01 Nov 2001 18:06:38 GMT
On Thu, 1 Nov 2001 18:36:25 +0000, John Ericson wrote:

>On Nov 01 16:20, Jeni Tennison wrote:
>> This gives you a template like:
>> <xsl:template match="text()">
>>   <xsl:variable name="normalizedString" select="normalize-space()" />
>>   <xsl:if test="not(normalize-space(substring(., 1, 1)))">
>>     <xsl:text> </xsl:text>
>>   </xsl:if>
>>   <xsl:value-of select="$normalizedString" />
>>   <xsl:if test="not(normalize-space(substring(., string-length())))">
>>     <xsl:text> </xsl:text>
>>   </xsl:if>
>> </xsl:template>
>This is more like what I thought of, but this has the problem of that if
>the line contains several whitespaces in the beginning it will get *one*
>whitespace added to the beginning. It should have none in that case.
I think you are misreading Jeni's code.  Given your input

   <link url="231243342">SpazeIRC</link> blablablabla bla...

you will get

   SpazeIRC blablablabla bla...

which is what you *said* you wanted.

If you had instead

   <link url="231243342">SpazeIRC</link>      blablablabla bla...

I assume you still want the result to have a single space between RC
and blabla, right?
>This would put *one* whitespace infront of the line who begins with *one*
>whitespace, not several.

Jeni's code does just this.

BTW earlier I wrote in response to Kevin's suggestion:

>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

or to put it on a plate for you:

 <xsl:template match="text()">
   <!-- normalize-space removes external spaces, but we want them
        normalised - so we make them internal by adding a couple of
        extra characters. -->
   <xsl:variable name="normalizedString"
        select="normalize-space(concat('x', concat(., 'x')))" />
   <!-- remove the extra characters when using the result -->
   <xsl:value-of select="substring($normalizedString, 2,
                  string-length($normalizedString)-2)" />

This does the same as Jeni's version, but might be easier to follow.
Does that help?

If not, you will have to tell us *precisely* what you want done.

BTW please do not keep changing the subject line - it makes it very
hard to follow the thread.

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