Current node vs. Context node in XSLT/XPath?

The current node is whatever the template is currently operating on. Normally this happens to also be the context node, but the context node has special meaning within a nested XPath expression (the part in square brackets). There, it refers to whatever node is currently being tested for a match.

Hence, the context node changes within the XPath expression, but not the current node The context node can be abbreviated with a dot ( ) or sometimes left out entirely. This is probably a little confusing, because outside of a nested expression, a dot signifies the current node. (In that case the current node happens to be the context node, so one might say that it is the current node only proximately, and it is more properly called the context node.

But even the spec calls it the current node here. ) Since a dot gives you the context node, in a nested XPath expression the user needs a way to refer back to the current node, the one being processed by the current template. You can do this via the current() function Distinguishing these two is useful in some cases.

For instance, suppose you have some XML like this: a> foo bar baz aak eep blech Batteries not included. Some assembly required. \footnote{...} \footnotemark...

The current node is whatever the template is currently operating on. Normally this happens to also be the context node, but the context node has special meaning within a nested XPath expression (the part in square brackets). There, it refers to whatever node is currently being tested for a match.

Hence, the context node changes within the XPath expression, but not the current node. The context node can be abbreviated with a dot (.) or sometimes left out entirely. This is probably a little confusing, because outside of a nested expression, a dot signifies the current node.(In that case the current node happens to be the context node, so one might say that it is the current node only proximately, and it is more properly called the context node.

But even the spec calls it the current node here. ) Since a dot gives you the context node, in a nested XPath expression the user needs a way to refer back to the current node, the one being processed by the current template. You can do this via the current() function.

Distinguishing these two is useful in some cases. For instance, suppose you have some XML like this: foo bar baz aak eep blech Batteries not included. Some assembly required.

Now suppose you want to convert it to LaTeX like this: foo\footnote{Batteries not included. } bar baz aak\footnote{Some assembly required. } eep blech\footnotemark2 The trick is the tell whether a footnote has already been used or not.

If this is the first time you've encountered the footnote, you want to write a \footnote command; otherwise you want to write a \footnotemark command. You could use XSL code like this: \footnote{...} \footnotemark... Here we are comparing the context-node fn attribute (from the results of the preceding::* node-set) to the current-node fn attribute.(You don't actually have to say . /@fn; you could just say @fn.) So in short, the context node leaves you inside the XPath predicate; the current node reaches outside the predicate, back to the node being processed by the current template.

1 That was fast. You posted the question 1 min ago, and the answer 57s ago (according to my browser)! – Brian Agnew Jun 20 '09 at 19:32 1 @Brian Agnew: Man, I really have to improve my typing skills.

On average it takes me several minutes to answer a question... But if I answer my own, I could save some time. – Tomalak Jun 22 '09 at 8:38.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions