2017-02-21 79 views
0

XML文件包含帐户和帐户列表(包含ID和AccountDescription)。 在下面的例子中,有2个帐户。如何显示所有XSL元素?

<?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 AccountDescription

在第2页:

ID AccountDescription

我想显示这样的数据:

ID AccountDescription

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> 
+0

你想申请,模板/匹配'AccountRow',但该元素不会在你的示例XML存在。这是你的样式表的问题还是你的样本问题? –

+0

是的,你是对的。我编辑了我原来的帖子,所以现在我不会调用。相反,我做了。 有了这个,我看到的数据,但每个数据显示在不同的页面上,即:Page 1我有5 - 帐户说明5,并在第2页我有8 - 帐户说明8.如何显示所有数据同一页?谢谢。 – faujong

回答

1

我如何可以显示在同一页面中的所有数据?

您只需要使用一个fo:page-sequence。将其从Account模板上移到Accounts模板中。

更新XSLT

<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> 
     <fo:page-sequence master-reference="main"> 
     <fo:flow flow-name="xsl-region-body"> 
      <xsl:apply-templates select="Account"/> 
     </fo:flow> 
     </fo:page-sequence> 
    </fo:root> 
    </xsl:template> 

    <xsl:template match="Account"> 
    <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> 
    </xsl:template> 

</xsl:stylesheet> 
+0

这很有效,谢谢!但是,它重复每一行的列标题。所以,我对它做了小的修改:< fo:table-row> ID faujong

相关问题