XSL - URGENTE AYUDA

 
Vista:
sin imagen de perfil

URGENTE AYUDA

Publicado por esemgi (1 intervención) el 04/06/2015 12:44:10
Quiero realizar un xls de este xml que enere un html MUY URGENTE
<facturas>
<factura codigo="AA123456">
<fecha>
<dia>12</dia>
<mes>1</mes>
<año>2012</año>
</fecha>
<nombre>Fernando</nombre>
<nit>54545454X</nit>
<direccion>C/ Sarten sin rabo, nº (tapao con barro) - La Roda (Albacete)</direccion>
<tels>666-323245</tels>
<linea>
<descripcion>plancha de pelo</descripcion>
<valor>56.09 </valor>
</linea>
<linea>
<descripcion>tijeras </descripcion>
</linea>
</factura>
<factura codigo="AA123400">
<fecha>
<dia>20</dia>
<mes>01</mes>
<año>2012</año>
</fecha>
<nombre>Fernando</nombre>
<nit>54545454X</nit>
<direccion>C/ Sarten sin rabo, nº (tapao con barro) - La Roda (Albacete)</direccion>
<tels>666-000000</tels>
<linea>
<descripcion>garrafa de agua</descripcion>
<valor>11.23 </valor>
</linea>
<linea>
<descripcion>harina de garbanzos</descripcion>
<valor>3.23</valor>
</linea>
<linea>
<descripcion>calabazas grandes</descripcion>
<valor>8.13</valor>
</linea>
</factura>
<factura codigo="GT324532">
<fecha>
<dia>1</dia>
<mes>12</mes>
<año>2013</año>
</fecha>
<nombre>Alicia</nombre>
<nit>12312340X</nit>
<direccion>C/ El otro lado del espejo, nº (69) - Distrito norte (Londres)</direccion>
<tels>032-2343 545 33</tels>
<linea>
<descripcion>fish and chips</descripcion>
</linea>
<linea>
<descripcion>carrots</descripcion>
<valor>6.78</valor>
</linea>
<linea>
<descripcion>meat</descripcion>
<valor>14.00</valor>
</linea>
<linea>
<descripcion>apples</descripcion>
<valor>3.75</valor>
</linea>
<linea>
<descripcion>oranges</descripcion>
<valor>4.20</valor>
</linea>
</factura>
</facturas>
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 de facturas desde XML

Publicado por Alejandro (227 intervenciones) el 07/07/2023 17:31:47
Aquí tienes un ejemplo de código XSL para generar un archivo HTML a partir del XML proporcionado:

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
<?xml version="1.0" encoding="ISO-8859-1"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
  <xsl:template match="/">
    <html>
      <body>
        <h2>Facturas</h2>
        <table border="1">
          <tr bgcolor="#DFDFDF">
            <th>Código</th>
            <th>Fecha</th>
            <th>Nombre</th>
            <th>NIT</th>
            <th>Dirección</th>
            <th>Teléfono</th>
            <th>Descripción</th>
            <th>Valor</th>
          </tr>
          <xsl:for-each select="//factura">
            <xsl:variable name="codigo" select="@codigo" />
            <xsl:variable name="fechaDia" select="fecha/dia" />
            <xsl:variable name="fechaMes" select="fecha/mes" />
            <xsl:variable name="fechaAnio" select="fecha/año" />
            <xsl:variable name="nombre" select="nombre" />
            <xsl:variable name="nit" select="nit" />
            <xsl:variable name="direccion" select="direccion" />
            <xsl:variable name="telefono" select="tels" />
            <xsl:for-each select="linea">
              <tr>
                <xsl:if test="position() = 1">
                  <td rowspan="{count(linea)}">
                    <xsl:value-of select="$codigo" />
                  </td>
                  <td rowspan="{count(linea)}">
                    <xsl:value-of select="concat($fechaDia, '/', $fechaMes, '/', $fechaAnio)" />
                  </td>
                  <td rowspan="{count(linea)}">
                    <xsl:value-of select="$nombre" />
                  </td>
                  <td rowspan="{count(linea)}">
                    <xsl:value-of select="$nit" />
                  </td>
                  <td rowspan="{count(linea)}">
                    <xsl:value-of select="$direccion" />
                  </td>
                  <td rowspan="{count(linea)}">
                    <xsl:value-of select="$telefono" />
                  </td>
                </xsl:if>
                <td>
                  <xsl:value-of select="descripcion" />
                </td>
                <td>
                  <xsl:value-of select="valor" />
                </td>
              </tr>
            </xsl:for-each>
          </xsl:for-each>
        </table>
      </body>
    </html>
  </xsl:template>
</xsl:stylesheet>

Guarda este código XSL en un archivo con extensión ".xsl" y aplícalo a tu XML para generar el HTML correspondiente.
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