Re: [xsl] Combination of normalize-space() and apply-templates

Subject: Re: [xsl] Combination of normalize-space() and apply-templates
From: Andreas Grytz <agrytz@xxxxxxxxxxxxx>
Date: Thu, 26 Feb 2004 13:48:06 +0100
On Thu, Feb 26, 2004 at 10:40:09AM +0000, David Carlisle wrote:
>   <xsl:template match="document">
>    <xsl:apply-templates select="normalize-space(para)" />
>   </xsl:template>
> 
>   It doesn't work. But if I do it this way:
> 
> normalize-space returns a string and you can't apply templates to a
> string, only to nodes.

OK, that's clear.
> 
> However that will normalize the two text nodes separately, producing
> 
> <p>Some text, that is wrapped several times, but should be one line in the output document. And which has -- to make it tricky -- some Elements<em>within</em>which should also be processed.</p>
> 
> and the space around the emph has gone, so you need to put something
> more like
> 
> <xsl:template match="para/text()">
>  <xsl:if test="preceding-sibling::* and (starts-with(.,' ') or
>                                          starts-with(.,'&#10;'))">
>    <xsl:text> </xsl:text>
>  </xsl:if>
>  <xsl:value-of select="normalize-space(.)"/>
>  <xsl:if test="following-sibling::* and (substring(.,string-length(.)-1)=' ' or
>                    substring(.,string-length(.)-1)='&#10;')">
>    <xsl:text> </xsl:text>
>  </xsl:if>
> </xsl:template>
[Missing quotes added and one bracket deleted]

That one worked, except fo the trailing blank. What does it do? Take the
string between to elements. Examine, wether the first character is a
blank or a newline(?). Normalize all space and examine, wether the last
character is a blank or newline. But, can there be a trailing character,
which matches the condition?

To put it clear: Are these instructions proccessed one after each other?

If so, the last condition will always fail, because we already
normalized the string.

Anyway, thanks a lot for the insight.

Andreas

-- 
Andreas Grytz		| http://www.linuxnewmedia.de
Stefan-George-Ring 24	| Tel:	+49 (0) 89 993411-0
D-81929 München		| Fax:	+49 (0) 89 993411-99

 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list


Current Thread