埃希德度假

Vacations in eXide

<vacaciones>
    <destino identificador="p023" tipo="unico">
        <titulo>París, la ciudad del amor</titulo>
        <fecha_salida>
              <mes>Marzo</mes>
        </fecha_salida>
        <estancias>
          <hotel estrellas="4">Macuya</hotel>
        </estancias>
    </destino>

    <destino identificador="m036" tipo="unico">
        <titulo>Islas Baleares, ahí mismo</titulo>
        <fecha_salida>
            <mes>Abril</mes>
        </fecha_salida>
        <estancias>
          <hotel estrellas="2">Fuentevino</hotel>
          <hotel estrellas="3">Tresarazos</hotel>
        </estancias>
    </destino>

    <destino identificador="i07" tipo="pack">
        <titulo>Italia, en sí misma</titulo>
        <fecha_salida>
            <mes>Agosto</mes>
        </fecha_salida>
        <estancias>
            <hotel estrellas="3">Mortareilo</hotel>
            <hotel estrellas="2">Sisa da Roca</hotel>
            <hotel estrellas="5">A Gatti</hotel>
            <hotel estrellas="3">La Nostra</hotel>
        </estancias>
    </destino>

    <destino identificador="a456" tipo="unico">
        <titulo>Amsterdam, la Venecia del norte</titulo>
        <fecha_salida>
            <mes>Agosto</mes>
        </fecha_salida>
        <estancias>
            <hotel estrellas="3">The sounders</hotel>
        </estancias>
    </destino>

    <destino identificador="n046" tipo="pack">
        <titulo>Los secretos del Nilo</titulo>
        <fecha_salida>
            <mes>Septiembre</mes>
        </fecha_salida>
        <estancias>
        </estancias>
    </destino>
</vacaciones>

我要2星以上酒店的编号

我有两个不同的代码:

1.-

xquery version "3.1";
for $i in collection("/db/exercise")//destino
where $i//estancias/hotel/@estrellas>"2"
return $i/estancias/hotel/text()

没有给出预期的结果

2.-

xquery version "3.1";
for $i in collection("/db/exercise")//destino
return $i/estancias/hotel[@estrellas>2]/text()

这给出了预期的结果。

谁能给我解释一下为什么第一个没有给出我想要的结果?或者指出解释原因的网页?

为什么当我尝试获取 8 月开始的每个 viaje 的标题时,它有效?

for $i in collection("/db/exercise")//destino
where $i/fecha_salida/mes="Agosto"
return ($i/titulo)

第一个

hotel/@estrellas>"2"

检查是否存在具有属性 estrellashotel,该属性的值大于“2”。由于其中至少存在一个,它将 return true.

第二个表达式

/hotel[@estrellas>2]/text()

仅选择具有该属性和该值的酒店(即过滤掉那些不具有该属性的酒店)。最后/text()return是他们的名字。

For one of many examples, see here.