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

Re: normalize-space() except ...

Subject: Re: normalize-space() except ...
From: "Graydon graydon@xxxxxxxxx" <xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx>
Date: Mon, 9 Feb 2015 20:42:33 -0000
Re:  normalize-space() except ...
On Mon, Feb 09, 2015 at 08:21:16PM -0000, dvint@xxxxxxxxx scripsit:
[that thing where normalize-space() takes the trailing space off a text
node followed by an inline markup element and no one is happy]
> I'm just wondering if there is a better solution for handling this in XSLT
> than basically writing my own normalize-space function. The real solution
> would be to get the importing tool to handle the text properly and
> normalize on import, but that is not an option.

This is always kinda difficult because of the definition of white space.

XSLT 2.0 lets you do useful things with regular expressions and the
Unicode space character category, \p{Zs}, so you can replace all
sequential white space with one regular space, but of course line feeds
aren't spaces so you have to add that in --

<xsl:template match="text()">
    <xsl:value-of select="replace(.,'[\p{Zs}&#x000A;]+','&#x0020;')"/>
</xsl:template>

which won't strip the trailing space.  It might still qualify as having
to re-write normalize-space().

The XSLT 1.0 solution involves substring() and string-length(); you saw
off the last character, normalize the substring of everything but the
last character, and concat() them back together.  This has the
disadvantage of leaking non-breaking spaces.

-- Graydon

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.