XSL - Tengo problemas al pasar un xml a xhtml con el codigo XSL

 
Vista:
sin imagen de perfil

Tengo problemas al pasar un xml a xhtml con el codigo XSL

Publicado por Jose Antonio (1 intervención) el 15/04/2014 17:42:09
Hola por mas que lo miro no entiendo porque este codigo no me permite salir todos los elementos seleccionados ya que solo me muestra la tabla de los encabezados, paso el codigo por si alguien sabe donde meto la pata

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
<?xml version="1.0" encoding="UTF-8" ?>
 
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
 
<xsl:output method="html" indent="yes" encoding="UTF-8"/>
 
<xsl:template match="/notas">
 
	<html>
 
		<head>
			<tittle>TRANSFORMACION XSLT JOSE ANTONIO GOMEZ</tittle>
 
		</head>
		<body>
			<h2 align="center">Listado de notas (Convocatoria de Junio)</h2>
			<table border="1" align="center">
				<tr bgcolor="#00ccff">
					<th colspan="3">Alumnos</th>
					<th colspan="3">Notas</th>
				</tr>
				<tr bgcolor="#0033ff">
					<th>NOMBRE</th>
					<th>APELLIDOS</th>
					<th>Cuestionarios</th>
					<th>Tareas</th>
					<th>Examen</th>
					<th>Final</th>
				</tr>
				<xsl:for-each select="notas/alumno">
				<xsl:if test="./@convocatoria='Junio'">
				<tr>
				<td><xsl:value-of select="nombre"/></td>
				<td><xsl:value-of select="apellidos"/></td>
				<td bgcolor="ffff00"><xsl:value-of select="cuestionarios"/></td>
				<td bgcolor="ffff00"><xsl:value-of select="tareas"/></td>
				<td bgcolor="ffff00"><xsl:value-of select="examen"/></td>
				<td bgcolor="ff6600"><xsl:choose>
					<xsl:when test="final&gt;=9">
						Sobresaliente
					</xsl:when>
					<xsl:when test="final&gt;=7">
						Notable
					</xsl:when>
					<xsl:when test="final&gt;=6">
						Bien
					</xsl:when>
					<xsl:when test="final&gt;=5">
						Suficiente
					</xsl:when>
					<xsl:otherwise>
						Insuficiente
					</xsl:otherwise>
				</xsl:choose></td>
				</tr>
				</xsl:if>
				</xsl:for-each>
			</table>
		</body>
	</html>
</xsl:template>
 
</xsl:stylesheet>
Valora esta pregunta
Me gusta: Está pregunta es útil y esta claraNo me gusta: Está pregunta no esta clara o no es útil
0
Responder
Imágen de perfil de Alejandro

Generación de tabla filtrada con datos de XML

Publicado por Alejandro (227 intervenciones) el 07/07/2023 16:16:00
El problema en tu código XSLT está en el patrón de coincidencia en la plantilla principal. En lugar de usar `/notas` como patrón de coincidencia, debes usar `notas` ya que estás dentro del contexto de la plantilla.

Aquí tienes el código corregido:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
<?xml version="1.0" encoding="UTF-8" ?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
 
<xsl:output method="html" indent="yes" encoding="UTF-8"/>
 
<xsl:template match="notas">
	<html>
		<head>
			<title>TRANSFORMACION XSLT JOSE ANTONIO GOMEZ</title>
		</head>
		<body>
			<h2 align="center">Listado de notas (Convocatoria de Junio)</h2>
			<table border="1" align="center">
				<tr bgcolor="#00ccff">
					<th colspan="3">Alumnos</th>
					<th colspan="3">Notas</th>
				</tr>
				<tr bgcolor="#0033ff">
					<th>NOMBRE</th>
					<th>APELLIDOS</th>
					<th>Cuestionarios</th>
					<th>Tareas</th>
					<th>Examen</th>
					<th>Final</th>
				</tr>
				<xsl:for-each select="alumno">
					<xsl:if test="@convocatoria='Junio'">
						<tr>
							<td><xsl:value-of select="nombre"/></td>
							<td><xsl:value-of select="apellidos"/></td>
							<td bgcolor="ffff00"><xsl:value-of select="cuestionarios"/></td>
							<td bgcolor="ffff00"><xsl:value-of select="tareas"/></td>
							<td bgcolor="ffff00"><xsl:value-of select="examen"/></td>
							<td bgcolor="ff6600">
								<xsl:choose>
									<xsl:when test="final &gt;= 9">Sobresaliente</xsl:when>
									<xsl:when test="final &gt;= 7">Notable</xsl:when>
									<xsl:when test="final &gt;= 6">Bien</xsl:when>
									<xsl:when test="final &gt;= 5">Suficiente</xsl:when>
									<xsl:otherwise>Insuficiente</xsl:otherwise>
								</xsl:choose>
							</td>
						</tr>
					</xsl:if>
				</xsl:for-each>
			</table>
		</body>
	</html>
</xsl:template>
 
</xsl:stylesheet>

En este código, hemos cambiado el patrón de coincidencia de `/notas` a `notas` en la plantilla principal. Además, hemos ajustado la selección en el bucle `xsl:for-each` a `alumno` en lugar de `notas/alumno`.

Con estas correcciones, el código debería generar la tabla completa con todos los elementos seleccionados correctamente.
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar