XSL - ejercicio

 
Vista:
sin imagen de perfil

ejercicio

Publicado por Joe (1 intervención) el 26/05/2022 23:45:22
Hola tengo este xml y xsd pero no se como modificarlo para que quede como se ve en la imagen






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
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
	<xsl:template match='/'>
		<html>
			<head>
			</head>
			<body>
				<h2><center>EXAMEN</center></h2>
					<table border="1" width="500" align="center">
						<form action="" method="get">
							<xsl:for-each select="examen/cuestion">
								<xsl:choose>
									<xsl:when test="(@tipo = 'multiple')">
								     <tr>
								       <td colspan="2">
								         <font size="+1">
								           <xsl:value-of select="pregunta" />
                         </font>
                       </td>
                     </tr>
 							      <xsl:for-each select="opciones/opcion">
									     <tr>
		    						     <td width="1">
				    				       <input type="checkbox">
						    		       <xsl:attribute name="id"><xsl:value-of select="namechk" /></xsl:attribute>
								           <xsl:attribute name="name"><xsl:value-of select="namechk" /></xsl:attribute>
								           <xsl:attribute name="value"><xsl:value-of select="texto" /></xsl:attribute>
								           </input>
								         </td>
								         <td>
								           <xsl:value-of select="texto" />
								         </td>
                       </tr>
                     </xsl:for-each>
									</xsl:when>
									<xsl:when test="(@tipo = 'numero')">
									  <tr><td colspan="2">    </td></tr>
									  <tr><td colspan="2">    </td></tr>
									</xsl:when>
									<xsl:when test="(@tipo = 'bool')">
									  <tr><td colspan="2"></td></tr>
									  <tr><td width="50">     </td><td>     </td></tr>
									  <tr><td width="50">     </td><td>     </td></tr>
									</xsl:when>
									<xsl:when test="(@tipo = 'rollo')">
									  <tr><td colspan="2">    </td></tr>
									  <tr><td colspan="2">    </td></tr>
									</xsl:when>
								</xsl:choose>
							</xsl:for-each>
						</form>
					</table>
  				<input type="submit" value="Enviar respuesta" />
			</body>
		</html>
	</xsl:template>
</xsl:stylesheet>




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
<?xml version="1.0" encoding="utf-8"?>
<?xml-stylesheet type="text/xsl" href="examen.xsl"?>
<examen>
	<cuestion tipo="multiple">
		<pregunta>1) Harías puenting alguna vez en tu vida?</pregunta>
		<opciones>
			<opcion>
				<texto>Si</texto>
				<namechk>chk11</namechk>
			</opcion>
			<opcion>
				<texto>No</texto>
				<namechk>chk12</namechk>
			</opcion>
			<opcion>
				<texto>Depende</texto>
				<namechk>chk13</namechk>
			</opcion>
			<opcion>
				<texto>Quizás</texto>
				<namechk>chk14</namechk>
			</opcion>
		</opciones>
	</cuestion>
	<cuestion tipo="numero">
		<pregunta>2) Introduce el nombre de tu deportista favorito:</pregunta>
	</cuestion>
	<cuestion tipo="bool">
		<pregunta>3) Te gusta el fútbol?</pregunta>
	</cuestion>
	<cuestion tipo="rollo">
		<pregunta>4) Explica en qué consiste el curling?</pregunta>
	</cuestion>
</examen>
Sin-titulo
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 formulario de examen personalizado

Publicado por Alejandro (227 intervenciones) el 07/07/2023 19:29:45
Puedo ayudarte a mejorar tu código XSLT para que se ajuste a tus necesidades. Basándome en la descripción que proporcionas, aquí tienes una posible modificación de tu código XSLT para lograr el formato deseado:

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
64
65
66
67
68
69
70
71
72
73
74
75
76
<?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"/>
 
  <xsl:template match="/">
    <html>
      <head>
        <title>EXAMEN</title>
      </head>
      <body>
        <h2 style="text-align:center;">EXAMEN</h2>
        <form action="" method="get">
          <table border="1" width="500" align="center">
            <xsl:for-each select="examen/cuestion">
              <tr>
                <td colspan="2">
                  <font size="+1">
                    <xsl:value-of select="pregunta"/>
                  </font>
                </td>
              </tr>
              <xsl:choose>
                <xsl:when test="@tipo = 'multiple'">
                  <xsl:apply-templates select="opciones/opcion"/>
                </xsl:when>
                <xsl:when test="@tipo = 'numero'">
                  <tr>
                    <td colspan="2">
                      <!-- Aquí puedes colocar el campo de entrada para el número -->
                      <input type="text" name="numero"/>
                    </td>
                  </tr>
                </xsl:when>
                <xsl:when test="@tipo = 'bool'">
                  <tr>
                    <td width="50"></td>
                    <td>
                      <input type="radio" name="bool" value="Si"/>Si
                    </td>
                  </tr>
                  <tr>
                    <td width="50"></td>
                    <td>
                      <input type="radio" name="bool" value="No"/>No
                    </td>
                  </tr>
                </xsl:when>
                <xsl:when test="@tipo = 'rollo'">
                  <tr>
                    <td colspan="2">
                      <!-- Aquí puedes colocar el campo de entrada para el texto largo -->
                      <textarea name="rollo"></textarea>
                    </td>
                  </tr>
                </xsl:when>
              </xsl:choose>
            </xsl:for-each>
          </table>
          <input type="submit" value="Enviar respuesta"/>
        </form>
      </body>
    </html>
  </xsl:template>
 
  <xsl:template match="opcion">
    <tr>
      <td width="1">
        <input type="checkbox" id="{namechk}" name="{namechk}" value="{texto}"/>
      </td>
      <td>
        <xsl:value-of select="texto"/>
      </td>
    </tr>
  </xsl:template>
 
</xsl:stylesheet>

En esta modificación, se han realizado los siguientes cambios:
- Se eliminaron los espacios en blanco adicionales y se ajustó la estructura del código para mayor legibilidad.
- Se utilizó el atributo `style` en la etiqueta `<h2>` para centrar el título del examen.
- Se movió la etiqueta `<form>` fuera del elemento `<table>` para asegurar su validez semántica.
- Se agregaron templates específicos para las opciones de tipo "multiple" y se aplican utilizando `<xsl:apply-templates>`.
- Se ajustaron los elementos de entrada según los diferentes tipos de cuestiones (número, booleano y texto largo).

Ten en cuenta que los campos de entrada deben vincularse correctamente con tu lógica de procesamiento del lado del servidor para capturar y manejar las respuestas del examen.

Espero que esta modificación te ayude a lograr el formato deseado en tu página de examen.
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