469,358 Members | 1,659 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,358 developers. It's quick & easy.

The normalize-space

Hi all

I'm trying to get a value from an xml node 'Publisher' use the value as
a name of an .css class. This works fine until I get a value from the
Publisher node with white space in it.
I've been trying to use normalize-space function on this but I can't
make this work

here is what I'm trying to do

<xsl:attribute name="class">color<xsl:value-of
select="normalize-space(Publisher)"/></xsl:attribute>

Can anyone help me, I've spent to much time on this already..
Thanks
K.

Dec 12 '06 #1
4 2479
normalize-space doesn't remove spaces, just trims off the ends and compacts
multiple whitespace to a single character.
Perhaps you can use translate(' ', '_') to change all spaces to an
underscore, maybe after normalize-space?

--

Joe Fawcett (MVP - XML)

http://joe.fawcett.name

<ko*********@gmail.comwrote in message
news:11**********************@j44g2000cwa.googlegr oups.com...
Hi all

I'm trying to get a value from an xml node 'Publisher' use the value as
a name of an .css class. This works fine until I get a value from the
Publisher node with white space in it.
I've been trying to use normalize-space function on this but I can't
make this work

here is what I'm trying to do

<xsl:attribute name="class">color<xsl:value-of
select="normalize-space(Publisher)"/></xsl:attribute>

Can anyone help me, I've spent to much time on this already..
Thanks
K.

Dec 12 '06 #2
ko*********@gmail.com wrote:
I'm trying to get a value from an xml node 'Publisher' use the value as
a name of an .css class. This works fine until I get a value from the
Publisher node with white space in it.
I've been trying to use normalize-space function on this but I can't
make this work

here is what I'm trying to do

<xsl:attribute name="class">color<xsl:value-of
select="normalize-space(Publisher)"/></xsl:attribute>
CSS class names can't contain white space, if you end up with e.g.
<div class="class name">
then the div elements belongs to two classes, one with name "class", the
second with name "name".

If you want to strip spaces from Publisher then use e.g.

<xsl:attribute name="class">color<xsl:value-of
select="translate(Publisher, ' ', '')"/></xsl:attribute>

If you want to use '-' instead of space then you could do e.g.

<xsl:attribute name="class">color<xsl:value-of
select="translate(normalize-space(Publisher), ' ', '-')"/></xsl:attribute>
--

Martin Honnen --- MVP XML
http://JavaScript.FAQTs.com/
Dec 12 '06 #3

ML wrote:
Could you give an example of the value in Publisher?
ML

---
http://milambda.blogspot.com/
Hi
The value is 'Pan vision' and I have to remove the whitespace or
replace it with _ so it will be 'PanVision' or 'Pan_Vision'.

Dec 12 '06 #4
Thanks Martin - this works like a charm :o)

Martin Honnen wrote:
ko*********@gmail.com wrote:
I'm trying to get a value from an xml node 'Publisher' use the value as
a name of an .css class. This works fine until I get a value from the
Publisher node with white space in it.
I've been trying to use normalize-space function on this but I can't
make this work

here is what I'm trying to do

<xsl:attribute name="class">color<xsl:value-of
select="normalize-space(Publisher)"/></xsl:attribute>

CSS class names can't contain white space, if you end up with e.g.
<div class="class name">
then the div elements belongs to two classes, one with name "class", the
second with name "name".

If you want to strip spaces from Publisher then use e.g.

<xsl:attribute name="class">color<xsl:value-of
select="translate(Publisher, ' ', '')"/></xsl:attribute>

If you want to use '-' instead of space then you could do e.g.

<xsl:attribute name="class">color<xsl:value-of
select="translate(normalize-space(Publisher), ' ', '-')"/></xsl:attribute>
--

Martin Honnen --- MVP XML
http://JavaScript.FAQTs.com/
Dec 12 '06 #5

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

3 posts views Thread by Christos TZOTZIOY Georgiou | last post: by
4 posts views Thread by Nathan Benefield | last post: by
5 posts views Thread by =?iso-8859-1?B?TWF0dGlhcyBCcuRuZHN0cvZt?= | last post: by
dmjpro
5 posts views Thread by dmjpro | last post: by
9 posts views Thread by Peter Bengtsson | last post: by
1 post views Thread by asharda | last post: by
1 post views Thread by CARIGAR | last post: by
reply views Thread by zhoujie | last post: by
1 post views Thread by Marylou17 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.