Reputation: 49
I want to make a table in which I'm going to make an unordered list with the names of the hotels and the number of stars like this:
Hoteles
· Macuya (4)
· Fuentevino (2)
· Tresarazos (3)
Using this code:
<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>
I tried this in eXide, but the names come together without spaces and the number of stars isn't shown:
<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>
Upvotes: 2
Views: 68
Reputation: 1895
You could also use this approach (incorporating @Martin Honnen`s great star rendering)
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>
Upvotes: 0
Reputation: 167716
I think you want to nest a further for .. return ..
expression (and correct the attribute selection although I have simply used the ||
string concatenation operator):
<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>
Upvotes: 2