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

I

Ian Clifton

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,
 
M

Mayeul

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::*
 
M

Martin Honnen

Ian said:
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.
 
R

Richard Tobin

Martin Honnen said:
".." 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
 
I

Ian Clifton

Martin Honnen said:
".." 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!
 
M

Mayeul

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.
 
J

Joe Kesselman

. 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."
 
M

Mayeul

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



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

Oops. I read medieval fantasy way too much.
 
M

Martin Honnen

Piet said:
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.
 

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,764
Messages
2,569,567
Members
45,041
Latest member
RomeoFarnh

Latest Threads

Top