在Saxon EE 11.4中使用format-time提取时区遇内部错误求助
在Saxon EE 11.4中使用format-time提取时区触发内部错误的解决办法
问题现象
使用format-time(current-time(), '[z]')提取当前时区时,程序崩溃并抛出错误:Internal error evaluating template rule at line X.,无法返回如GMT -07:00的预期结果。
出错代码:
<!-- 触发内部错误 --> <xsl:value-of select="format-time(current-time(), '[z]')" />
但其他时区相关函数均能正常返回偏移值(示例输出均为-PT7H):
<xsl:value-of select="implicit-timezone()" /> <xsl:value-of select="timezone-from-dateTime(current-dateTime())" /> <xsl:value-of select="timezone-from-date(current-date())" /> <xsl:value-of select="timezone-from-time(current-time())" />
临时解决方案
由于format-time的[z]格式符在Saxon 11.4中存在bug,可通过手动构造时区格式来替代:
<xsl:variable name="tz-offset" select="implicit-timezone()" /> <xsl:variable name="tz-hours" select="hours-from-duration($tz-offset)" /> <xsl:variable name="tz-mins" select="minutes-from-duration($tz-offset)" /> <xsl:value-of select="concat( 'GMT ', if ($tz-hours >= 0) then '+' else '', format-number($tz-hours, '00'), ':', format-number(abs($tz-mins), '00') )" />
这段代码会生成与[z]格式符预期一致的输出,例如GMT -07:00。
长期修复建议
该问题大概率是Saxon 11.4版本的已知缺陷,建议查看Saxon官方版本更新日志,升级至11.5及以上版本,此类内部错误通常会在后续版本中被修复。
内容的提问来源于stack exchange,提问作者Austin
相关产品推荐
相关产品推荐

