値が数値の場合は変数に要素の値を持たせたいのですが、そうでない場合は変数に value を持たせたいです0
。
言い換えれば、XSLT に次の単純な同等物はありますか?
var foobar = is_numeric(element value) ? element value : 0
または、これをどのように書きますか?
<xsl:variable name="foobar" select=" ? " />
XPath 1.0:
<xsl:variable name="foobar">
<xsl:choose>
<xsl:when test="number($value) = number($value)">
<xsl:value-of select="$value"/>
</xsl:when>
<xsl:otherwise>0</xsl:otherwise>
</xsl:choose>
</xsl:variable>
この巧妙なnumber($value) = number($value)
数値テストの参照: Dimitre Novatchev 's answer to "Xpath test if is number" question .
castable as
XPath 2.0 では、はい、" "を使用できます
<xsl:variable name="foobar" as="xs:double"
select="if (x castable as xs:double) then x else 0" />