current() doesn't maintain position
Added by Anonymous over 19 years ago
Legacy ID: #3051693 Legacy Poster: daiei27 (daiei27)
I'm trying to write an XSL for XML differencing so I need to be able to compare positions in 2 documents. The most convenient way would be to use position() in an XPath for the second doc. and compare it to the current()/position() in the first. However, current()/position() always seems to return 1 in Saxon. Other XSLT engines I have maintain the document position of the element to which current() refers. I can still do the same thing w/Saxon if I create a variable for the position before the comparison, but the less overhead the better. One more thing. Any tips/hints for an efficient differencing algorithm would be greatly appreciated. :)
Replies (3)
Please register to reply
RE: current() doesn't maintain position - Added by Anonymous over 19 years ago
Legacy ID: #3051890 Legacy Poster: Michael Kay (mhkay)
position() does not return the position of a node in its containing document, it returns the position of an item in the sequence of items currently being processed, and therefore depends on the processing that was used to reach the node. The expression A/position() has only become legal in the latest XPath 2.0 draft, so it's unlikely to work with many processors. It returns the sequence of integers from 1 up to count(A). If A is the expression current(), which always returns a single item, then count(A) is 1, so current()/position() returns 1. In XPath 1.0 it would be an error. To find the position of a node in its containing document, you need expressions such as count(preceding-sibling::*). Michael Kay
RE: current() doesn't maintain position - Added by Anonymous over 19 years ago
Legacy ID: #3074886 Legacy Poster: daiei27 (daiei27)
current() seems less useful to me in that way. I was hoping it was more like a pointer to the current context node. Otherwise, why would there be a need for the current() function?
RE: current() doesn't maintain position - Added by Anonymous over 19 years ago
Legacy ID: #3074934 Legacy Poster: Michael Kay (mhkay)
I don't really understand your question. current() returns the value that is the context node at the outermost level of an XPath expression. It was designed for doing simple joins, such as //x[@name = current()/@name]
Please register to reply