繁体   English   中英

xsl-fo表显示pdf生成的xml数据

[英]xsl-fo table to display xml data for a pdf generation

我需要有关xsl-fo中的模板的帮助,以便从xml数据生成pdf。

我的问题是我需要制作一张仅包含许多项(节点)的表。

例如,我可能有一个看起来像这样的xml

<CollectionOfItems>
<items>
<title ID="someid" location="somelocation" price="someprice"/>
<title ID="someid" location="somelocation" price="someprice"/>
<title ID="someid" location="somelocation" price="someprice"/>
</items>
<items>
<title ID="someid" location="somelocation" price="someprice"/>
<title ID="someid" location="somelocation" price="someprice"/>
<title ID="someid" location="somelocation" price="someprice"/>
</items>
</items>
<title ID="someid" location="somelocation" price="someprice"/>
<title ID="someid" location="somelocation" price="someprice"/>
<title ID="someid" location="somelocation" price="someprice"/>
<title ID="someid" location="somelocation" price="someprice"/>
<title ID="someid" location="somelocation" price="someprice"/>
<title ID="someid" location="somelocation" price="someprice"/>
</items>
</CollectionOfItems>

每个“项目”节点都需要在单独的表中...所以我在xsl-fo表中制作了一个看起来像这样的表

<fo:table width="100%" border-style="outset" border-width="2pt" background-repeat="no-repeat">
<fo:table-column/>
<fo:table-column/>
<fo:table-column/>
<fo:table-body>
    <xsl:for-each select="/Items/item/DataModification/Form/Tab/ModControl/Value/CompetenceConfig/Chapters/Chapter">
        <xsl:variable name="Chapter" select="."/>
        <fo:table-row>
            <fo:table-cell border-style="inset" border-width="2pt" padding="2pt" background-repeat="repeat" display-align="center">
                <fo:block>
                    <xsl:value-of select="@ID"/>
                </fo:block>
            </fo:table-cell>
            <fo:table-cell border-style="inset" border-width="2pt" padding="2pt" background-repeat="repeat" display-align="center">
                <fo:block>
                    <xsl:value-of select="@location"/>
                </fo:block>
            </fo:table-cell>
            <fo:table-cell border-style="inset" border-width="2pt" padding="2pt" background-repeat="repeat" display-align="center">
            <fo:block>
                <xsl:value-of select="@price"/>
            </fo:block>
            </fo:table-cell>
        </fo:table-row>
    </xsl:for-each>
</fo:table-body>

这种方法是可行的,但是不是像每个表那样获得一个带有内部项目的“ items”节点,而是得到三个带有相同外观的3个“ items”节点的表。 如何在第一个表中显示第一个“节点”项,在第二个表中显示第二个“项”节点,依此类推? 我真的很感谢任何帮助。 几天来我一直在努力解决这个问题,而我对xsl-fo还是陌生的。

非常感谢!

那这样的东西呢? 不知道您还有什么,并更正XML中的错误。

    <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:fo="http://www.w3.org/1999/XSL/Format">
    <xsl:template match="/">
        <fo:root>
            <fo:layout-master-set>
                <fo:simple-page-master master-name="page" page-width="8.5in" page-height="11in" margin-top="0.5in" margin-bottom="0.5in" margin-left="0.5in" margin-right="0.5in">
                    <fo:region-body region-name="body" margin-top="0.5in" margin-bottom="0.5in" margin-left="0.5in" margin-right="0.5in"/>
                </fo:simple-page-master>
            </fo:layout-master-set>
            <fo:page-sequence master-reference="page">
                <fo:flow flow-name="body">
                    <xsl:apply-templates/>
                </fo:flow>
            </fo:page-sequence>
        </fo:root>
    </xsl:template>
    <xsl:template match="items">
        <fo:block space-before="6pt" border-top="3pt solid green">
            <fo:table>
                <fo:table-body>
                    <xsl:apply-templates/>
                </fo:table-body>
            </fo:table>
        </fo:block>
    </xsl:template>
    <xsl:template match="title">
        <fo:table-row>
            <xsl:apply-templates select="@*"/>
        </fo:table-row>
    </xsl:template>
    <xsl:template match="@ID | @location | @price">
        <fo:table-cell border="1pt solid black">
            <fo:block>
                <xsl:value-of select="."/>
            </fo:block>
        </fo:table-cell>
    </xsl:template>
</xsl:stylesheet>

产生此:

在此处输入图片说明

它具有用于为每个“ items”标签创建表,为每个“ title”标签创建一行以及为“ title”标签中每个属性创建一个单元的模板。 我相信那就是你想要的。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM