【发布时间】:2017-07-11 15:06:13
【问题描述】:
XML 文件包含帐户和帐户列表(包含 ID 和 AccountDescription)。 在下面的示例中,有 2 个帐户。
<?xml version="1.0"?>
<Accounts>
<Account>
<ID>5</ID>
<AccountDescription>Account Description 5</AccountDescription>
</Account>
<Account>
<ID>8</ID>
<AccountDescription>Account Description 8</AccountDescription>
</Account>
</Accounts>
当使用下面的 XSL 时,它会创建一个包含 2 页的 PDF 文件,每个页面都有标题 ID 和 AccountDescription,但它下面没有数据/内容,如下所示:
在第 1 页:
ID 帐户描述
在第 2 页:
ID 帐户描述
我想这样显示数据:
ID 帐户描述
5 账户说明 5
8 帐户说明 8
我该怎么做?谢谢。
这是我当前的 XSL:
<xsl:stylesheet version="2.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:fo="http://www.w3.org/1999/XSL/Format">
<xsl:template match="Accounts">
<fo:root xmlns:fo="http://www.w3.org/1999/XSL/Format">
<fo:layout-master-set>
<fo:simple-page-master
master-name="main"
margin-top="0px"
margin-bottom="0px"
margin-left="18px"
margin-right="18px">
<fo:region-body margin-top="0.75in" margin-bottom="2in" margin-left="18px" margin-right="18px"/>
<fo:region-before extent="0.75in"/>
<fo:region-after extent="1.5in"/>
<fo:region-end extent="75px"/>
</fo:simple-page-master>
</fo:layout-master-set>
<xsl:apply-templates select="Account"/>
</fo:root>
</xsl:template>
<xsl:template match="Account">
<fo:page-sequence master-reference="main">
<fo:flow flow-name="xsl-region-body">
<fo:table font-size="10pt">
<fo:table-column column-width="15mm"/>
<fo:table-column column-width="55mm"/>
<fo:table-body>
<fo:table-row>
<fo:table-cell >
<fo:block text-align="right"><xsl:value-of select="ID"/></fo:block>
</fo:table-cell>
<fo:table-cell >
<fo:block text-align="right"><xsl:value-of select="AccountDescription"/></fo:block>
</fo:table-cell>
</fo:table-row>
</fo:table-body>
</fo:table>
</fo:flow>
</fo:page-sequence>
</xsl:template>
</xsl:stylesheet>
【问题讨论】:
-
您正在尝试将模板应用于/匹配
AccountRow,但该元素在您的示例 XML 中不存在。这是您的样式表的问题还是您的示例的问题? -
是的,你是对的。我编辑了我的原始帖子,所以现在我没有调用
。相反,我使用 。有了这个,我确实看到了数据,但是每个数据都显示在不同的页面上,即:第 1 页我有 5 - 帐户描述 5,在第 2 页我有 8 - 帐户描述 8。我怎样才能在同一页面中显示所有数据页 ?谢谢。
标签: asp.net xml asp.net-mvc-4 xslt apache-fop