[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: Jarno.Elovirta@xxxxxxxxx
Date: Thu, 26 Feb 2004 12:42:09 +0200
xsl normalize space
Hi,

> I am using xsltroc (from libxslt 1.1.0). When I m trying to normalize
> the space in certain elements, I got stuck since I couldn't 
> figure out,
> how to apply normalize-space() and apply templates for 
> elements within a
> node. Example:
> 
> <document>
>  <para>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 <emp>within</emp>
>  which should also be processed.
>  </para>
> <document>
> 
> If I write a template like this:
> 
> <xsl:template match="document">
>  <xsl:apply-templates select="normalize-space(para)" />
> </xsl:template>
> 
> It doesn't work. But if I do it this way:
> 
> <xsl:template match="document">
>  <xsl:apply-templates select="para" />
> </xsl:template>
> 
> <xsl:template match="para">
>  <xsl:value-of select="normalize-space(para)" />
> </xsl:template>
> 
> It worked, but the inline element won't get processed.

Did you want something in the lines of

  <xsl:template match="para/text()">
    <xsl:if test="preceding-sibling::node()">
      <xsl:text> </xsl:text>
    </xsl:if>
    <xsl:value-of select="normalize-space()"/>
    <xsl:if test="following-sibling::node()">
      <xsl:text> </xsl:text>
    </xsl:if>
  </xsl:template>
  <xsl:template match="@* | node()">
    <xsl:copy>
      <xsl:apply-templates select="@* | node()"/>
    </xsl:copy>
  </xsl:template>

Cheers,

Jarno - Chris C: The Zurich Mix <http://mp3.hardnrg.com/chrisc/ChrisC-The_Zurich_Mix-June_2003.mp3>

 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.