XSLT-复制的使用似乎忽略了模板中的“ if”语句

|| 我今天早些时候发布了另一个查询,询问是否包含适用于不同模板的标记,并且收到了一些答复,这些答复有助于我获得所需的输出。现在,我还有一个小细节要解决。我的XML看起来像:
<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?>
<root>
    <account>
        <name>accountA</name>
    </account>
    <period>
        <type>priormonth</type>
        <balance>0.0000</balance>
    </period>
    <period>
        <type>currentmonth</type>
        <balance>20.0000</balance>
    </period>
    <account>
        <name>accountB</name>
    </account>
    <period>
        <type>priormonth</type>
        <balance>30.0000</balance>
    </period>
    <period>
        <type>currentmonth</type>
        <balance>0.0000</balance>
    </period>
</root>
我的XSLT看起来像:
<xsl:stylesheet version=\"1.0\" xmlns:xsl=\"http://www.w3.org/1999/XSL/Transform\">
<xsl:output method=\"xml\" indent=\"yes\"/>

<xsl:template match=\"/root\">
        <xsl:apply-templates select=\"account\"/>
</xsl:template>

<xsl:template match=\"account\">
    <xsl:copy>
        <xsl:copy-of select=\"name\" />
        <perioddata>
            <xsl:copy-of select=\"following-sibling::period[position()&lt;=2]\" />
        </perioddata>
    </xsl:copy>
</xsl:template>

<xsl:template match=\"period\">
    <period>
    <type> <xsl:value-of select=\"type\"/> </type>
    <balance>
    <xsl:if test=\"balance != 0\">
        <xsl:value-of select=\"balance\"/>
    </xsl:if>
    </balance>
    </period>
</xsl:template>

</xsl:stylesheet>
产生的输出如下:
<account>
  <name>accountA</name>
  <perioddata>
      <period>
          <type>priormonth</type>
          <balance>0.0000</balance>
      </period>
      <period>
          <type>currentmonth</type>
          <balance>20.0000</balance>
      </period>
   </perioddata>
</account>
<account>
  <name>accountB</name>
  <perioddata>
      <period>
          <type>priormonth</type>
          <balance>30.0000</balance>
      </period>
      <period>
          <type>currentmonth</type>
          <balance>0.0000</balance>
      </period>
   </perioddata>
</account>
此输出很好,除了我希望使用以下行:
<balance>0.0000</balance>
显示为:
<balance/>
对于上面的任何错字表示歉意...我主要是在打字而不是剪切/粘贴。我在读\“ copy-of \”可以与\“ value-of \”相同,并产生文本输出,该文本输出可以解释为什么\“ if \”子句不能识别零值。我试着做:
<xsl:if test=\"number(balance) != 0\">
但仍然没有得到我想要的结果。谢谢。     
已邀请:
尝试改变
<xsl:copy-of select=\"following-sibling::period[position()&lt;=2]\" />
<xsl:apply-templates select=\"following-sibling::period[position()&lt;=2]\" />
您的\“ period \”模板未使用,因为\“ root \”模板消耗了节点。     

要回复问题请先登录注册