XSL转换为中间有“ - ”的整数提供NaN

时间:2014-01-17 13:14:07

标签: xml xslt xslt-1.0

我有以下xml代码,我已对其应用了转换,以使我的数据达到5个小数点。但我不想对其间有“ - ”的数据应用转换。见第1栏。

<Column1>1718-001</Column1>
<Column2>2013</Column2>
<Column3>KK</Column3>
<Column4>42000</Column4>

这是我申请的xslt。

 <xsl:template match = "*[translate(.,'-0123456789.******', '') = ''][not(*)]            

   [translate(.,'-0123456789.*****', '') = '']">

    <xsl:copy>
      <xsl:value-of select="format-number(number(.), '0.00000')"/>

    </xsl:copy>

这是我得到的结果。但是我不想对有“ - ”的数据应用xslt  介于两者之间。(我不想那个NaN)

 <Row>
 <Column1>NaN</Column1>
 <Column2>2013.00000</Column2>
 <Column3>KK</Column3>
 <Column4>42000.00000</Column4>
 </Row>

1 个答案:

答案 0 :(得分:3)

这会做你需要的吗?

<xsl:template match = "*[not(*) and number() = number()]">
    <xsl:copy>
      <xsl:value-of select="format-number(., '0.00000')"/>
    </xsl:copy>
</xsl:template>

它只匹配其字符串值可以成功转换为数字的叶元素。