使用XML数据,XSLT和xsl-fo创建PDF

时间:2017-07-27 14:35:22

标签: xml pdf xslt xmltable

我正在尝试从XML Data创建PDF表格。我正在努力的是为不同的货币创建单独的表。

我已经设法创建了一个带有标题的简单表,它可以提取所有数据,但现在我试图让它只通过特定数据。

data.xml中

<?xml version="1.0" encoding="UTF-8" ?>
<StockFile>
   <Customer>
       <Supplier>A</Supplier>
       <Currency>US DOLLAR</Currency>
       <Deposit>0</Deposit>
       <Balance>0</Balance>
       <January>0</January>
       <February>0</February>
       <March>0</March>
       <April>0</April>
       <May>0</May>
       <June>0</June>
       <July>62</July>
       <August>18</August>
       <September>0</September>
       <October>0</October>
       <November>0</November>
       <December>77</December>
       <Total>157</Total>
       <Notes></Notes>
    </Customer>
    <Customer>
       <Supplier>B</Supplier>
       <Currency>Euro</Currency>
       <Deposit>0</Deposit>
       <Balance>0</Balance>
       <January>0</January>
       <February>0</February>
       <March>0</March>
       <April>11</April>
       <May>94</May>
       <June>0</June>
       <July></July>
       <August>18</August>
       <September>0</September>
       <October>0</October>
       <November>0</November>
       <December></December>
       <Total>123</Total>
       <Notes></Notes>
    </Customer>

Stylesheet.xsl

     <?xml version="1.0" encoding="ISO-8859-1"?>

   <xsl:stylesheet
        version="1.0"
        xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
        xmlns:fo="http://www.w3.org/1999/XSL/Format"
        xmlns:datetime="http://exslt.org/dates-and-times"
        xmlns:fmt="http://xml.apache.org/xalan/java/com.ims.fop.Formatting">

    <xsl:output method="xml"/>

<!-- REPORT BODY HEADER-->
    <xsl:template name="Body">
    <xsl:template match="/">
        <fo:block border="solid" border-after-width.conditionality="retain" border-before-width.conditionality="retain">
            <fo:table keep-together="auto" table-omit-footer-at-break="true" xsl:use-attribute-sets="normal-text">
                    <fo:table-column column-width="1.6cm"/>
                    <fo:table-column column-width="1.6cm"/>
                    <fo:table-column column-width="1.6cm"/>
                <fo:table-column column-width="1.6cm"/>
                <fo:table-column column-width="1.6cm"/>
                <fo:table-column column-width="1.6cm"/>
                <fo:table-column column-width="1.6cm"/>
                <fo:table-column column-width="1.6cm"/>
                <fo:table-column column-width="1.6cm"/>
                <fo:table-column column-width="1.6cm"/>
                <fo:table-column column-width="1.6cm"/>
                <fo:table-column column-width="1.6cm"/>
                <fo:table-column column-width="1.6cm"/>
                <fo:table-column column-width="1.6cm"/>
                <fo:table-column column-width="1.6cm"/>
                <fo:table-column column-width="1.6cm"/>
                <fo:table-column column-width="1.6cm"/>         
                <fo:table-column column-width="1.6cm"/>         
                <fo:table-header>
                    <xsl:call-template name="backgroundheader"/>
                    <fo:table-row xsl:use-attribute-sets="h2">
                        <fo:table-cell xsl:use-attribute-sets="cell-padding"><fo:block>Supplier</fo:block></fo:table-cell>
                        <fo:table-cell xsl:use-attribute-sets="cell-padding"><fo:block>Deposit/Paid</fo:block></fo:table-cell>
                        <fo:table-cell xsl:use-attribute-sets="cell-padding"><fo:block>Bal to Pay</fo:block></fo:table-cell>
                        <fo:table-cell xsl:use-attribute-sets="cell-padding"><fo:block>Jan</fo:block></fo:table-cell>
                        <fo:table-cell xsl:use-attribute-sets="cell-padding"><fo:block>Feb</fo:block></fo:table-cell>
                        <fo:table-cell xsl:use-attribute-sets="cell-padding"><fo:block>Mar</fo:block></fo:table-cell>
                        <fo:table-cell xsl:use-attribute-sets="cell-padding"><fo:block>Apr</fo:block></fo:table-cell>
                        <fo:table-cell xsl:use-attribute-sets="cell-padding"><fo:block>May</fo:block></fo:table-cell>
                        <fo:table-cell xsl:use-attribute-sets="cell-padding"><fo:block>June</fo:block></fo:table-cell>
                        <fo:table-cell xsl:use-attribute-sets="cell-padding"><fo:block>July</fo:block></fo:table-cell>
                        <fo:table-cell xsl:use-attribute-sets="cell-padding"><fo:block>Aug</fo:block></fo:table-cell>
                        <fo:table-cell xsl:use-attribute-sets="cell-padding"><fo:block>Sept</fo:block></fo:table-cell>
                        <fo:table-cell xsl:use-attribute-sets="cell-padding"><fo:block>Oct</fo:block></fo:table-cell>
                        <fo:table-cell xsl:use-attribute-sets="cell-padding"><fo:block>Nov</fo:block></fo:table-cell>
                        <fo:table-cell xsl:use-attribute-sets="cell-padding"><fo:block>Dec</fo:block></fo:table-cell>
                        <fo:table-cell xsl:use-attribute-sets="cell-padding"><fo:block>Total</fo:block></fo:table-cell>
                        <fo:table-cell xsl:use-attribute-sets="cell-padding"><fo:block>Notes</fo:block></fo:table-cell>
                    </fo:table-row>
                    <xsl:template match="USHeader"/>
                </fo:table-header>
                <fo:table-body>
                <!--Not sure what to put in this section-->

                </fo:table-body>
            </fo:table>
        </fo:block>
    </xsl:template >
</xsl:template>

    <xsl:template name="USHeader">
    <fo:table-row xsl:use-attribute-sets="h2">
                        <fo:table-cell xsl:use-attribute-sets="cell-padding">$<fo:block></fo:block></fo:table-cell>
                        <fo:table-cell xsl:use-attribute-sets="cell-padding">$<fo:block></fo:block></fo:table-cell>
                        <fo:table-cell xsl:use-attribute-sets="cell-padding">$<fo:block></fo:block></fo:table-cell>
                        <fo:table-cell xsl:use-attribute-sets="cell-padding">$<fo:block></fo:block></fo:table-cell>
                        <fo:table-cell xsl:use-attribute-sets="cell-padding">$<fo:block></fo:block></fo:table-cell>
                        <fo:table-cell xsl:use-attribute-sets="cell-padding">$<fo:block></fo:block></fo:table-cell>
                        <fo:table-cell xsl:use-attribute-sets="cell-padding">$<fo:block></fo:block></fo:table-cell>
                        <fo:table-cell xsl:use-attribute-sets="cell-padding">$<fo:block></fo:block></fo:table-cell>
                        <fo:table-cell xsl:use-attribute-sets="cell-padding">$<fo:block></fo:block></fo:table-cell>
                        <fo:table-cell xsl:use-attribute-sets="cell-padding">$<fo:block></fo:block></fo:table-cell>
                        <fo:table-cell xsl:use-attribute-sets="cell-padding">$<fo:block></fo:block></fo:table-cell>
                        <fo:table-cell xsl:use-attribute-sets="cell-padding">$<fo:block></fo:block></fo:table-cell>
                        <fo:table-cell xsl:use-attribute-sets="cell-padding">$<fo:block></fo:block></fo:table-cell>
                        <fo:table-cell xsl:use-attribute-sets="cell-padding">$<fo:block></fo:block></fo:table-cell>
                        <fo:table-cell xsl:use-attribute-sets="cell-padding">$<fo:block></fo:block></fo:table-cell>
                        <fo:table-cell xsl:use-attribute-sets="cell-padding">$<fo:block></fo:block></fo:table-cell>
    </fo:table-row>
    </xsl:template>

    <xsl:template name="EUROHeader">
    <fo:table-row xsl:use-attribute-sets="h2">
                        <fo:table-cell xsl:use-attribute-sets="cell-padding"><fo:block></fo:block></fo:table-cell>
                        <fo:table-cell xsl:use-attribute-sets="cell-padding"><fo:block></fo:block></fo:table-cell>
                        <fo:table-cell xsl:use-attribute-sets="cell-padding"><fo:block></fo:block></fo:table-cell>
                        <fo:table-cell xsl:use-attribute-sets="cell-padding"><fo:block></fo:block></fo:table-cell>
                        <fo:table-cell xsl:use-attribute-sets="cell-padding"><fo:block></fo:block></fo:table-cell>
                        <fo:table-cell xsl:use-attribute-sets="cell-padding"><fo:block></fo:block></fo:table-cell>
                        <fo:table-cell xsl:use-attribute-sets="cell-padding"><fo:block></fo:block></fo:table-cell>
                        <fo:table-cell xsl:use-attribute-sets="cell-padding"><fo:block></fo:block></fo:table-cell>
                        <fo:table-cell xsl:use-attribute-sets="cell-padding"><fo:block></fo:block></fo:table-cell>
                        <fo:table-cell xsl:use-attribute-sets="cell-padding"><fo:block></fo:block></fo:table-cell>
                        <fo:table-cell xsl:use-attribute-sets="cell-padding"><fo:block></fo:block></fo:table-cell>
                        <fo:table-cell xsl:use-attribute-sets="cell-padding"><fo:block></fo:block></fo:table-cell>
                        <fo:table-cell xsl:use-attribute-sets="cell-padding"><fo:block></fo:block></fo:table-cell>
                        <fo:table-cell xsl:use-attribute-sets="cell-padding"><fo:block></fo:block></fo:table-cell>
                        <fo:table-cell xsl:use-attribute-sets="cell-padding"><fo:block></fo:block></fo:table-cell>
                        <fo:table-cell xsl:use-attribute-sets="cell-padding"><fo:block></fo:block></fo:table-cell>
    </fo:table-row>
    </xsl:template>

</xsl:stylesheet>

这是我的代码的主要部分,我已经尝试过了

 <xsl:key name="grpCur" match="Customer" use="Currency"/>

这不起作用

<xsl:for-each select="Customer[generate-id(.)=generate-id(key('grpCur', Currency))[1])]">

我迷失在哪里,因为我对XSLT作为一种语言并不过分自信。

0 个答案:

没有答案