.Re: XPath comparison of numbers

  • Thread starter Dimitre Novatchev
  • Start date
D

Dimitre Novatchev

The following expression was rejected by Xalan:
*[position() < $pos]

Where 'pos' is an XSL variable having a numerical value. What is wrong
here and in comparable expressions like:

*[$pos > position()]

or

*[position() < $pos]

which Xalan is also unable to interpret? And if for some reason this
is not legal XPath (though I couldn't find such a reason in the spec),
how can I specify child elements preceding an element with a specific
position?

Btw, 'pos' was created as follows:

<xsl:variable name="pos">
<xsl:for-each select="*[generate-id(.)=$id]">
<xsl:value select="position()"/>
</xsl:for-each>
</xsl:variable>


The value of $pos will always be 1 because the node-set specified as
the value of the "select" attribute of the above xsl:for-each consists
of a single element.

Therefore Xalan (and any XPath engine) will evaluate:
*[position() &lt; $pos]

to the empty node-set, because position() cannot be less than one
(e.g. 0 or negative).


=====
Cheers,

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

Pim Lemmens

Dimitre Novatchev said:
The following expression was rejected by Xalan:

*[position() &lt; $pos]

Where 'pos' is an XSL variable having a numerical value. What is wrong
here and in comparable expressions like:

*[$pos &gt; position()]

or

*[position() < $pos]

which Xalan is also unable to interpret? And if for some reason this
is not legal XPath (though I couldn't find such a reason in the spec),
how can I specify child elements preceding an element with a specific
position?

Btw, 'pos' was created as follows:

<xsl:variable name="pos">
<xsl:for-each select="*[generate-id(.)=$id]">
<xsl:value select="position()"/>
</xsl:for-each>
</xsl:variable>


The value of $pos will always be 1 because the node-set specified as
the value of the "select" attribute of the above xsl:for-each consists
of a single element.

Therefore Xalan (and any XPath engine) will evaluate:
*[position() &lt; $pos]

to the empty node-set, because position() cannot be less than one
(e.g. 0 or negative).
OK. I can see that. But my problem was that Xalan complains about a
syntax error. It says: "Expected ']' but got '<'"

And another problem is how I can get the position of an identified
child node among the other child nodes of an element.

Pim.
 

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

No members online now.

Forum statistics

Threads
473,994
Messages
2,570,223
Members
46,812
Latest member
GracielaWa

Latest Threads

Top