Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Need help to understand - context node and current node in XPath/XSLT [duplicate]

Tags:

xslt

xpath

nodes

I was going through some online materials from Understanding XPath Processor Terms. Here I found definitions of current node and context node as below.

Current Node Current node is the node that the XPath processor is looking at when it begins evaluation of a query. In other words, the current node is the first context node that the XPath processor uses when it starts to execute the query. During evaluation of a query, the current node does not change. If you pass a document to the XPath processor, the root node is the current node. If you pass a node to the XPath processor, that node is the current node.

Context Node A context node is the node the XPath processor is currently looking at. The context node changes as the XPath processor evaluates a query. If you pass a document to the XPath processor, the root node is the initial context node. If you pass a node to the XPath processor, the node that you pass is the initial context node. During evaluation of a query, the initial context node is also the current node.

Although the definitions are a bit good to understand the difference between current node and context node,examples are not good to understand the differences practically to me.

Can any give me some good examples to show the below two things explicitly ?

  • During xpath evaluation current node is fixed,but context nodes are keep changing.
  • context node and current node are co-incised with each other.
like image 803
Arup Rakshit Avatar asked Nov 02 '22 18:11

Arup Rakshit


1 Answers

The current node is only relevant if you are in an XSLT-scope; it refers to the node the current template is applied to and can be accessed using current().

For plain XPath (without XSLT), this function is not available and the current not neither accessible nor relevant.

For more details on the current node in XSLT, I'm referring to an answer by Paul A Jungwirth on another question.

like image 188
Jens Erat Avatar answered Nov 09 '22 22:11

Jens Erat