Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

xsl:strip-space

4 views
Skip to first unread message

Andrew

unread,
Dec 17, 2009, 4:53:37 PM12/17/09
to
Another basic question for you guys. I'm having trouble implementing
the strip-space command. I have an xml that looks like this:

<?xml version="1.0" encoding="utf-8"?>
<?xml-stylesheet type="text/xsl" href="feed.xsl"?>
<rss xmlns:qpm="http://www.quickplaymedia.com" version="2.0">
<channel>
<item><title><![CDATA
[123456789012345678901234567890123456789012345678901234567890]]></
title></item>

<item><title><![CDATA[The national weather forecast]]
></title></item>

<item><title>
<![CDATA[Six bodies recovered at B.C. plane
crash]]>
</title></item>

<item><title>
<![CDATA[Suspect in police deaths hurt,
possibly dead: police]]>
</title></item>
</channel>


in my XSL, i've tried inserting

<xsl:strip-space elements="*"/>

but I presume that command is only for the XSL itself.

I also tried:

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

That didnt seem to do the trick either.

I ended up having to insert normalize-space at every function to have
it work properly, ie

string-length(normalize-space(title)).

Am I missing something here?

Thanks in advance,

Martin Honnen

unread,
Dec 18, 2009, 6:23:06 AM12/18/09
to
Andrew wrote:
> Another basic question for you guys. I'm having trouble implementing
> the strip-space command. I have an xml that looks like this:
>
> <?xml version="1.0" encoding="utf-8"?>
> <?xml-stylesheet type="text/xsl" href="feed.xsl"?>
> <rss xmlns:qpm="http://www.quickplaymedia.com" version="2.0">
> <channel>
> <item><title><![CDATA
> [123456789012345678901234567890123456789012345678901234567890]]></
> title></item>
>
> <item><title><![CDATA[The national weather forecast]]
>> </title></item>
>
> <item><title>
> <![CDATA[Six bodies recovered at B.C. plane
> crash]]>
> </title></item>
>
> <item><title>
> <![CDATA[Suspect in police deaths hurt,
> possibly dead: police]]>
> </title></item>
> </channel>
>
>
> in my XSL, i've tried inserting
>
> <xsl:strip-space elements="*"/>
>
> but I presume that command is only for the XSL itself.

You can strip whitespace only text nodes that way, such as between the
'item' elements.

> I also tried:
>
> <xsl:template match="*">
> <xsl:apply-templates select="normalize-space()">
> </xsl:template>

That does not make any sense at all, the select expression needs to
select nodes while normalize-space() would yield a string.

> That didnt seem to do the trick either.
>
> I ended up having to insert normalize-space at every function to have
> it work properly, ie
>
> string-length(normalize-space(title)).
>
> Am I missing something here?

It is not clear what you want to achieve. If you want to trim leading
and trailing whitespace from the 'title' elements then
normalize-space(title) is the correct way (it also collapses any
whitespace within text however).

--

Martin Honnen --- MVP XML
http://msmvps.com/blogs/martin_honnen/

terminate

unread,
Dec 21, 2009, 11:35:16 AM12/21/09
to


Thanks for the clarification, Martin.


0 new messages