撒克逊人抱怨功能未知,尽管功能可用

saxon complains about unknown function although function-available

我正在通过 xslt 转换一些东西,尝试在可用时使用 xalan 函数 document-location,否则避免使用它(可移植)。示例代码:

<xsl:transform xmlns:xsl="http://www.w3.org/1999/XSL/Transform"  version="1.0">
  <xsl:template match="/">
    <xsl:choose>
      <xsl:when test="function-available('document-location')">
        <xsl:message>YES document-location&#xa;</xsl:message>
        <xsl:message><xsl:value-of select="document-location()"/></xsl:message>
      </xsl:when>
      <xsl:otherwise>
        <xsl:message>NO document-location&#xa;</xsl:message>
      </xsl:otherwise>
    </xsl:choose>
  </xsl:template>
</xsl:transform>

撒克逊人报道

SAXON 6.5.5 from Michael Kay
Java version 1.7.0_151
Error at xsl:value-of on line 8 of file:minisax.xsl:
  Error in expression document-location(): Unknown system function: document-location
Transformation failed: Failed to compile stylesheet. 1 error detected.

虽然功能可用测试before.trying使用它。它似乎在 "control" 达到那个点之前尝试使用它。

它可以与 xalanj 一起正常工作(这很简单),也可以与 xsltproc 一起工作。

我怎样才能完成这项工作?

Edit/Backgroud

这是我的 Renderx XEP 评估附带的撒克逊版本,这使得编写可移植样式表以开箱即用变得困难。我知道这不是当前的撒克逊问题,因为版本太旧了。

我用当前版本的xsltproc测试了一下,结果是NO。发生这种情况的原因可能是 XSLT 中没有 document-location() 函数。

因此我猜您指的是 XSLT 2.0 及更高版本中可用的 document-uri() 函数。

因此,如果您将 XSLT 更改为

<xsl:transform xmlns:xsl="http://www.w3.org/1999/XSL/Transform"  version="2.0">
  <xsl:template match="/">
    <xsl:choose>
      <xsl:when test="function-available('document-uri')">
        <xsl:message>YES document-location&#xa;</xsl:message>
        <xsl:message><xsl:value-of select="document-uri()"/></xsl:message>
      </xsl:when>
      <xsl:otherwise>
        <xsl:message>NO document-location&#xa;</xsl:message>
      </xsl:otherwise>
    </xsl:choose>
  </xsl:template>
</xsl:transform>

您将从 Saxon 和当前 XML 文档的路径获得肯定的 'YES' 结果。

P.S.:你的撒克逊版本很古老。

Saxon 6.5.5 是一个非常古老的版本,我建议您转向更现代的版本。样式表在 Saxon 9.9 中似乎按预期工作。

我不打算研究 Saxon 6.5.5 源代码,但一种可能性是它假设规范不允许您将函数添加到默认(系统定义的)函数命名空间,因此它可以静态地假设它知道该命名空间中存在哪些函数。 Xalan 通过向系统命名空间添加非标准函数显然打破了这条规则,而 Saxon 并没有考虑到这一点。