[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Re: xsl:sequence

Subject: Re: xsl:sequence
From: "tom tom" <tomxsllist@xxxxxxxxxxx>
Date: Wed, 09 Aug 2006 12:50:06 +0100
foo text download
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@xxxxxxxxx>
Reply-To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
Subject: Re:  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



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


Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.