469,299 Members | 2,081 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

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

When to use <xsl:text>

When is the use of <xsl:text>blah blah</xsl:text> necessary? I'm finding
that, although it's used religously in the book I'm learning from, if I
miss it out, the output is just the same.
Jul 20 '05 #1
3 3383
Derek

the main reason you want to use this is when whitespace is significant in
the result document. For instance, consider this snippet of xsl

<h1>
details for user
<xsl:value-of select="@username"/>
in group
<xsl:value-of select="@groupname"/>
</h1>

the text node for the phrase 'details for user' starts just after the
closing > of <h1> and ends just before the opening < of <xsl:value-of>. All
this extra whitespace will be copied into the resulting output. This doesn't
normally matter with HTML but you might be using an output format where
whitespace is significant or you maybe want the HTML to look nice. in this
case you can do this:

<h1>details for user<xsl:value-of select="@username"/>in group<xsl:value-of
select="@groupname"/></h1>

but this can get unwieldy (and if you use a pretty printer to reformat your
XSL it might break it up again). Here's where xsl:text comes in:

<h1>
<xsl:text>details for user</xsl:text>
<xsl:value-of select="@username"/>
<xsl:text>in group</xsl:text>
<xsl:value-of select="@groupname"/>
</h1>

now you have no whitespace within those text nodes. Instead you have created
some new text nodes which just contain the whitespace but fortunately the
XSLT processor will ignore those.

Dealing with whitespace in XSL is a pain the butt and you usually don't need
to bother. on those occasions where you need to control the whitespace that
gets generated, xsl:text is the way to do it

HTH

Andy

"Derek Fountain" <no****@hursley.ibm.com> wrote in message
news:3f***********************@freenews.iinet.net. au...
When is the use of <xsl:text>blah blah</xsl:text> necessary? I'm finding
that, although it's used religously in the book I'm learning from, if I
miss it out, the output is just the same.

Jul 20 '05 #2
"Derek Fountain" <no****@hursley.ibm.com> wrote in message
news:3f***********************@freenews.iinet.net. au...
When is the use of <xsl:text>blah blah</xsl:text> necessary?
I'm finding that, although it's used religously in the book I'm
learning from, if I miss it out, the output is just the same.


I'm no guru but I'd say the element probably comes into play whenever you
are using variables rather than actual text. A similar scenario is possible
with <xsl:element name="Mine">, which is equivalent to simply entering
<Mine>, but because the attriibute is quoted text, you can use a variable
instead.

hth
Christopher Boomer
Jul 20 '05 #3
<snip!>
HTH

Andy


Yes, it did help, thanks. Makes sense now... :o)
Jul 20 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

2 posts views Thread by websls | last post: by
5 posts views Thread by Luke Vogel | last post: by
2 posts views Thread by Paul Verbelen | last post: by
4 posts views Thread by C.W.Holeman II | last post: by
3 posts views Thread by Petterson Mikael | last post: by
reply views Thread by zhoujie | last post: by
reply views Thread by suresh191 | last post: by
reply views Thread by harlem98 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.