首页 > 解决方案 > 撒克逊人抱怨未知功能虽然功能可用

问题描述

我正在通过 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.

虽然之前的功能可用测试。尝试使用它。它似乎试图在“控制”达到这一点之前使用它。

它适用于 xalanj(这很容易),但也适用于 xsltproc。

我怎样才能使这项工作?

编辑/背景

那是我的 Renderx XEP 评估附带的 saxon 版本,因此很难编写可移植的样式表以开箱即用。我知道由于古老的版本,这不是当前的撒克逊问题。

标签: xslt-1.0saxonrenderx

解决方案


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

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


推荐阅读