I'm running an xslt on an XML that at one point puts my current node at the following "item" element in the tree:
host/device/item
I've found through experimentation that the following xpath takes the xslt back up to the "host" branch of the XML tree, then successfully locates the "trigger" grand child element of the "host" element.
../.././setting/trigger
It works, but the xpath syntax seems odd to me. The dot parent notation ../../.
makes sense when you read it from the .
from right to left. But the child phrase notation setting/trigger
only make sense if you read from left to right. The "final meaning" of the entire xpath is equivalent to saying:
host/setting/trigger
Is it always true that the middle ../.
section of the xpath (or开发者_开发百科 however many parent ../
levels it is) is always ignored to create the final meaning host/device/trigger
?
Since .
means self, you could interpret it as being ignored. ./././././././*
means the same as ./*
, which means the same as *
.
Regarding Reading the XPath, breaking it down from the context node host/device/item
In ../.././setting/trigger
, the /
characters separate the node tests, so, LtoR:
..
you are now at host/device,
..
you are now at host
.
you are still at host
setting
you are now at host/setting
trigger
you are now at host/setting/trigger
If you read it RtoL, then you must understand that instead of following node-tests, you are reading each node test with the opposite meaning, and your context is where you want to end up, so:
from host/setting/trigger
(your desired endpoint)
trigger
(read as ..
), you are now at host/setting
setting
(again, ..
), you are now at host
.
(.
), you are still at host
..
(read as *
) you might now be at host/device
..
(read as *
) you might now be at host/device/item
精彩评论