[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: Tue, 08 Aug 2006 11:07:51 +0100
xsl changing node pointer
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.

I am unclear when I should using value-of and copy-of.


> I was thinking that an attribute node contains a text node. Reading up on it
> an attribute node seems to *be* both the attribute name and its value. When
> it is co-erced to an atomic xs:double value it somehow loses the attribute
> name part and just takes on the value - this is what I was referring to as
> waste.



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?


Am I delving into things I shouldn't be delving into here?



From: David Carlisle <davidc@xxxxxxxxx>
Reply-To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
Subject: Re:  xsl:sequence
Date: Mon, 7 Aug 2006 16:41:25 +0100

> I was referring to constructing a copy of the node in the output and by the
> sounds of it I'm right in still calling this a copy.


in an implementation you may be right that xsl:sequence acts like
xsl:copy-of in this context but that isn't the way the semantics are
described (and isn't the best way to think about it)

the body of an xsl instruction (xsl:template, xsl:variable, xsl:if, etc)
is always evaluated the smae way and always generates a _sequence_ so
the semantics of a particular instruction such as xsl:sequence within
that xsl instruction doesn't change depending on what the parent is.
What does change is what happens to the sequence once it is constructed.
Whether it is copied to an output, stored in a variable, merged into the
sequence being constructed by another instruction etc. In th ecase of
the main result tree, it's possible that the system never materialises
the sequence in memory and never actually makes the nodes in teh result
tree either, but simply directly serialises the result to an XMl
document. But that's an optimisation that doesn't affect the semantics
of the instructions.

> If a variable value is a reference rather than a copy what advantages
> does that provide?

it's a lot faster and a lot less memory.

If you go
<xsl:variable name="a" as="document-node()">
 <xsl:copy-of select="/"/>
</xsl:variable>

<xsl:variable name="b" as="document-node()">
 <xsl:sequence select="/"/>
</xsl:variable>


then $b is simply a pointer to the current document, which takes no time to build and hardly any space to store, and $b is / is true.

on the other hand $a is a document structurally identical to the
current document but it is a copy, so it takes time and memory
proportional to the size of the document to build, and $a is / is false.


> I was thinking that an attribute node contains a text node. Reading up on it
> an attribute node seems to *be* both the attribute name and its value. When
> it is co-erced to an atomic xs:double value it somehow loses the attribute
> name part and just takes on the value - this is what I was referring to as
> waste.


It may be take less space to store the sequence of attribute nodes
depends on the implementation, but logically it is just a sequence of
pointers into the existing tree, so the data doesn't need to be copied,
conversely if you store the data then you are copying the data and need
to store the sequence of doubles which may or may not be more data than
a sequence of attribute node pointers. Also of course often you _need_
to store a list of attribute nodes, for example if you need to know
whhat there parents are $variable/.. wil work on a sequence of attribute
nodes, to give a sequence of elements.

But it's wrong to think of xsl:sequence as an optimisation of
xsl;copy-of normally the important thing is that one works and the other
doesn't. (You can usually replace copy-of by sequence, but not always,
you usually can't replace xsl:sequence by copy-of)

David


_________________________________________________________________
Be the first to hear what's new at MSN - sign up to our free newsletters! http://www.msn.co.uk/newsletters


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.