xslt for-each语句显示重复项

时间:2014-06-20 18:40:50

标签: xml xslt xsl-fo

这是xml:

          <root>
            ...
            <payment-schedule>
              <loan>
                <l-number id='0'>00321-123456789-01</l-number>
                <financed id='0'>2500.0000</financed>
              </loan>
              <loan>
                <l-number id='1'>00321-123456789-02</l-number>
                <financed id='1'>3000.0000</financed>
              </loan>
            </payment-schedule>
          </root>

这是xslt:

          <!--Repeating Rows Displays Loans-->
          <xsl:apply-templates select="loan"/>

          </xsl:template>

          <xsl:template match="loan">
            <xsl:for-each select="/root/payment-schedule/loan">
              <fo:table-row>
                <fo:table-cell border-right-style="solid" border-width="0.2mm" padding-left="2mm">
                </fo:table-cell>
                <fo:table-cell border-right-style="solid" border-width="0.2mm" padding-left="2mm">
                  <fo:block font-weight="bold">
                    <xsl:value-of select="l-number" />:  $<xsl:value-of select='format-number(financed, "#.00")'/>
                  </fo:block>
                </fo:table-cell>
              </fo:table-row>
            </xsl:for-each>
          </xsl:template>

这是输出:

00321-123456789-01:  $2500.00
00321-123456789-02:  $3500.00
00321-123456789-01:  $2500.00
00321-123456789-02:  $3500.00

我花了太多时间尝试删除这些重复的节点。帮助!

1 个答案:

答案 0 :(得分:1)

您有一个为每个loan触发一次的模板,在该模板中,您再次对所有for-each元素执行loan。删除for-each,您应该得到所需的结果。

 <xsl:template match="loan">
   <fo:table-row>
     <!-- ... -->