对于每个功能不起作用,但是,当fop到pdf时,没有显示任何错误,如何解决?

时间:2019-04-05 11:50:10

标签: xml xslt apache-fop

我在使用“ for-each”功能执行循环时遇到了问题,我在请求模板调用时放到那里,但是此刻要打印出变形的FOP,它不会打印任何内容,并且FOP不会给我错误。 谁能告诉我是否有另一种方法可以执行此循环?

我尝试将循环放在XSL CODE的不同位置,但是他不起作用,他停用了该代码,而是显示了内容。

XSL代码:

<?xml version="1.0" encoding="iso-8859-1"?>
<xsl:stylesheet version="1.1" exclude-result-prefixes="fo" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:fo="http://www.w3.org/1999/XSL/Format">
<xsl:decimal-format name="euro" decimal-separator="," grouping-separator="."/>
<xsl:output method="xml" version="1.0" omit-xml-declaration="no" indent="yes"/>
<xsl:param name="versionParam" select="'1.0'"/>
<xsl:template name="FormatDate">
    <xsl:param name="DateTime"/>

    <xsl:variable name="year" select="substring($DateTime,1,4)"/>
    <xsl:variable name="month" select="substring($DateTime,6,2)"/>
    <xsl:variable name="day" select="substring($DateTime,9,2)"/>


    <xsl:value-of select="$day"/>
    <xsl:value-of select="'-'"/>
    <xsl:value-of select="$month"/>
    <xsl:value-of select="'-'"/>
    <xsl:value-of select="$year"/>

    <xsl:variable name="time" select="substring($DateTime,12)"/>
    <xsl:if test="$time != ''">
        <xsl:variable name="hh" select="substring($time,1,2)"/>
        <xsl:variable name="mm" select="substring($time,4,2)"/>
        <xsl:variable name="ss" select="substring($time,7,2)"/>

        <xsl:value-of select="' '"/>
        <xsl:value-of select="$hh"/>
        <xsl:value-of select="':'"/>
        <xsl:value-of select="$mm"/>
        <xsl:value-of select="':'"/>
        <xsl:value-of select="$ss"/>
    </xsl:if>

</xsl:template>


<!-- ========================= -->
<!-- root element: projectteam --> 
<!-- ========================= -->
<xsl:template match="documento">
    <fo:root xmlns:fo="http://www.w3.org/1999/XSL/Format">
        <fo:layout-master-set>
            <fo:simple-page-master master-name="firstPage" page-width="29.7cm" page-height="21cm" margin-top="0.6cm" margin-bottom="0.7cm" margin-left="1cm" margin-right="1cm">
                <fo:region-body margin-top="5.4cm" margin-bottom="1.4cm"/>
                <fo:region-before extent="0cm"/>
                <fo:region-after region-name="xsl-region-after-first-page" extent="1.5cm"/>
            </fo:simple-page-master>
            <fo:simple-page-master master-name="restPage" page-width="29.7cm" page-height="21cm" margin-top="0.6cm" margin-bottom="0.7cm" margin-left="1cm" margin-right="1cm">
                <fo:region-body margin-top="5.4cm" margin-bottom="1.4cm"/>
                <fo:region-before extent="0cm"/>
                <fo:region-after  region-name="xsl-region-after-rest-page" extent="1.5cm"/>
            </fo:simple-page-master>
            <fo:simple-page-master master-name="lastPage" page-width="29.7cm" page-height="21cm" margin-top="0.6cm" margin-bottom="0.7cm" margin-left="1cm" margin-right="1cm">
                <fo:region-body margin-top="5.4cm" margin-bottom="1.4cm"/>
                <fo:region-before extent="0cm"/>
                <fo:region-after region-name="xsl-region-after-last-page" extent="1.5cm"/>
            </fo:simple-page-master>
            <fo:page-sequence-master master-name="pages">
                <fo:repeatable-page-master-alternatives>
                    <fo:conditional-page-master-reference page-position="only"   master-reference="lastPage"/>
                    <fo:conditional-page-master-reference page-position="first"  master-reference="firstPage"/>
                    <fo:conditional-page-master-reference page-position="rest"   master-reference="restPage"/>
                    <fo:conditional-page-master-reference page-position="last"   master-reference="lastPage"/>
                </fo:repeatable-page-master-alternatives>
            </fo:page-sequence-master>
        </fo:layout-master-set>

        <fo:page-sequence master-reference="pages" id="end">
            <fo:static-content flow-name="xsl-region-before" >
            </fo:static-content>
            <fo:static-content flow-name="xsl-region-after-first-page">
            </fo:static-content>
            <fo:static-content flow-name="xsl-region-after-rest-page">
            </fo:static-content>
            <fo:static-content flow-name="xsl-region-after-last-page">
            </fo:static-content>
            <fo:flow flow-name="xsl-region-body" >
                <xsl:apply-templates select="tabella"/>
            </fo:flow>
                    </fo:page-sequence>
                    </fo:root>
                    </xsl:template>

                    <xsl:template match="piedipagina">
    <fo:table-row border="1pt solid">
        <fo:table-cell>
            <fo:block font-size = "8" text-align="center" padding-top="0.1cm" padding-bottom="0.1cm" padding-left="0.1cm">
                <xsl:value-of select="condPag"/>
            </fo:block>
        </fo:table-cell>
        <fo:table-cell>
            <fo:block font-size = "8" text-align="center" padding-top="0.1cm" padding-bottom="0.1cm" padding-left="0.1cm">
                <xsl:value-of select="valuta"/>
            </fo:block>
        </fo:table-cell>
        <fo:table-cell>
            <fo:block font-size = "8" text-align="center" padding-top="0.1cm" padding-bottom="0.1cm" padding-left="0.1cm">
                <xsl:value-of select="bollo"/>
            </fo:block>
        </fo:table-cell>
        <fo:table-cell>
            <fo:block font-size = "8" text-align="center" padding-top="0.1cm" padding-bottom="0.1cm" padding-left="0.1cm">
                <xsl:value-of select="totimpo"/>
            </fo:block>
        </fo:table-cell>
        <fo:table-cell>
            <fo:block font-size = "8" text-align="center" padding-top="0.1cm" padding-bottom="0.1cm" padding-left="0.1cm">
                <xsl:value-of select="totiva"/>
            </fo:block>
        </fo:table-cell>
        <fo:table-cell>
            <fo:block font-size = "8" text-align="center" padding-top="0.1cm" padding-bottom="0.1cm" padding-left="0.1cm">
                <xsl:value-of select="totdoc"/>
            </fo:block>
        </fo:table-cell>
        <fo:table-cell>
            <fo:block font-size = "8" text-align="center" padding-top="0.1cm" padding-bottom="0.1cm" padding-left="0.1cm">
                <xsl:value-of select="bollovirt"/>
            </fo:block>
        </fo:table-cell>
        <fo:table-cell>
            <fo:block font-size = "8" text-align="center" padding-top="0.1cm" padding-bottom="0.1cm" padding-left="0.1cm">
                <xsl:value-of select="banca"/>
            </fo:block>
        </fo:table-cell>
        <fo:table-cell>
            <fo:block font-size = "8" text-align="center" padding-top="0.1cm" padding-bottom="0.1cm" padding-left="0.1cm">
                <xsl:value-of select="fdes"/>
            </fo:block>
        </fo:table-cell>
        <fo:table-cell>
            <fo:block font-size = "8" text-align="center" padding-top="0.1cm" padding-bottom="0.1cm" padding-left="0.1cm">
                <xsl:value-of select="ftdinm"/>
            </fo:block>
        </fo:table-cell>
    </fo:table-row>
</xsl:template>

                    <xsl:template match="tabella">
    <fo:block page-break-after="always">
        <fo:table  width="100%" height="100%" border-width="0.3mm" border-style="transparent,solid,transparent,solid">
            <fo:table-column  column-width="10%"/>
            <fo:table-column  column-width="75%"/>
            <fo:table-column  column-width="10%"/>
            <fo:table-column  column-width="5%"/>
            <fo:table-header>
                <xsl:apply-templates select="testatabella"/>
            </fo:table-header>
            <fo:table-body>
                <xsl:apply-templates select="corpotabella"/>
                <xsl:apply-templates select="ivatabella"/>
            </fo:table-body>
        </fo:table>
    </fo:block>
</xsl:template>

<xsl:template match="testatabella">
    <fo:table-row>
        <fo:table-cell border-style="solid" border-width="0.3mm">
            <fo:block font-size = "10" text-align="center" padding-top="0.2cm" padding-bottom="0.2cm" padding-left="0.1cm" font-weight="bold">
                <xsl:value-of select="ordine"/>
            </fo:block>
        </fo:table-cell>
        <fo:table-cell border-style="solid" border-width="0.3mm" margin-bottom="8mm">
            <fo:block font-size = "10" text-align="center" padding-top="0.2cm" padding-bottom="0.2cm" padding-left="0.1cm" font-weight="bold">
                <xsl:value-of select="descrizione"/>
            </fo:block>
        </fo:table-cell>
        <fo:table-cell border-style="solid" border-width="0.3mm" margin-bottom="8mm">
            <fo:block font-size = "10" text-align="center" padding-top="0.2cm" padding-bottom="0.2cm" padding-left="0.1cm" font-weight="bold">
                <xsl:value-of select="importo"/>
            </fo:block>
        </fo:table-cell>
        <fo:table-cell border-style="solid" border-width="0.3mm" margin-bottom="8mm">
            <fo:block font-size = "10" text-align="center" padding-top="0.2cm" padding-bottom="0.2cm" padding-left="0.1cm" font-weight="bold">
                <xsl:value-of select="iva"/>
            </fo:block>
        </fo:table-cell>
    </fo:table-row>
</xsl:template>
<xsl:template match="corpotabella">
    <xsl:apply-templates select="riga"/>
</xsl:template>
<xsl:template match="riga">

<fo:table-row>

        <fo:table-cell margin="0.1" border-width="0.3mm" border-style="transparent">
            <fo:block font-size = "8" text-align="left" padding="0.1cm"  >
                <fo:block>
                    <xsl:value-of select="ordine"/><xsl:value-of select="dataordine"/>
                </fo:block>
            </fo:block>
        </fo:table-cell>
        <fo:table-cell margin="0.1cm" border-width="0.3mm" border-style="transparent">
            <fo:block font-size = "8" text-align="left" padding="0.1cm"  >
                <xsl:value-of select="descrizione"/>
            </fo:block>

        </fo:table-cell>
        <fo:table-cell margin="0.1cm" border-width="0.3mm" border-style="transparent">
            <fo:block font-size = "8" text-align="right" padding="0.1cm" >
                <xsl:choose>
                    <xsl:when test="importo !=''">

                        <xsl:value-of select="format-number(importo, '#.###.###.##0,00', 'euro')"/>
                    </xsl:when>
                    <xsl:otherwise/>
                </xsl:choose>
            </fo:block>
        </fo:table-cell>
        <fo:table-cell margin="0.1cm" border-width="0.3mm" border-style="transparent">
            <fo:block font-size = "8" text-align="center" padding="0.1cm" >
                <xsl:value-of select="iva"/>
            </fo:block>
        </fo:table-cell>
    </fo:table-row>


</xsl:template>


    <xsl:template match="iva">
    <fo:table-row>
        <fo:table-cell >
            <fo:block font-size = "6" text-align="center" padding-top="0.05cm" padding-bottom="0.05cm" padding-left="0.1cm" white-space-collapse="false">&#x00A0;</fo:block>
        </fo:table-cell>
        <fo:table-cell >
        <xsl:for-each select="ivariga">
            <fo:table margin-top="7mm">
                <fo:table-column  column-width="8%"/>
                <fo:table-column  column-width="71%"/>
                <fo:table-column  column-width="6%"/>
                <fo:table-column  column-width="5%"/>
                <fo:table-body>
                    <fo:table-row >
                        <fo:table-cell>
                            <fo:block font-size="8" margin-left="1mm" text-align="left">Cod. <xsl:value-of select="codiva"/>&#x00A0;&#x00A0;</fo:block>
                        </fo:table-cell>
                        <fo:table-cell>
                            <fo:block font-size="8" text-align="left">
                                <xsl:value-of select="desiva"/>
                            </fo:block>
                            <fo:block> &#x00A0; </fo:block>
                            <fo:block font-size="7.5" text-align="left">Imposta di bollo assolta in modo virtuale giusta autorizzazione del direttore dellufficio di genova 1, prot 88943 del 18/07/2007 </fo:block>
                        </fo:table-cell>
                        <fo:table-cell>
                            <fo:block font-size="8" text-align="left">Tot.imp</fo:block>
                        </fo:table-cell>
                        <fo:table-cell>
                            <fo:block font-size="8" text-align="right">

                                <xsl:value-of select="format-number(impiva, '#.###.###.##0,00', 'euro')"/>
                            </fo:block>
                        </fo:table-cell>
                    </fo:table-row>
                </fo:table-body>
            </fo:table>
            </xsl:for-each> 
        </fo:table-cell>
        <fo:table-cell>
            <fo:block font-size="8" text-align="right"/>
        </fo:table-cell>
        <fo:table-cell >
            <fo:block font-size="8" text-align="right">


            </fo:block>
        </fo:table-cell>
    </fo:table-row>
</xsl:template> 
</xsl:stylesheet> 

XML源:

<documento>
<intestazione1>
    <emittente1>Sede legale via Scarsellini, 171  -  16149 Genova (GE)</emittente1>
    <emittente2>CAP.SOCIALE 11.764.116,49 Euro I.V.</emittente2>
    <emittente3>REGISTRO IMPRESE CCIAA N.291785</emittente3>
    <emittente4>Tel. 01065701 r.a.   Fax 0106570310 </emittente4>
    <emittente5>Cod.Fisc e P.Iva:02716640103- Albo Autotr.GE/3405504/F</emittente5>
</intestazione1>
<intestazione2_1>
    <cliente1>AEM S.R.L.</cliente1>
    <cliente2>VIA C.R. CECCARDI,</cliente2>
    <cliente3>16121 GENOVA (GE)</cliente3>
    <cliente4/>
    <cliente5/>
    <cliente6/>
    <cliente7/>
    <cliente8>Cod: 000249 P.iva: IT01122330101</cliente8>
</intestazione2_1>
<intestazione2_2>
    <cliente1>AEM S.R.L.</cliente1>
    <cliente2>VIA C.R. CECCARDI,</cliente2>
    <cliente3>16121 GENOVA (GE)</cliente3>
    <cliente4/>
    <cliente5/>
    <cliente6/>
    <cliente7/>
    <cliente8>Cod: 000249 P.iva: IT01122330101</cliente8>
</intestazione2_2>
<piedipagina>
    <condPag>Ricevuta bancaria a 90 gg.d.f.fm.</condPag>
    <valuta>EURO</valuta>
    <bollo>0.00</bollo>
    <totimpo>4267.21</totimpo>
    <totiva>64.84</totiva>
    <totdoc>4332.05</totdoc>
    <bollovirt/>
    <banca>BANCA FILIALE OPERATIVA ROMA 1 - SWIFT CODE: UNCRITMMORR IBAN: IT06L 02008 05364 000500057491</banca>
    <ftdes>REBATE INCENTIVES GENNAIO 2019</ftdes>
    <ftdinm/>
</piedipagina>
<intestazione3>
    <riferimenti>Data: 13-03-2019     FATTURA   Numero:      RIF.INTERNO: NI/2019.2086</riferimenti>
    <nmec/>
    <divisione>TRASPORT DIVISION</divisione>
</intestazione3>
<tabella>
    <testatabella>
        <ordine>Ordine</ordine>
        <descrizione>Descrizione</descrizione>
        <importo>Importo</importo>
        <iva>Iva</iva>
    </testatabella>
    <corpotabella>
        <riga>
            <ordine>1464</ordine>
            <dataordine>04-01-2019</dataordine>
            <descrizione>Km: 153</descrizione>
            <importo/>
            <iva/>
        </riga>
        <riga>
            <ordine/>
            <dataordine/>
            <descrizione>Cntr:20BOX MFTU2132213 Bk:ITGOARBI1802508 Nave:AS PETRONIA Voy:19050007 Imb:GE Scalo:CARTAGENA</descrizione>
            <importo/>
            <iva/>
        </riga>
        <riga>
            <ordine/>
            <dataordine/>
            <descrizione>Term.Rit.Vuoti TERM. REBORA ARLUNO,ARLUNO(MI) / Riempimento PGM LOGISTICA,GORLAGO(BG) / Pesatura (Segue)</descrizione>
            <importo/>
            <iva/>
        </riga>
        <riga>
            <ordine/>
            <dataordine/>
            <descrizione>***PESATURA VGM***,MILANO(MI) / Term.Cons.Pieni TERM. REBORA ARLUNO,ARLUNO(MI) / Staz.Partenza TERM. (Segue)</descrizione>
            <importo/>
            <iva/>
        </riga>
        <riga>
            <ordine/>
            <dataordine/>
            <descrizione>REBORA ARLUNO,ARLUNO(MI) / Staz.Arrivo GENOA TERMINAL,GENOVA PORTO(GE)</descrizione>
            <importo/>
            <iva/>
        </riga>
        <riga>
            <ordine/>
            <dataordine/>
            <descrizione>Trasporto intermod.</descrizione>
            <importo>56.55</importo>
            <iva>58</iva>
        </riga>
    </corpotabella>
        <iva>
            <ivariga>
                <codiva>58</codiva>
                <desiva>Operazione non imponibile IVA art.9/1°c. Dpr 633/72</desiva>
                <impiva>3972.49</impiva>
                <iva>0.00</iva>
            </ivariga>
            <ivariga>
                <codiva>22</codiva>
                <desiva>Iva 22%</desiva>
                <impiva>294.72</impiva>
                <iva>64.84</iva>
            </ivariga>
        </iva>
</tabella>
</documento>

1 个答案:

答案 0 :(得分:0)

代码有两个问题。

处理ivariga的唯一地方是iva的模板。在示例XML源中,唯一的ivatabella的子级。但是:

  • riga的模板是唯一选择iva进行处理的模板,我们已经看到iva不是riga的子代。
  • tabella的模板仅选择testatabellacorpotabellaivatabella进行处理,因此未选择iva

我无法告诉您是否需要修复XML源或XSLT,但是两者之间目前存在脱节。