.Re: XPath comparison of numbers

Discussion in 'XML' started by Dimitre Novatchev, Sep 2, 2003.

  1. > 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
     
    Dimitre Novatchev, Sep 2, 2003
    #1
    1. Advertising

  2. Dimitre Novatchev

    Pim Lemmens Guest

    Re: XPath comparison of numbers

    "Dimitre Novatchev" <> wrote in message
    news:...
    > > 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.
     
    Pim Lemmens, Sep 2, 2003
    #2
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Marvin_123456

    "Memory leak" in javax.xml.xpath.XPath

    Marvin_123456, Jul 29, 2005, in forum: Java
    Replies:
    4
    Views:
    2,028
    jan V
    Jul 29, 2005
  2. Alastair Cameron
    Replies:
    1
    Views:
    7,522
    SQL Server Development Team [MSFT]
    Jul 8, 2003
  3. Anna
    Replies:
    0
    Views:
    572
  4. Dimitre Novatchev

    Re: XPath comparison of numbers

    Dimitre Novatchev, Sep 2, 2003, in forum: XML
    Replies:
    0
    Views:
    787
    Dimitre Novatchev
    Sep 2, 2003
  5. Deepu
    Replies:
    1
    Views:
    266
    ccc31807
    Feb 7, 2011
Loading...

Share This Page