table 内的无序列表使用 FLWOR
Unordered list inside table using FLWOR
我想制作一个 table,我将在其中制作一个无序列表,其中包含酒店名称和星级数量,如下所示:
酒店
· 马库亚 (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>
我认为您想进一步嵌套 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>
您也可以使用这种方法(结合@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>
我想制作一个 table,我将在其中制作一个无序列表,其中包含酒店名称和星级数量,如下所示:
酒店
· 马库亚 (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>
我认为您想进一步嵌套 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>
您也可以使用这种方法(结合@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>