我想做一张桌子,列一张无序的名单,上面写着酒店的名字和明星的数量,比如:
旅馆
·Macuya (4)
·Fuentevino (2)
·Tresarazos (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>发布于 2020-03-29 19:05:10
我认为您希望嵌套一个进一步的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>发布于 2020-04-26 15:12:52
您也可以使用这种方法(包括@Martin Honnen`s的伟大的星体渲染)
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>https://stackoverflow.com/questions/60905488
复制相似问题