Discussion:
Losing white space when identity transform
Karl J. Stubsjoen
2004-03-18 05:53:43 UTC
Permalink
Hello,

So close on this. I have some XHMTL... looks like this:

<f>We need to know just a little bit about you to get started. Please
supply us with your first name, last name, and <b>(important)</b> a valid
email.</f>

I am transforming like this:

<xsl:template match="*">
<xsl:element name="{local-name()}">
<xsl:copy-of select="@*"/>
<xsl:apply-templates/>
</xsl:element>
</xsl:template>

But am losing my white-space around the <b> elements... what is up with
that? I know this has been discussed before. Seems like there is a fix for
this.

Karl


XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
Jeni Tennison
2004-03-18 09:32:33 UTC
Permalink
Hi Karl,
Post by Karl J. Stubsjoen
But am losing my white-space around the <b> elements... what is up
with that? I know this has been discussed before. Seems like there
is a fix for this.
The text before and after the <b> element is probably output according
to the template that you have for text nodes. If you're losing the
leading and trailing whitespace from those text nodes, my guess would
be that you have a template that uses normalize-space() to output the
value of the text nodes, as in:

<xsl:template match="text()">
<xsl:value-of select="normalize-space()" />
</xsl:template>

If so, you need to change this template to:

<xsl:template match="text()">
<xsl:value-of select="." />
</xsl:template>

(or just omit it altogether, since this is the same as the built-in
template for text nodes).

If you don't have a template like that, please send the part of your
stylesheet that deals with text nodes and we should be able to figure
out how to change it to handle the whitespace correctly.

Cheers,

Jeni

---
Jeni Tennison
http://www.jenitennison.com/


XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
Michael Kay
2004-03-18 10:00:40 UTC
Permalink
You shouldn't lose the whitespace around the <b> elements. What XSLT
processor are you using?

Michael Kay

# -----Original Message-----
# From: owner-xsl-***@lists.mulberrytech.com
# [mailto:owner-xsl-***@lists.mulberrytech.com] On Behalf Of
# Karl J. Stubsjoen
# Sent: 18 March 2004 05:54
# To: xsl-***@lists.mulberrytech.com
# Subject: [xsl] Losing white space when identity transform
#
# Hello,
#
# So close on this. I have some XHMTL... looks like this:
#
# <f>We need to know just a little bit about you to get
# started. Please supply us with your first name, last name,
# and <b>(important)</b> a valid email.</f>
#
# I am transforming like this:
#
# <xsl:template match="*">
# <xsl:element name="{local-name()}">
# <xsl:copy-of select="@*"/>
# <xsl:apply-templates/>
# </xsl:element>
# </xsl:template>
#
# But am losing my white-space around the <b> elements... what
# is up with that? I know this has been discussed before.
# Seems like there is a fix for this.
#
# Karl
#
#
# XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
#
#


XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
Karl J. Stubsjoen
2004-03-18 15:16:41 UTC
Permalink
Jeni: I do not have a template that would normalize-space. I do not see
that anywhere.
Michael: I am using MSXML2.

Wow! Just threw in:

<xsl:template match="text()">
<xsl:value-of select="." />
</xsl:template>

And I got my spaces back. Go figure.
Correction!! Jeni, you were right, I do have the template:

<xsl:template match="text()">
<xsl:value-of select="normalize-space(.)"/>
</xsl:template>

The above template rule is over-riding the below, which comes as part of a
library of XSLT template rules that I include for all of my web projects.
I'm really not sure why I have that in there. I think I will remove it.

Karl

P.S. I love it when you guys are right


XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
Michael Kay
2004-03-18 16:07:07 UTC
Permalink
#
# P.S. I love it when you guys are right
#

And it's great to see Jeni back, having lost none of her unique ability to
reverse-engineer incorrect stylesheets from their incorrect output!

Michael Kay


XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
Loading...