首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >在eXide中度假

在eXide中度假
EN

Stack Overflow用户
提问于 2020-05-14 01:11:41
回答 1查看 29关注 0票数 1
代码语言:javascript
复制
<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.-

代码语言:javascript
复制
xquery version "3.1";
for $i in collection("/db/exercise")//destino
where $i//estancias/hotel/@estrellas>"2"
return $i/estancias/hotel/text()

它没有给出预期的结果

2.-

代码语言:javascript
复制
xquery version "3.1";
for $i in collection("/db/exercise")//destino
return $i/estancias/hotel[@estrellas>2]/text()

这给出了预期的结果。

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

为什么,当我试图从8月开始获得每个viaje的titulo时,它都起作用了?

代码语言:javascript
复制
for $i in collection("/db/exercise")//destino
where $i/fecha_salida/mes="Agosto"
return ($i/titulo)
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2020-05-14 01:24:17

第一个

代码语言:javascript
复制
hotel/@estrellas>"2"

检查是否存在具有属性estrellashotel,该属性的值大于"2“。因为其中至少有一个存在,所以它将返回true

第二个表达式

代码语言:javascript
复制
/hotel[@estrellas>2]/text()

只选择具有该属性值的酒店(即,它会过滤掉那些没有该属性的酒店)。最后的/text()返回他们的名字。

For one of many examples, see here.

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/61780724

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档