RE: [xsl] A parameter current context or context passed

Subject: RE: [xsl] A parameter current context or context passed
From: "Michael Kay" <mike@xxxxxxxxxxxx>
Date: Sun, 15 May 2005 11:45:52 +0100
> When you say, "the context node is the root of a tree", what does that
> mean exactly?  

I think you need to do some reading!

A tree is the internal representation of an XML document: you can't write
XSLT without understanding this. There are slight variations between the
tree model in 1.0 and 2.0, let's stick to 1.0 for now. There are seven kinds
of node in a tree (elements, text nodes, attribute nodes text nodes,
comments, processing instructions, and the node representing the document
itself which 1.0 calls the root node and 2.0 calls a document node.)

At any point in XSLT or XPath processing there is a context node (or current
node - XSLT calls it the current node, XPath the context node). A node
becomes the context node when it is processed using xsl:for-each or
xsl:apply-templates or when you evaluate a predicate in a path expression.
When you start processing, the context node is the root node of the
principal source document.

The XPath expression "." gives you the context node. The expression "/"
gives you the root node of the tree that contains the context node. The "|"
operator gives you the union of two sets of nodes. So (. | /) gives you the
node-set that contains both the context node and the root of the tree
containing the context node. If these are the same node, this node-set will
contain one node, otherwise it will contain two.

Any clearer?

Michael Kay
http://www.saxonica.com/




And when refering to (what I call the SourceXML) how do
> you refer to that in XSLT specification?  I haven't seen a simple
> glossary on these sort of terms.  Is there one on the net somewhere?
> 
> Thanks for the corrections, I'm lov'n XSLT but can be a bit slow with
> the verbiage (sorry).
> 
> 
> On 5/13/05, Michael Kay <mike@xxxxxxxxxxxx> wrote:
> > > Hmm.  So if I excpicitly pass in my context through my param
> > > "current", doesn't the "/" resolve the same as the "." for the
> > > variable passed in?
> > 
> > If you explicitly pass a value for the parameter then the 
> select expression
> > in xsl:param is irrelevant: it's only used when you don't 
> supply a value.
> > 
> > You're using language here "resolve the same as.. for the 
> variable" which I
> > don't understand; it would be easier if you used the language of the
> > specification. You don't pass a variable to a template, you 
> pass a value.
> > 
> > The expression ". | /" (or current() | /) returns one node 
> if the context
> > node is the root of a tree; it returns a node-set 
> containing two nodes if
> > the context node is not the root of the tree.
> > 
> > Michael Kay
> > http://www.saxonica.com/

Current Thread