Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > XML > .Re: XPath comparison of numbers

Reply
Thread Tools

.Re: XPath comparison of numbers

 
 
Dimitre Novatchev
Guest
Posts: n/a
 
      09-02-2003
> 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
 
Reply With Quote
 
 
 
 
Pim Lemmens
Guest
Posts: n/a
 
      09-02-2003

"Dimitre Novatchev" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed) om...
> > 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.


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
"Memory leak" in javax.xml.xpath.XPath Marvin_123456 Java 4 07-29-2005 03:49 PM
Are there any XPath parsers that generate XPath trees? goog XML 0 01-14-2004 01:47 PM
Re: XPath comparison of numbers Dimitre Novatchev XML 0 09-02-2003 03:21 PM
XPath that does not include other XPath Anna XML 0 07-31-2003 07:55 AM
Problem selecting a node with XPATH if attribute value contains backslashes - how to force XPATH string to be treated as literal? Alastair Cameron XML 1 07-08-2003 07:24 PM



Advertisments