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

用于显示pdf生成的xml数据的xsl fo表,xml,pdf,xslt,pdf-generation,xsl-fo,Xml,Pdf,Xslt,Pdf Generation,Xsl Fo,我需要一些关于xsl fo中的模板的帮助,以便从xml数据生成pdf 我的问题是,我需要创建一个只获取多个项中的一个项(节点)的表 例如,我可能有一个如下所示的xml <CollectionOfItems> <items> <title ID="someid" location="somelocation" price="someprice"/> <title ID="someid" location="somelocation" price="some

我需要一些关于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>

每个“items”节点都需要位于一个单独的表中……所以我在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个表,其中有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”标记中的每个属性创建一个单元格的模板。我相信这就是你想要的。

在你的XSL:/Items/item/DataModification/Form/Tab/ModControl/Value/competencyconconfig/Chapters/Chapters中向我们展示这一点,然后提供一个甚至不具备这种结构(或其上的模板)的XML是毫无价值的。没有人能猜出你工作的背景。因此,请你进一步解释,并根据你的输入。。。你是说你想要六张桌子吗?第一个有3行,第二个有3行。第三排,第四排,第五排和第六排各一排?这就是你要问的吗?对不起,凯文,我想把它改为/collectionfitems/items/title。我想要3个表,在每个表中我应该有“items”节点中的内容。第一个“items”节点应位于第一个表中。所以第一个表应该有3行,第二个表应该有3行,第三个表应该有6行。它们都应该有3列(ID、location和price)。执行解析的XML处理器可以按任意顺序将属性呈现给XSLT处理器。在一般情况下,按照所需的顺序选择属性会更安全。在这种情况下,您甚至可以在处理属性时按名称对属性进行排序。然后,在一个封闭的系统中,您生成了XML,并且您知道一切是如何工作的,属性可能会按照预期的顺序得到处理,就像它们在这里一样。