[英]How to create a subtable with XSLT-1.0
I'm trying to create this table with XSLT and the provided XML: table desired 我试图创建该表XSLT和提供的XML: 表所需
This is the XML provided: 这是提供的XML:
<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" href="baile.xsl"?>
<academia nombre="Trassierra">
<curso id="C1" inicio="2019/10/01" fin="2020/06/30" nivel="intermedio">
<baile>tango</baile>
<imagen>imagenes/tango.jpeg</imagen>
<profesor>Ricardo Buenos Aires</profesor>
<sala>1</sala>
<plazas>10</plazas>
<horario>
<dia>lunes</dia>
<hora>17:00:00</hora>
<dia>miercoles</dia>
<hora>18:30:00</hora>
<dia>viérnes</dia>
<hora>18:00:00</hora>
</horario>
<precio cuota="trimestral">55</precio>
<matriculas>
<alumno>
<dni>30987123Z</dni>
<nombre>Jose Maria Ortiz Ots</nombre>
</alumno>
<alumno>
<dni>29876013J</dni>
<nombre>Maria Gonzalo Hernandez</nombre>
</alumno>
</matriculas>
</curso>
<curso id="C2" inicio="2019/01/01" fin="2019/06/30" nivel="intermedio">
<baile>salsa</baile>
<imagen>imagenes/salsa.jpeg</imagen>
<profesor>Raquel Langa</profesor>
<sala>2</sala>
<plazas>15</plazas>
<horario>
<dia>martes</dia>
<hora>19:00:00</hora>
<dia>jueves</dia>
<hora>19:00:00</hora>
</horario>
<precio cuota="mensual">20</precio>
<matriculas>
<alumno>
<dni>30983123B</dni>
<nombre>Jose Antonio Casado Alcaide</nombre>
</alumno>
<alumno>
<dni>34987245H</dni>
<nombre>Maria Angeles Luque Montes</nombre>
</alumno>
</matriculas>
</curso>
<curso id="C3" inicio="2019/03/01" fin="2019/03/30" nivel="iniciacion">
<baile>bachata</baile>
<imagen>imagenes/bachata.jpeg</imagen>
<profesor>Raquel Langa</profesor>
<sala>3</sala>
<plazas>10</plazas>
<horario>
<dia>viernes</dia>
<hora>19:00:00</hora>
</horario>
<matriculas>
<alumno>
<dni>39283827A</dni>
<nombre>Manuel Jimenez Luque</nombre>
</alumno>
<alumno>
<dni>29098373H</dni>
<nombre>Luisa Medina Ortega</nombre>
</alumno>
</matriculas>
</curso>
<curso id="C4" inicio="2019/07/01" fin="2019/08/30" nivel="intermedio">
<baile>zumba</baile>
<profesor>Antonio Rodríguez Luanda</profesor>
<sala>1</sala>
<plazas>5</plazas>
<horario>
<dia>viérnes</dia>
<hora>21:00:00</hora>
<dia>sábado</dia>
<hora>22:00:00</hora>
</horario>
<matriculas>
<alumno>
<dni>30987092K</dni>
<nombre>Marisa Paredes Sanchez</nombre>
</alumno>
<alumno>
<dni>29087296R</dni>
<nombre>Maribel Henández Pons</nombre>
</alumno>
<alumno>
<dni>29098373A</dni>
<nombre>Luisa Medina Ortega</nombre>
</alumno>
</matriculas>
</curso>
</academia>
And this is what I'm trying to do with the XSLT-1.0 这就是我要使用XSLT-1.0进行的操作
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:output method="html"/>
<xsl:template match="/">
<html style="color: #369;">
<head>
<title>baile.xsl</title>
</head>
<body>
<h1>
<strong>Curso de tango</strong>
</h1>
<p>
<img src="imagenes/tango.jpeg" align="center" height="100"/>
</p>
<table border="1" style="border-collapse">
<thead>
<strong>
<th style="text-aling:center">Profesor</th>
<th style="text-aling:center">Nº Plazas</th>
<th colspan="2" style="text-aling:center">Horario</th>
</strong>
</thead>
<tbody>
<xsl:for-each select="academia/curso" >
<xsl:if test="baile='tango'">
<tr>
<td rowspan="4">
<xsl:value-of select="profesor"/>
</td>
<td rowspan="4">
<xsl:value-of select="plazas"/>
</td>
<td>
<table>
<tr>
<xsl:for-each select="horario">
<tr>
<xsl:for-each select="dia">
<td>
<xsl:value-of select="/."/>
</td>
</xsl:for-each>
<xsl:for-each select="hora">
<td>
<xsl:value-of select="/."/>
</td>
</xsl:for-each>
</tr>
</xsl:for-each>
</tr>
</table>
</td>
</tr>
</xsl:if>
</xsl:for-each>
</tbody>
</table>
<h2>Matriculados</h2>
<table border="1" style="border-collapse:separate;border-spacing:2px">
<xsl:for-each select="academia/curso/baile/matriculas">
<xsl:if test="baile='tango'">
<tr>
<td>
<xsl:value-of select="nombre"/>
</td>
<td>
<xsl:value-of select="dni"/>
</td>
</tr>
</xsl:if>
</xsl:for-each>
</table>
</body>
</html>
</xsl:template>
</xsl:stylesheet>
The "horario" table output is all in one line, I know that maybe I have to iterate over "horario" and extract every "day" and "hour" , but I'm not able to know how to do that, I can only get one pair or all in one line. “ horario”表的输出全部在一行中,我知道也许我必须遍历“ horario”并提取每个“ day”和“ hour”,但是我不知道该怎么做,我可以只能得到一对或全部成对出现。
Any help? 有什么帮助吗?
Many thanks, and regards 非常感谢和问候
I debugged and rearranged your XSLT stylesheet: 我调试并重新排列了您的XSLT样式表:
text-aling:center
should have been text-align:center
您确实有错字: text-aling:center
应该是text-align:center
td
didn't need a rowspan="4"
attribute td
不需要rowspan="4"
属性 <strong>
tag on a block of table tags instead of a single text tag. 您将<strong>
标签错误地放在了一个表格标签块上,而不是一个文本标签上。 I split your template into two parts: 我将您的模板分为两部分:
curso
part curso
部分 So changing your XSLT to the following should improve your outcome: 因此,将XSLT更改为以下内容可以改善结果:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:output method="html"/>
<xsl:template match="/academia">
<html style="color: #369;">
<head>
<title>baile.xsl</title>
</head>
<body>
<h1>
<strong>Curso de tango</strong>
</h1>
<p>
<img src="imagenes/tango.jpeg" align="center" height="100"/>
</p>
<table border="1" style="border-collapse">
<thead>
<th style="text-align:center">Profesor</th>
<th style="text-align:center">Nº Plazas</th>
<th colspan="2" style="text-align:center">Horario</th>
</thead>
<xsl:apply-templates select="curso"/>
</table>
</body>
</html>
</xsl:template>
<xsl:template match="curso">
<tr>
<td rowspan="1">
<xsl:value-of select="profesor"/>
</td>
<td rowspan="1" style="text-align:center">
<xsl:value-of select="plazas"/>
</td>
<td>
<table border="1">
<xsl:for-each select="horario">
<xsl:for-each select="dia">
<tr>
<td>
<xsl:value-of select="."/>
</td>
<td>
<xsl:value-of select="following-sibling::hora[1]"/>
</td>
</tr>
</xsl:for-each>
</xsl:for-each>
</table>
</td>
</tr>
<h2>Matriculados</h2>
<table border="1" style="border-collapse:separate;border-spacing:2px">
<xsl:for-each select="matriculas/alumno[../../baile='tango']">
<tr>
<td>
<xsl:value-of select="nombre"/>
</td>
<td>
<xsl:value-of select="dni"/>
</td>
</tr>
</xsl:for-each>
</table>
</xsl:template>
</xsl:stylesheet>
A partial output is: 部分输出为:
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.