xsl-list
[Top] [All Lists]

Re: [xsl] xsl:sequence

2006-08-09 04:50:29
OK and I've just discovered that <xsl:sequence select="foo/text()"/> also returns "a c".

My point is that if xsl:sequence can mimic xsl:value-of behavior in this way whats the point of using xsl:value-of ever? Removing xsl:value-of from the list of elements you need to get your head around will make XSLT easier to grasp, in my opinion this outweighs the extra effort of having to append XPaths with 'text()'.



From: David Carlisle <davidc(_at_)nag(_dot_)co(_dot_)uk>
Reply-To: xsl-list(_at_)lists(_dot_)mulberrytech(_dot_)com
To: xsl-list(_at_)lists(_dot_)mulberrytech(_dot_)com
Subject: Re: [xsl] xsl:sequence
Date: Wed, 9 Aug 2006 10:30:24 +0100

> Can anyone tell me when I should be using value-of, when i should be using
> copy-of and when I should be using sequence?

I'll have a try, although I made one or two errors last time.

> >............................................................., some people
> >tend to
> >over-use text() it makes the stylesheet rather fragile as it means that
> >source files with comments in often fail
>
> But how else can you retreive the value of an element when it is text?

use value-of.

In XSLT 1.0

given <foo>a <!-- b -->c</foo>

then
<xsl:value-of select="foo"/> is a text node "a c" and
 <xsl:value-of select="foo/text()"/> is a text node "a "
which is usually not what you want to happen just because someone added
a comment.
In XSLT2 value-of does produce the value of the whole sequence and
re-merges text nodes, so actually inthi scase in xslt2
 <xsl:value-of select="foo/text()"/> is text node "a c"
but it's simpler for you and teh system just to go
<xsl:value-of select="foo"/>
Of course, if there are child elements of foo and you only want top
level text  then you may have to use text() to obtain that but that's a
ratherr are requirement. Normally if their is mixed content you need
_all_ the content, the contentthatjust happens to be at the top level
isn't so often interesting.

xsl:value-of always generates a _text node_ so use it when you want
to generate text.

<p><i>This</i> is <b>bold</b> text</p>

Then (in XSLT2)

<xsl:value-of select="p" produces a text node "This is bold text"

<xsl:value-of select="p/text()" produces a text node " is  text"

<xsl:sequence select="p"/> returns the _same_ p node
     <p><i>This</i> is <b>bold</b> text</p>

<xsl:copy-of select="p"/> returns a _new_ p node
     <p><i>This</i> is <b>bold</b> text</p>


xsl:copy-of is there with the semantics it has because of xslt1,
although to be honest I can't think off hand of any case where you would
need to use xsl:copy-of rather than xsl:sequence.


David




--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--


_________________________________________________________________
Windows Live? Messenger has arrived. Click here to download it for free! http://imagine-msn.com/messenger/launch80/?locale=en-gb


--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--

<Prev in Thread] Current Thread [Next in Thread>