/ / Den Wert des Attributs speichern und in Xquery abgleichen - xpath, xquery, zorba

Den Wert des Attributs speichern und in Xquery abgleichen - xpath, xquery, zorba

<a>
{
for $p in doc("x.xml")/user//district
where data($p/@population) div data($p/@area) > 20
return <b>
<c> {$p/@name/string()} </c>
<d> {$p/@population div $p/@area} </d>
<d> {$p/@city/string()}</e>
</b>
}
</a>

Ich bekomme die ID des Viertels, aber ich möchteder Name des Landes Ich möchte also von der Stadt zurück in den Bezirk fahren. Wie im folgenden Snippet erhalte ich das Land (id = "f0_149"), kann es jedoch nicht finden und stattdessen den Ländernamen "Austria" drucken.

Ich bin neu bei Xquery, daher bin ich mir über viele Dinge nicht bewusst.

XML-DATEI-SNIPPET:

<?xml version="1.0" encoding="utf-8"?>
<user xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<country id="f0_149" name="Austria" capital="f0_1467" population="10000000" total_area="50000" >
<name>
Austria
</name>
<district id="f0_17440" name="Burgenland" country="f0_149" capital="f0_2291" population="250000" area="5000">
<city id="f0_2291" country="f0_149" province="f0_17440">
<name>
Eisenstadt
</name>
<population year="87">
10102
</population>
</city>

Antworten:

0 für die Antwort № 1

Du kannst den ... benutzen parent:: XPath-Achse:

<c> { $p/parent::country/@name/string() } </c>