xsl-list
[Top] [All Lists]

RE: [xsl] position() from the attribute axis for getting the position of the parent in respect to its siblings

2007-01-18 04:32:13

Somehow, I understood that position() retrieves the position 
of the context node relative to its siblings, in most cases 
at least. 

No, it returns the position in whatever set of nodes you are currently
processing. Those might be siblings, or they might not.

However, when at the attribute axis, this number is 
undefined, because the order in which attributes are mapped 
to the internal tree representation of the input is undefined.

It's only undefined to the extent that you can't predict the relationship
between the order of the attributes in the source (lexical) XML and the
order of the attributes in the tree data model.

But I am not after the position of the attribute, but I am 
after the position of its parent. Below are two ways to do 
it, however without the
position() function. My question is: Is it not possible to use
position() to get the "position" of the parent node when I am 
at the attribute axis? And if it is possible, how can I do 
it, what am I overlooking?

You're overlooking the fact that position() has nothing to do with the
position of a node in the source tree, it returns the position of the node
in the list of nodes currently selected for processing by a mapping operator
such as for-each, apply-templates, [], or /.

To get the position of a node in the source tree, use xsl:number, or
expressions such as count($x/preceding-sibling::node()).

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



--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--