xsl-list
[Top] [All Lists]

Re: [xsl] normalize-space() except ...

2015-02-09 18:52:18
To All,
When I don't want normalize-space() in a mixed content text flow I use this 
function to preserve any leading and trailing space which the normalize-space() 
would eliminate
<!-- 
============================================================================= 
-->
<!-- this function is a single parm which is the text value to be cleanup NOT 
normalized -->
<!-- leading and trailing spaces are preserved but runs of white space 
characters become a single space -->
<!-- This means that tab, 0A and 0D should vanish. -->
<xsl:functionname="tb:string-cleanup">
<xsl:paramname="string"/>
<xsl:variablename="string-to-output">
<xsl:analyze-stringselect="$string"regex="\s+">
<xsl:matching-substring>
<xsl:text> </xsl:text>
</xsl:matching-substring>
<xsl:non-matching-substring>
<xsl:value-ofselect="."/>
</xsl:non-matching-substring>
</xsl:analyze-string>
</xsl:variable>
<xsl:iftest="$DEBUG-string-cleanup = 'yes' and $string != $string-to-output">
<xsl:message>
<xsl:text>STRING CHANGED FROM [</xsl:text>
<xsl:copy-ofselect="$string"/>
<xsl:text>]&#x0A;TO [</xsl:text>
<xsl:copy-ofselect="$string-to-output"/>
<xsl:text>]</xsl:text>
</xsl:message>
</xsl:if>
<xsl:copy-ofselect="$string-to-output"/>
</xsl:function>

 
Terry


On Monday, February 9, 2015 7:31 PM, "Christopher R. Maden 
crism(_at_)maden(_dot_)org" 
<xsl-list-service(_at_)lists(_dot_)mulberrytech(_dot_)com> wrote:



On 02/09/2015 06:23 PM, Liam R E Quin liam(_at_)w3(_dot_)org wrote:
I'd probably do this in two steps -
(1) match text() and turn one or more whitespace characters into a
space, probably using replace()
(2) strip leading space from the first text() in p, and trailing
space from the last;

My algorithm (for which I can’t find code right now, but may rewrite
later) is to concatenate the following:

1) If the text node starts with a space, a single space.

2) The results of normalize-space().

3) If the text node ends with a space, a single space.

~Chris
-- 
Chris Maden, text nerd  <URL: http://crism.maden.org/ >
Surround hate and force it to surrender.
GnuPG fingerprint: DB08 CF6C 2583 7F55 3BE9  A210 4A51 DBAC 5C5C 3D5E
--~----------------------------------------------------------------
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
EasyUnsubscribe: http://lists.mulberrytech.com/unsub/xsl-list/1167547
or by email: xsl-list-unsub(_at_)lists(_dot_)mulberrytech(_dot_)com
--~--

<Prev in Thread] Current Thread [Next in Thread>