Re: [xsl] xsl:sequence

Subject: Re: [xsl] xsl:sequence
From: David Carlisle <davidc@xxxxxxxxx>
Date: Tue, 8 Aug 2006 11:20:27 +0100
> If I'm retreiving the value of a text node where I don't need to navigate 
> away from it, I'm not worried about performance and I didn't need to do an 
> identity-related operation I presume I perfectly OK to use value-of or 
> copy-of but there seems to be little point.

value-of and copy-of are the same thing on a text node (although it's
normally fairly rare to access text nodes directly, some people tend to
over-use text() it makes the stylesheet rather fragile as it means that
source files with comments in often fail  given
<foo>onetwo</foo>
<xsl:value-of select="foo"/> and <xsl:value-of select="foo/text()"/>
both generate a text node with value "onetwo". But given
<foo>one<!-- hmm -->two</foo>
<xsl:value-of select="foo"/> generates a text node with value "one two"
<xsl:value-of select="foo/text()"/> generates a text node with value
"one two" in 2.0 mode or "one" in 1.0 compatibility mode.
So unless you intend your code to do something different in the presence
of comments then it's usually better just to select the element.


> But is the following true: an element node's consists of the name of the 
> element; a text node consists of the CDATA assigned to that node; But an 
> attribute node consists of the name of an attribute *as well* as its CDATA - 
> is this not inconsistent?

Nodes have various properties, as well as unique identies (element nodes
can have the same name and content but are not equal (as tested by the
is operator) unless they are "really" the same node.
attribute, text, processing instruction and comment nodes all have
simple content, that is, they have a string valued property (which is
what you mean by CDATA above, although the term CDATA isn't used in XSL
and means something slightly different in XML) element nodes and
document nodes have complex content, so they do not have a string valued
property (their string value is derived from the string value of their
children) they do have other properties, notably properties listing the
child and attribute nodes.

> Am I delving into things I shouldn't be delving into here?
Not at all, it seems to me you are asking how xslt works which couldn't
be more on topic for this list.

David

Current Thread