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

Re: Continuing problem. &NotaWhitespace;?

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

>On Nov 01 16:20, Jeni Tennison wrote:
>>[[snip]]
>> 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
>space.

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)" />
 </xsl:template>

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.

Regards,
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:  http://www.mulberrytech.com/xsl/xsl-list


Current Thread

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.