猿问

使用 FLWOR 的表内无序列表

我想制作一个表格,其中我将制作一个无序列表,其中包含酒店名称和星级数,如下所示:


酒店


·马库亚 (4)


·富恩特维诺 (2)


· 特萨拉索斯 (3)


使用此代码:


<vacaciones>

    <destino identificador="p023">

        <estancias>

          <hotel estrellas="4">Macuya</hotel>

        </estancias>

    </destino>


    <destino identificador="m036">

        <estancias>

          <hotel estrellas="2">Fuentevino</hotel>

          <hotel estrellas="3">Tresarazos</hotel>

        </estancias>

    </destino>

</vacaciones>

我在 eXide 中尝试过此操作,但名称组合在一起时没有空格,并且未显示星星的数量:


<table>

  <tr>

    <th>Hoteles</th>

  </tr>

  {for $i in doc("/db/exercise/vacaciones.xml")//destino

  return

    <tr>

      <td>

        <ul>

          <li>

            {$i/estancias/hotel/text()} ({$i/estancias/hotel/@estrellas/text()})

          </li>

        </ul>

      </td>

    </tr>

  }

</table>


沧海一幻觉
浏览 97回答 2
2回答

慕工程0101907

我认为您想要嵌套一个进一步的for .. return ..表达式(并更正属性选择,尽管我只是使用了||字符串连接运算符):&nbsp; &nbsp; <table>&nbsp; &nbsp; &nbsp; <tr>&nbsp; &nbsp; &nbsp; &nbsp; <th>Hoteles</th>&nbsp; &nbsp; &nbsp; </tr>&nbsp; &nbsp; &nbsp; {&nbsp; &nbsp; &nbsp; for $i in //destino&nbsp; &nbsp; &nbsp; return&nbsp; &nbsp; &nbsp; &nbsp; <tr>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <td>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <ul>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; {&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; for $hotel in $i/estancias/hotel&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; return&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <li>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; {&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; $hotel || '(' || $hotel/@estrellas || ')'&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </li>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </ul>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </td>&nbsp; &nbsp; &nbsp; &nbsp; </tr>&nbsp; &nbsp; &nbsp; }&nbsp; &nbsp; </table>

蝴蝶刀刀

你也可以使用这种方法(结合@Martin Honnen的伟大的星星渲染)declare function local:render-destination ($desination as element(destino)) {&nbsp; <ul>{for-each($destination//hotel, local:render-hotel(?))}</ul>};declare function local:render-hotel ($hotel as element(hotel)) {&nbsp; <li>{&nbsp; &nbsp; ``[`{$hotel}` (`{local:render-stars($hotel/@estrellas/data())}`)`]``&nbsp; &nbsp; }</li>};declare function local:render-stars ($n as xs:integer) {&nbsp; string-join((1 to $n) ! '⭐')};<section>&nbsp; <header>Hoteles</header>&nbsp; {for-each(//destino, local:render-destination(?))}</section>
随时随地看视频慕课网APP

相关分类

Html5
我要回答