Re: [xsl] normalize-space()?

Subject: Re: [xsl] normalize-space()?
From: Abel Braaksma <abel.online@xxxxxxxxx>
Date: Tue, 31 Oct 2006 20:47:05 +0100
Luke Jones wrote:
<xsl:template match="covers">
	[<xsl:apply-templates select="normalize-space(covers)" />]
</xsl:template>

Currently this doesn't pull anything from the covers tag, all I get is
empty [].

One thing puzzles me here. Do you really want to match a node that looks like this:


covers/covers

Likely, you want to match the node 'covers/*' or similar (not sure). Are there templates that need to be applied? I assume so, because you add the comma from some place. If indeed the xpath is incorrect, try this:

<xsl:template match="covers">
   [<xsl:apply-templates select="normalize-space(*)" />]
</xsl:template>


When I leave out the select portion of the expression I get [ LB 101, LR
1332 ].  What I want is [LB 101, LR 1332]. Is the normalize-space
function the way to go to achieve this?

You are doing it the right thing. However, be aware that normalize-space() also "folds" all other space nodes. That means that the following:


<node>  this   is     text
with spaces   </node>

becomes:

<node>this is a text with spaces</node>

It that is what you want, it will work.

Cheers,
-- Abel Braaksma
  http://www.nuntia.com

Current Thread