Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Problem generating 500 receipts HTML from a xsl generator

I am generating a HTML about a 500 receipts from a xsl file but in the last two bills from the 500 they are not generated the way i want.

I get this error: Type error at char 26 in expression in xsl:value-of/@select on line 17 column 174 of llista_factures.xsl:
XPTY0004 A sequence of more than one item is not allowed as the first operand of ‘*
(<unitats>, <unitats>, <unitats>, …)
In template rule with match="celler" on line 5 of llista_factures.xsl
invoked by built-in template rule (text-only)
[ERROR]: file:/C:/FP/Llenguatge%20de%20marques/TercerTrimestre/XML/AgendaXML/AgendaXML/ImportantEntrega/llista_factures.xsl: line 17: column 26: A sequence of more than one item is not allowed as the first operand of ‘*‘ (<unitats>, <unitats>, <unitats>, …) I tried fixing the problem but it didnt worked. I also tried increasing the memory heap but i didn’t change anything. If someone knows how i can fix it… **

The structure from the 1 bill should look like this, I am putting only 1 because the file extends up 52981 lines of coding:

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

     <!DOCTYPE HTML><html>
   <head>
      <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
      <title>Celler</title>
      <link rel="stylesheet" href="estil_factures.css">
   </head>
   <body>
      <table>
         <tr>
            <td colspan="5">
               <h1>Distribucions Tunel</h1>
            </td>
         </tr>
         <tr colspan="3">
            <td>Factura: F000001</td>
            <td>Codi:C00071</td>
            <td class="columna_client">Client: Tomas Muñoz, Diana Iris</td>
         </tr>
         <tr>
            <td>Codi</td>
            <td>Producte</td>
            <td class="quantitat_columna">Quantitat</td>
            <td>Preu per unitat</td>
            <td>Preu Total</td>
         </tr>
         <tr>
            <td>B5</td>
            <td>Vi blanc garrafa de 5 litres</td>
            <td class="columna_quantitat">5</td>
            <td>8.85€</td>
            <td>44.25€</td>
         </tr>
         <tr>
            <td>N1</td>
            <td>Vi negre botella d'1 litre</td>
            <td class="columna_quantitat">1</td>
            <td>2.00€</td>
            <td>2.00€</td>
         </tr>
         <tr>
            <td>N2</td>
            <td>Vi negre botella de 2 litres</td>
            <td class="columna_quantitat">2</td>
            <td>3.95€</td>
            <td>7.90€</td>
         </tr>
         <tr>
            <td>N3</td>
            <td>Vi negre garrafa de 3 litres</td>
            <td class="columna_quantitat">2</td>
            <td>5.45€</td>
            <td>10.90€</td>
         </tr>
         <tr>
            <td>N5</td>
            <td>Vi negre garrafa de 5 litres</td>
            <td class="columna_quantitat">1</td>
            <td>8.85€</td>
            <td>8.85€</td>
         </tr>
         <tr>
            <td>R1</td>
            <td>Vi rosat botella d'1 litre</td>
            <td class="columna_quantitat">1</td>
            <td>2.00€</td>
            <td>2.00€</td>
         </tr>
         <tr>
            <td>R5</td>
            <td>Vi rosat garrafa de 5 litres</td>
            <td class="columna_quantitat">5</td>
            <td>8.85€</td>
            <td>44.25€</td>
         </tr>
         <tr class="empty-row">
            <td></td>
            <td></td>
            <td></td>
            <td></td>
            <td></td>
         </tr>
         <tr class="empty-row">
            <td></td>
            <td></td>
            <td></td>
            <td></td>
            <td></td>
         </tr>
         <tr class="empty-row">
            <td></td>
            <td></td>
            <td></td>
            <td></td>
            <td></td>
         </tr>
         <tr class="empty-row">
            <td></td>
            <td></td>
            <td></td>
            <td></td>
            <td></td>
         </tr>
         <tr class="empty-row">
            <td></td>
            <td></td>
            <td></td>
            <td></td>
            <td></td>
         </tr>
         <tr>
            <td colspan="3" bgcolor="white"></td>
            <td align="right">total</td>
            <td align="right">120.15€</td>
         </tr>

This is the XSL that generates the HTML:

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="2.0">

    <xsl:output method="html" encoding="UTF-8" indent="yes"/>

    <xsl:template match="celler">
        <html>
            <head>
                <title>Celler</title>
                <link rel="stylesheet" href="estil_factures.css"/>
            </head>
            <body>
                <table>
                    <xsl:apply-templates select="factures/factura"/>
                    <tr>
                        <td colspan="5" align="right">
                            <xsl:text>Total: </xsl:text>
                            <xsl:value-of select="format-number(sum(factures/factura/unitats * //producte[@codi=current()/factures/factura/unitats/@codi]/@preu), '#.00€')"/>
                        </td>
                    </tr>
                </table>
            </body>
        </html>
    </xsl:template>

    <xsl:template match="factura">
        <tr>
            <td colspan="5">
                <h1>Distribucions Tunel</h1>
            </td>
        </tr>
        <tr colspan="3">

            <xsl:variable name="codi_client" select="comprador/@codi"/>
            <xsl:variable name="client" select="//client[@codi=$codi_client]"/>
            <td>Factura: <xsl:value-of select="@numero"/></td>
            <td>Codi:<xsl:value-of select="$client/@codi"/></td>
            <td class="columna_client">Client: <xsl:value-of select="$client/nom"/></td>
        </tr>

        <tr>
            <td>Codi</td>
            <td>Producte</td>
            <td class="quantitat_columna">Quantitat</td>
            <td>Preu per unitat</td>
            <td>Preu Total</td>
        </tr>

        <xsl:apply-templates select="unitats"/>

        <!-- Filas vacías -->
        <xsl:variable name="emptyRowCount" select="12 - count(unitats)"/>
        <xsl:if test="$emptyRowCount > 0">
            <xsl:call-template name="emptyRow">
                <xsl:with-param name="count" select="$emptyRowCount"/>
            </xsl:call-template>
        </xsl:if>

        <xsl:variable name="total">
            <xsl:for-each select="unitats">
                <td>Codi</td>
                <xsl:variable name="codi_producte" select="@codi"/>
                <xsl:variable name="producte" select="//producte[@codi=$codi_producte]"/>
                <xsl:element name="parcial">
                    <xsl:for-each select=".">
                        <xsl:variable name="currentUnitat" select="."/>
                        <xsl:for-each select="$producte/@preu">
                            <xsl:variable name="currentPreu" select="."/>
                            <parcial>
                                <xsl:value-of select="$currentUnitat * $currentPreu"/>
                            </parcial>
                        </xsl:for-each>
                    </xsl:for-each>

                </xsl:element>
            </xsl:for-each>
        </xsl:variable>
        <tr>
        <td colspan="3" bgcolor="white"></td>
        <td align="right">total</td>
        <td align="right"><xsl:value-of select="format-number(sum($total/parcial),'#.00€')"/></td>
        </tr>
    </xsl:template>
<xsl:template name="emptyRow">
    <xsl:param name="count"/>
    <xsl:if test="$count > 0">
        <tr class="empty-row">
            <td></td>
            <td></td>
            <td></td>
            <td></td>
            <td></td>
        </tr>
        <xsl:call-template name="emptyRow">
            <xsl:with-param name="count" select="$count - 1"/>
        </xsl:call-template>
    </xsl:if>
</xsl:template>


<xsl:template match="unitats">
    <xsl:variable name="codi_producte" select="@codi"/>
    <xsl:variable name="producte" select="//producte[@codi=$codi_producte]"/>
    <tr>
        <td><xsl:value-of select="$producte/@codi"/></td>
        <td><xsl:value-of select="$producte"/></td>
        <td class="columna_quantitat"><xsl:value-of select="."/></td>
        <td><xsl:value-of select="format-number($producte/@preu, '#.00€')"/></td>
        <td><xsl:value-of select="format-number(. * $producte/@preu, '#.00€')"/></td>
    </tr>
</xsl:template>

</xsl:stylesheet>

>Solution :

Assuming the line 17 is e.g. <xsl:value-of select="format-number(sum(factures/factura/unitats * //producte[@codi=current()/factures/factura/unitats/@codi]/@preu), '#.00€')"/> then the error tells you that factures/factura/unitats selects more than one unitats element. And the * operator needs to have a single item on the left or right.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading