"." versus ".." in XPath2.0

Discussion in 'XML' started by Ian Clifton, Dec 2, 2010.

  1. Ian Clifton

    Ian Clifton Guest

    I'm trying to learn XSLT2.0/Xpath2.0 . In one of my efforts, I tried to
    write <xsl:number select="parent::."/> which is incorrect syntax. I
    found that <xsl:number select=".."/> does what I wanted perfectly. From
    studying the Xpath syntax tree, I can understand why this happens, but I
    don't "get" it: can anyone explain why "." and ".." have such different
    roles in Xpath's syntax?
    Thanks,
    --
    Ian Clifton Phone: +44 1865 275677
    Chemistry Research Laboratory Fax: +44 1865 285002
    Oxford University
    Mansfield Road Oxford OX1 3TA UK
    Ian Clifton, Dec 2, 2010
    #1
    1. Advertising

  2. Ian Clifton

    Mayeul Guest

    On 02/12/2010 13:15, Ian Clifton wrote:
    > I'm trying to learn XSLT2.0/Xpath2.0 . In one of my efforts, I tried to
    > write<xsl:number select="parent::."/> which is incorrect syntax. I
    > found that<xsl:number select=".."/> does what I wanted perfectly. From
    > studying the Xpath syntax tree, I can understand why this happens, but I
    > don't "get" it: can anyone explain why "." and ".." have such different
    > roles in Xpath's syntax?
    > Thanks,


    .. is current node
    ... is parent node

    Why? I dunno, because it was already the case in URLs and other path
    notations, probably.

    I case what you wonder is why parent::. is incorrect, you should note
    that parent::.. is incorrect too.
    That is because because parent:: specifies an axe (the parent axe) and .
    and .. are both shortcuts for notations that imply an axe, therefore an
    other one cannot be added.

    .. is (roughly) short for self::*
    ... is (roughly) short for parent::*

    --
    Mayeul
    Mayeul, Dec 2, 2010
    #2
    1. Advertising

  3. Ian Clifton wrote:
    > I'm trying to learn XSLT2.0/Xpath2.0 . In one of my efforts, I tried to
    > write<xsl:number select="parent::."/> which is incorrect syntax. I
    > found that<xsl:number select=".."/> does what I wanted perfectly. From
    > studying the Xpath syntax tree, I can understand why this happens, but I
    > don't "get" it: can anyone explain why "." and ".." have such different
    > roles in Xpath's syntax?


    ".." is a short form (or abbreviation
    http://www.w3.org/TR/xpath/#path-abbrev) for "parent::node()", "." is a
    short form for "self::node()".
    What you want to achieve with "parent::." I am not sure, that is indeed
    not a construct that makes sense to me.


    --

    Martin Honnen
    http://msmvps.com/blogs/martin_honnen/
    Martin Honnen, Dec 2, 2010
    #3
  4. In article <4cf7afc4$0$6978$-online.net>,
    Martin Honnen <> wrote:

    >".." is a short form (or abbreviation
    >http://www.w3.org/TR/xpath/#path-abbrev) for "parent::node()", "." is a
    >short form for "self::node()".
    >What you want to achieve with "parent::." I am not sure, that is indeed
    >not a construct that makes sense to me.


    Presumably the OP was aiming at parent::* or parent::node(). One
    might expect parent::. to work on the unix path analogy of ../. being
    equivalent to ..

    -- Richard
    Richard Tobin, Dec 2, 2010
    #4
  5. Ian Clifton

    Ian Clifton Guest

    Martin Honnen <> writes:

    > Ian Clifton wrote:
    >> I'm trying to learn XSLT2.0/Xpath2.0 . In one of my efforts, I tried to
    >> write<xsl:number select="parent::."/> which is incorrect syntax. I
    >> found that<xsl:number select=".."/> does what I wanted perfectly. From
    >> studying the Xpath syntax tree, I can understand why this happens, but I
    >> don't "get" it: can anyone explain why "." and ".." have such different
    >> roles in Xpath's syntax?

    >
    > ".." is a short form (or abbreviation
    > http://www.w3.org/TR/xpath/#path-abbrev) for "parent::node()", "." is
    > a short form for "self::node()".
    > What you want to achieve with "parent::." I am not sure, that is
    > indeed not a construct that makes sense to me.


    Yes, my original question was rather confused, I'm beginning to see. I
    think I've found the reason for the different role of "." relative to
    ".." in XPath 2.0 syntax: "." can also denote the current item in a
    sequence

    http://www.w3.org/TR/xpath20/#dt-filter-expression

    - I haven't got to that bit in my text book yet!
    --
    Ian Clifton Phone: +44 1865 275677
    Chemistry Research Laboratory Fax: +44 1865 285002
    Oxford University
    Mansfield Road Oxford OX1 3TA UK
    Ian Clifton, Dec 2, 2010
    #5
  6. Ian Clifton

    Mayeul Guest

    On 02/12/2010 16:36, Ian Clifton wrote:
    > Yes, my original question was rather confused, I'm beginning to see. I
    > think I've found the reason for the different role of "." relative to
    > ".." in XPath 2.0 syntax: "." can also denote the current item in a
    > sequence
    >
    > http://www.w3.org/TR/xpath20/#dt-filter-expression


    And .. denotes the parent of current node as well.

    The only difference in roles is .. denotes parent node and . denotes
    current node. Really.

    --
    Mayeul
    Mayeul, Dec 2, 2010
    #6
  7. On 12/2/2010 7:27 AM, Mayeul wrote:
    > . is current node
    > .. is parent node
    >
    > Why? I dunno, because it was already the case in URLs and other path
    > notations, probably.


    Inherited from the Unix filesystem notations, 'way back when.


    > . is (roughly) short for self::*
    > .. is (roughly) short for parent::*


    Exactly. (By the way, even though the plural is "axes", the English
    singular is "axis".)


    --
    Joe Kesselman,
    http://www.love-song-productions.com/people/keshlam/index.html

    {} ASCII Ribbon Campaign | "may'ron DaroQbe'chugh vaj bIrIQbej" --
    /\ Stamp out HTML mail! | "Put down the squeezebox & nobody gets hurt."
    Joe Kesselman, Dec 2, 2010
    #7
  8. Martin Honnen <> writes:

    > Ian Clifton wrote:
    >> I'm trying to learn XSLT2.0/Xpath2.0 . In one of my efforts, I tried to
    >> write<xsl:number select="parent::."/> which is incorrect syntax. I
    >> found that<xsl:number select=".."/> does what I wanted perfectly. From
    >> studying the Xpath syntax tree, I can understand why this happens, but I
    >> don't "get" it: can anyone explain why "." and ".." have such different
    >> roles in Xpath's syntax?

    >
    > ".." is a short form (or abbreviation
    > http://www.w3.org/TR/xpath/#path-abbrev) for "parent::node()", "." is a
    > short form for "self::node()".


    But in 2.0 "." is the context item which isn't necessarily a node. So it is no longer a shorthand for "self::node()".
    --
    Piet van Oostrum <>
    WWW: http://pietvanoostrum.com/
    PGP key: [8DAE142BE17999C4]
    Nu Fair Trade woonartikelen op http://www.zylja.com
    Piet van Oostrum, Dec 3, 2010
    #8
  9. Ian Clifton

    Mayeul Guest

    On 02/12/2010 23:58, Joe Kesselman wrote:
    > On 12/2/2010 7:27 AM, Mayeul wrote:
    >> . is current node
    >> .. is parent node
    >>
    >> Why? I dunno, because it was already the case in URLs and other path
    >> notations, probably.

    >
    > Inherited from the Unix filesystem notations, 'way back when.
    >
    >
    >> . is (roughly) short for self::*
    >> .. is (roughly) short for parent::*

    >
    > Exactly. (By the way, even though the plural is "axes", the English
    > singular is "axis".)
    >


    Oops. I read medieval fantasy way too much.

    --
    Mayeul
    Mayeul, Dec 3, 2010
    #9
  10. Piet van Oostrum wrote:
    > Martin Honnen<> writes:
    >
    >> Ian Clifton wrote:
    >>> I'm trying to learn XSLT2.0/Xpath2.0 . In one of my efforts, I tried to
    >>> write<xsl:number select="parent::."/> which is incorrect syntax. I
    >>> found that<xsl:number select=".."/> does what I wanted perfectly. From
    >>> studying the Xpath syntax tree, I can understand why this happens, but I
    >>> don't "get" it: can anyone explain why "." and ".." have such different
    >>> roles in Xpath's syntax?

    >>
    >> ".." is a short form (or abbreviation
    >> http://www.w3.org/TR/xpath/#path-abbrev) for "parent::node()", "." is a
    >> short form for "self::node()".

    >
    > But in 2.0 "." is the context item which isn't necessarily a node. So it is no longer a shorthand for "self::node()".


    Zes, good point, I made the mistake to try to cite the XPath 1.0 spec
    for a question about XPath 2.0.

    --

    Martin Honnen
    http://msmvps.com/blogs/martin_honnen/
    Martin Honnen, Dec 11, 2010
    #10
    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. Replies:
    1
    Views:
    1,720
    Martin Honnen
    Oct 5, 2005
  2. RolfK
    Replies:
    7
    Views:
    1,438
    Martin Honnen
    Dec 18, 2007
  3. Christof Hoeke

    state of XSLT2/XPath2 or XQuery in CPython

    Christof Hoeke, Dec 26, 2007, in forum: Python
    Replies:
    2
    Views:
    315
    Christof Hoeke
    Dec 26, 2007
  4. Philippe Poulard

    Typed datas in XPath2

    Philippe Poulard, Jan 9, 2008, in forum: XML
    Replies:
    2
    Views:
    341
    Philippe Poulard
    Jan 9, 2008
  5. Paul Butcher
    Replies:
    12
    Views:
    711
    Gary Wright
    Nov 28, 2007
Loading...

Share This Page