Re: [xsl] normalize-space problems with child elements

Subject: Re: [xsl] normalize-space problems with child elements
From: "G. Ken Holman" <gkholman@xxxxxxxxxxxxxxxxxxxx>
Date: Tue, 29 Mar 2005 12:57:51 -0500
At 2005-03-29 12:39 -0500, Jelks Cabaniss wrote:
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.

That's not exactly "weird", it is doing exactly what you asked for (but it isn't what you want).

How about preserving the existence of leading and trailing white-space by wrapping the node before normalization and unwrapping it after?

An example is below.

I hope this helps, Jelks,

...................... Ken

T:\ftemp>type jelks.xml
<?xml version="1.0" encoding="iso-8859-1"?>
    <description>This decribes how <code>FOO</code> is
    supposed to work.  Now "<code>bar</code>" is a
    different story altogether.</description>
T:\ftemp>type jelks.xsl
<?xml version="1.0" encoding="iso-8859-1"?>
<xsl:stylesheet xmlns:xsl="";

<xsl:output method="text"/>

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

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

<xsl:template match="text()">
  <xsl:variable name="ns" select="normalize-space(concat('x',.,'x'))"/>
  <xsl:value-of select="substring( $ns, 2, string-length($ns) - 2 )" />

T:\ftemp>saxon jelks.xml jelks.xsl
This decribes how FOO is supposed to work. Now "bar" is a different story altogether.

World-wide on-site corporate, govt. & user group XML/XSL training.
G. Ken Holman                 mailto:gkholman@xxxxxxxxxxxxxxxxxxxx
Crane Softwrights Ltd.
Box 266, Kars, Ontario CANADA K0A-2E0    +1(613)489-0999 (F:-0995)
Male Breast Cancer Awareness
Legal business disclaimers:

Current Thread