Está en la página 1de 8

<html>

<table>
<tr>
<th>Nombre Fabricante (mf)</th>
<th>Total calorias</th>
<th>Vitamina c</th>
</tr>
{for $x in doc("nutrition.xml")//nutrition/food
let $b :=$x/calories/@total
let $c :=$x/vitamins/c
return
<tr>
<td>{$x/mfr/data()}</td>
<td>{$b/data()}</td>
<td>{$c/data()}</td>
</tr>}
</table>
</html>
para los de sin fibra
https://www.w3schools.com/xml/xquery_syntax.asp
<html>
<table border="1">
<tr>
<th>Nombre Alimento</th>
<th>Calorias grasas</th>
<th>Vitamina</th>
</tr>
<tr>
{
for $f in doc ("nutrition.xml")//food
let $b := $f/name/string()
let $g := $f/calories/@fat/string()
let $e := $f/vitamins/a/string()
return
<tr>
<td>{$b}</td>
<td>{$g}</td>
<td>{$e}</td>
</tr>

</tr>
</table>
</html>

Como se pone el border ese de la tabla, me sale doble con border=”1”

Otro sin fibra: “Realice una consulta que muestre los alimentos. Debe mostrar el nombre y la
cantidad de fibra. Si no tiene fibra debe poner la etiqueta <sin_fibra/> tal y como aparece a
continuación:”
for $n in doc("nutrition.xml")/nutrition
return <alimentos_con_fibra>
{for $f in doc("nutrition.xml")//food
return
<alimento>
<nombre>{$f/name/data()}</nombre>
{if ($f/fiber=0)
then <sin_fibra/>
else <fibra>{$f/fiber/data()}</fibra>
}
</alimento>
}
</alimentos_con_fibra>

“Generar una lista ordenada en html que muestra los nombres de los alimentos que tienen
fibra, ordenado por el nombre de los alimentos. “--->
for $n in doc("nutrition.xml")/nutrition
return
<html>
<head>
<style>
</style>
</head>
<body>
<ol type="1">
{for $f in doc("nutrition.xml")//food
where $f/fiber>=1
order by $f/name
return
<li>{$f/name/data()}</li>
}
</ol>
</body>
</html>
<html>
<head></head>
<body>
<table border="1">
<tr>
<th>Nombre Alimento</th>
<th>Total de calorias</th>
<th>Calcio</th>
</tr>
<tr>
{
for $f in doc ("nutrition.xml") //food
let $n := $f/name/data()
let $calorias := $f/calories/@total/data()
let $calcio := $f/minerals/ca/data()
return
<tr>
<td>{$n}</td>
<td>{$calorias}</td>
<td>{$calcio}</td>
</tr>
}
</tr>
</table>
</body>
</html>

Como ordeno esto por nombre de fabricante?


<html>
<head>
</head>
<body>
{ for $x in doc("nutrition.xml")//food
let $a := $x/vitamins/a
let $s := $x/mfr/data()
where ($a>0)
return
<ul>
<li>{$s}</li>
</ul>
}
</body>
</html>
con order by

si pero donde es que no me lo coge


antes del return
pongo order by $s no?
si, pero si no te sale prueba a poner la ruta sin el data

También podría gustarte