Position of a node

  • Thread starter Hans-Michael Rupp
  • Start date
H

Hans-Michael Rupp

Hallo!

How can find out the postion of a node with a particular content in the
nodeset WITHOUT being in the context?

I would like have something like
<xsl:variable name="position" select="position(/foo/bar[blubber='test'])">
of course position() does not work this way.

Is there another way to solve this?

Many thanks,

Hans
 
M

Marrow

Hi Hans,

Depends on what you are actually trying to accomplish?

Crudely...
<xsl:variable name="position" select="position(/foo/bar[blubber='test'])">

Do you want the 'position' of <bar> within all children of the <foo>
element? e.g.
<xsl:variable name="position"
select="count(/foo/bar[blubber='test']/preceding-sibling::*)"/>

Do you want the 'position' of <bar> within all <bar> element children of the
<foo> element? e.g.
<xsl:variable name="position"
select="count(/foo/bar[blubber='test']/preceding-sibling::bar)"/>

etc. etc.

But you may get very unexpected results from the above unless the node you
are starting at (i.e. the part of the expression before the
/preceding-sibling axis) is gauranteed to be a single node.

Hope this helps
Marrow
http://www.marrowsoft.com - home of Xselerator (XSLT IDE and debugger)
http://www.topxml.com/Xselerator


Hans-Michael Rupp said:
Hallo!

How can find out the postion of a node with a particular content in the
nodeset WITHOUT being in the context?

I would like have something like
<xsl:variable name="position" select="position(/foo/bar[blubber='test'])">
of course position() does not work this way.

Is there another way to solve this?

Many thanks,

Hans
 
D

Dimitre Novatchev

The position of *which* node in *what* nodeset?

You haven't specified either.


Also, the XPath position() function is defined on the current *node-list*,
not node-set. This means that position() can be used:

in a relation in predicates within an XPath expression to select nodes
whose position in the current node-list satisfies this relation,

or

in the body of xsl:for-each or of xsl:template to return the position of
the current node in the current node-list.



=====
Cheers,

Dimitre Novatchev.
http://fxsl.sourceforge.net/ -- the home of FXSL
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,990
Messages
2,570,211
Members
46,796
Latest member
SteveBreed

Latest Threads

Top