<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的titulo时,它都起作用了?
for $i in collection("/db/exercise")//destino
where $i/fecha_salida/mes="Agosto"
return ($i/titulo)发布于 2020-05-14 01:24:17
第一个
hotel/@estrellas>"2"检查是否存在具有属性estrellas的hotel,该属性的值大于"2“。因为其中至少有一个存在,所以它将返回true。
第二个表达式
/hotel[@estrellas>2]/text()只选择具有该属性值的酒店(即,它会过滤掉那些没有该属性的酒店)。最后的/text()返回他们的名字。
https://stackoverflow.com/questions/61780724
复制相似问题