xsl-list
[Top] [All Lists]

Re: [xsl] XPATH 1.0: Selecting an element attribute starting from a self:: attribute

2015-06-23 15:40:49
Hi,

It's an interesting fine point that a simple join of this kind is not
possible in unassisted XPath 1.0, where there is no way to bind $this.

The current() function is a way of providing the functionality, but
it's not in XPath 1.0 either as Mike Kay points out.

Of course, the XSLT 1.0 solution, beyond going straight to current(),
is to define a key....

Cheers, Wendell



On Wed, Jun 17, 2015 at 2:00 PM, Liam R. E. Quin liam(_at_)w3(_dot_)org
<xsl-list-service(_at_)lists(_dot_)mulberrytech(_dot_)com> wrote:
On Wed, 2015-06-17 at 14:28 +0000, Malecki, Piotr 
piotr(_dot_)malecki(_at_)thyssenkrupp(_dot_)com wrote:
Hello,

The question corresponds basically to XPATH 1.0 (not 2.0 , not XSL).

I have an XML like this (snippet only):

<library>
            <catalog>
                        <book id="_1" name="Book1"/>
                        <book id="_2" name="Book2"/>
                        <book id="_3" name="Book3"/>
            </catalog>
            <customer>
                        <borrowed bookId="_1"/>
                        <borrowed bookId="_2"/>
            </customer>
</library>

In an application (Windows WPF / XAML), my execution context is e.g.
the element "borrowed" (e.g. <borrowed bookId="_1"/>).

I have to find the name of the book which is referenced as bookId.

So my XPATH expression is like this:
"//book[@id=self::*/@bookId]/@name"

Read as: give all books whose id equals to the bookId of the current
node.

Although you can read it that way, remember that predicates change the
current node for evaluating the predicate. So the current node for
  //book[anything]
will be each book element in the document.

A way to do this in pure XPath is to use two steps. First make an
Xpath variable binding, e.g. to "this", as the borrowed book, and then
use
    //book[@id = $this]/@name

Note also that some XPath engines can't return standalone attribute
names, so you have to return the list of matching elements and iterate
over them in the host language.

Liam


The Query  is executed for the "borrowed" node (execution context).

Unfortunately the expression doesn't return the result expected
(rather an empty set).

What is wrong in my understanding here?

Thank you
regards
Piotr


Mit freundlichen Grüßen / Kind regards

Dipl.-Ing. Piotr Malecki

Systemingenieur / Systems Engineer
Waffen und Führung Systemintegration
Weapon, Command & Control System Integration
Operating Unit Surface Vessels

ThyssenKrupp Marine Systems GmbH
Hermann-Blohm-Strasse 3 - 20457 Hamburg- Germany
P:O.Box 10 07 20 - 20005 Hamburg - Germany

Phone: +49 (0) 431 / 700 2446
Fax: +49 (0) 431 / 700 1600 2446

Mailto:piotr(_dot_)malecki(_at_)thyssenkrupp(_dot_)com

ThyssenKrupp Marine Systems GmbH
Chairman of the Supervisory Board: Dr. Hans Christoph Atzpodien
Executive Board: Andreas Burmester (Chairman), Dieter Rottsieper,
Dr. Walter Klausmann, Torsten Könker
Commercial Register: District Court of Kiel HRB 6960 KI
Registered Office: Kiel

Wie Sie wissen, können über das Internet versandte E-Mails unter
fremdem Namen erstellt oder der Inhalt verändert werden.
Aus diesem Grund sind unsere als E-Mail verschickten Nachrichten
grundsätzlich keine rechtsverbindlichen Erklärungen.
Der Inhalt dieser E-Mail samt Anlagen ist vertraulich und u. U.
rechtlich geschützt.

As you are aware, messages sent by e-mail can be manipulated by
third parties. For this reason our e-mail messages are generally not
legally binding.
This electronic message (including any attachments) contains
confidential information and may be privileged or otherwise
protected from disclosure





-- 
Wendell Piez | http://www.wendellpiez.com
XML | XSLT | electronic publishing
Eat Your Vegetables
_____oo_________o_o___ooooo____ooooooo_^
--~----------------------------------------------------------------
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
EasyUnsubscribe: http://lists.mulberrytech.com/unsub/xsl-list/1167547
or by email: xsl-list-unsub(_at_)lists(_dot_)mulberrytech(_dot_)com
--~--

<Prev in Thread] Current Thread [Next in Thread>