如何显示所有 XSL 元素?

How to show all XSL elements?

XML 文件包含帐户和帐户列表(包含 ID 和帐户描述)。 在下面的示例中,有 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,但下面没有 data/content,如下所示:

第 1 页:

ID AccountDescription

第 2 页:

ID AccountDescription

我想这样显示数据:

ID AccountDescription

5 Account Description 5

8 Account Description 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>

How can I show all data in the same page ?

您只需使用一个 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>