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

RE: normalize-space problems with child elements

Subject: RE: normalize-space problems with child elements
From: "Michael Kay" <mike@xxxxxxxxxxxx>
Date: Tue, 29 Mar 2005 19:09:01 +0100
normalize space
You have to face facts: the spaces adjacent to a <code> element are
significant, so you can't use a function like normalize-space() that
destroys them. I don't think there are any short-cuts here.

Michael Kay
http://www.saxonica.com/
 

> -----Original Message-----
> From: Jelks Cabaniss [mailto:jelks@xxxxxxxx] 
> Sent: 29 March 2005 18:39
> To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
> Subject:  normalize-space problems with child elements
> 
> I'm using the text output method to create a man page.
> 
> In my source XML, I have `<description>` elements which 
> contain text and
> `<code>` child elements.  `<description>` is "pretty printed" 
> (indented and
> with line breaks) which is easily fixed with 
> "normalize-space".  So far so
> good.  But that does weird stuff to the `<code>` child elements -- it
> removes the space before and after the `<code>foo</code>` so 
> that the word
> "foo" adjoins the surrounding text in the description output.
> 
> Example:
> 
>     <description>This decribes how <code>FOO</code> is
>     supposed to work.  Now "<code>bar</code>" is a 
>     different story altogether.</description>
> 
> ...
> 
>     <xsl:template match="description">
>       <xsl:apply-templates />
>     </xsl:template>
> 
>     <xsl:template match="code">
>       <xsl:apply-templates />
>     </xsl:template>
> 
>     <xsl:template match="text()">
>       <xsl:value-of select="normalize-space(.)" />
>     </xsl:template>
> 
> 
> Output:
> 
>     This decribes howFOOis supposed to work.
>     Now "bar" is a different story altogether.
> 
> 
> Since "bar" was surrounded by quotes and not whitespace, it 
> worked.  But see
> how "FOO" was mangled by "normalize-space"?  
> 
> If I change the `code` template to add spaces before and 
> after, it fixes
> "FOO", but breaks "bar":
> 
>     <xsl:template match="code">
>       <xls:text> </xls:text>
>         <xsl:apply-templates />
>       <xls:text> </xls:text>
>     </xsl:template>
> 
> Is there a way to do this without involving a complex template with
> substring processing, etc.?
> 
> 
> /Jelks

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.