The simple answer here is that there is no simple answer here. XSLT is
defined on top of XPath, and is defined in terms of processing complete
infosets. These yield slightly  different ways of looking at the question.


In XPath, "/" means the root of the Infoset, even if your starting context
is deep in the document... so a DOMSource can legitimately be interpreted
that way.  In this mode, "/" may be an ancestor of the DOMSource's starting
point, and that's fine.

The other approach, if you really need to define where "/" will be, is to
create a new Infoset to isolate the subtree. You can do this even with a
DOMSource that sees the whole source document -- it just requires that you
move that subtree out of the context of the larger Document before
processing (and, presumably, move it back after you're done). That's cheap
and easy to do in most DOM implementations, and even fairly efficient;
create a DocumentFragment node, move the node you want to process into
that, transform, and put the node back where it came from. If the source
may be read-only, this workaround becomes more expensive; you have to
clone/import the subtree into a new context before transforming it.

Internally, Xalan has dithered between building a new document model to
represent the subtree and trying to operate against the source document,
and has thus sometimes more closely resembled one or the other of those two
behaviors. My personal take is that since XSLT doesn't actually define the
concept of processing a subtree, either is equally defensible, and I'd
rather leave the processor free to make this decision one way or the other
as it sees fit for efficiency reasons. So I lean toward "Don't use absolute
paths with relative starting points; if you must, then it's up to you to
defensively clone the tree. We might clone it or we might not, but you
shouldn't count on our doing so."

This is certainly debatable. But given that we're attempting to move *away*
from our current bad habit of recopying significant amounts of data into
our internal models, I think it's the best long-term answer.

______________________________________
Joe Kesselman, IBM Next-Generation Web Technologies: XML, XSL and more.
"The world changed profoundly and unpredictably the day Tim Berners Lee
got bitten by a radioactive spider." -- Rafe Culpin, in r.m.filk

Reply via email to