我正在使用 Saxon 9.4 和 XSLT 2.0
我的样式表中有以下代码片段:-
<xsl:template name="some_template">
<xsl:param name="some_param" as="xs:integer?"/>
</xsl:template>
这基本上是一个接受可选整数参数的模板。然而,当我尝试这样称呼它时,
<xsl:call-template name="some_template>
<xsl:with-param name="some_param">
<xsl:if test="some_condition">
<xsl:value-of select="xs:integer(./@attr div 20)"/>
</xsl:if>
</xsl:with-param>
</xsl:call-template>
我收到一条错误消息:-
Validation error FORG0001: Cannot convert zero-length string to an integer
但是,以下两个样式表不会给我一个错误:-
<xsl:call-template name="some_template>
<xsl:with-param name="some_param">
<xsl:value-of select="xs:integer(./@attr div 20)"/>
</xsl:with-param>
</xsl:call-template>
或者
<xsl:variable name="dummy" as="xs:integer?">
<xsl:if test="some_condition">
<xsl:value-of select="xs:integer(./@attr div 20)"/>
</xsl:if>
</xsl:variable>
<xsl:call-template name="some_template>
<xsl:with-param name="some_param" select="$dummy"/>
</xsl:call-template>
很明显,类型信息没有在整个块中保留。知道如何让第一件事发挥作用吗?第三个样式表在语义上做了我想要的,但我宁愿不要为了能够做到这一点而四处创建(几个)虚拟变量。
谢谢!