为了账号安全,请及时绑定邮箱和手机立即绑定

使用 FLWOR 的表内无序列表

使用 FLWOR 的表内无序列表

沧海一幻觉 2023-10-17 17:28:06
我想制作一个表格,其中我将制作一个无序列表,其中包含酒店名称和星级数,如下所示:酒店·马库亚 (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>
查看完整描述

2 回答

?
慕工程0101907

TA贡献1887条经验 获得超5个赞

我认为您想要嵌套一个进一步的for .. return ..表达式(并更正属性选择,尽管我只是使用了||字符串连接运算符):


    <table>

      <tr>

        <th>Hoteles</th>

      </tr>

      {

      for $i in //destino

      return

        <tr>

          <td>

            <ul>

            {

                for $hotel in $i/estancias/hotel

                return 

                    <li>

                    {

                        $hotel || '(' || $hotel/@estrellas || ')'

                    }

                    </li>

            }

            </ul>

          </td>

        </tr>

      }

    </table>


查看完整回答
反对 回复 2023-10-17
?
蝴蝶刀刀

TA贡献1801条经验 获得超8个赞

你也可以使用这种方法(结合@Martin Honnen的伟大的星星渲染)


declare function local:render-destination ($desination as element(destino)) {

  <ul>{for-each($destination//hotel, local:render-hotel(?))}</ul>

};


declare function local:render-hotel ($hotel as element(hotel)) {

  <li>{

    ``[`{$hotel}` (`{local:render-stars($hotel/@estrellas/data())}`)`]``

    }</li>


};


declare function local:render-stars ($n as xs:integer) {

  string-join((1 to $n) ! '⭐')

};


<section>

  <header>Hoteles</header>

  {for-each(//destino, local:render-destination(?))}

</section>


查看完整回答
反对 回复 2023-10-17
  • 2 回答
  • 0 关注
  • 71 浏览

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信