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

Re: Combination of normalize-space() and apply-templat

Subject: Re: Combination of normalize-space() and apply-templates
From: David Carlisle <davidc@xxxxxxxxx>
Date: Thu, 26 Feb 2004 10:40:09 GMT
xsl normalize space

  <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.

The easy thing to do is normalize each text node of the para separately,
to do that you go


<xsl:template match="para">
<p>
 <xsl:apply-templates/>
</p>
</xsl:template>


<xsl:template match="emph">
<em>
 <xsl:apply-templates/>
</em>
</xsl:template>


and have


<xsl:template match="para/text()">
 <xsl:value-of select="normalize-space(.)"/>
</xsl:template>

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>


-- 
http://www.dcarlisle.demon.co.uk/matthew


________________________________________________________________________
This e-mail has been scanned for all viruses by Star Internet. The
service is powered by MessageLabs. For more information on a proactive
anti-virus service working around the clock, around the globe, visit:
http://www.star.net.uk
________________________________________________________________________

 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.