XPath的函数不能识别外部Java类(xpath-functions does not ident

2019-09-20 04:36发布

每当我尝试使用功能节点名()以下XSLT转换显示错误。

错误:E [Saxon6.5.5]的URI http://www.w3.org/2005/xpath-functions无法识别外部Java类

<xsl:stylesheet version="1.1" 
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    xmlns:xs="http://www.w3.org/2001/XMLSchema"
    xmlns:fn="http://www.w3.org/2005/xpath-functions">
<!--
<xsl:stylesheet version="1.0"
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
-->        

    <xsl:output method="text" />
    <xsl:variable name="in" select="/"/>
    <xsl:variable name="filter" select="document('elementsToBeLeftIn.xml')"/>

    <xsl:template match="/">
        <xsl:apply-templates select="*">
            <xsl:with-param name="f" select="$filter/*"/>
        </xsl:apply-templates>
    </xsl:template>

    <xsl:template match="*">
        <xsl:param name="f"/>
        <xsl:choose>
            <xsl:when test="$f/*">
                <xsl:copy-of select="fn:node-name()"/>

                <!--
                <xsl:for-each select="*[fn:node-name(.) = $f/*/fn:node-name(.)]">
                    <xsl:apply-templates select=".">
                        <xsl:with-param name="f" select="f/*[fn:node-name() = current()/fn:node-name()]"/>
                    </xsl:apply-templates>
                </xsl:for-each>
                -->
            </xsl:when>
            <xsl:otherwise>
                <xsl:copy-of select="."/>
            </xsl:otherwise>
        </xsl:choose>
    </xsl:template>

</xsl:stylesheet>    

谢谢大卫。 这是我真正想要做的工作 (这是递归的)。 使用name()我仍然获得错误*Unexpected tocken [<function>] in path expression*

在你之后

<xsl:stylesheet version="1.1" 
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    xmlns:xs="http://www.w3.org/2001/XMLSchema"
    xmlns:fn="http://www.w3.org/2005/xpath-functions">
<!--
<xsl:stylesheet version="1.0"
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
-->        

    <xsl:output method="text" />
    <xsl:variable name="in" select="/"/>
    <xsl:variable name="filter" select="document('elementsToBeLeftIn.xml')"/>

    <xsl:template match="/">
        <xsl:apply-templates select="*">
            <xsl:with-param name="f" select="$filter/*"/>
        </xsl:apply-templates>
    </xsl:template>

    <xsl:template match="*">
        <xsl:param name="f"/>
        <xsl:choose>
            <xsl:when test="$f/*">
                <xsl:for-each select="*[name() = $f/*/name()]">
                    <xsl:apply-templates select=".">
                        <xsl:with-param name="f" select="f/*[name() = current()/name()]"/>
                    </xsl:apply-templates>
                </xsl:for-each>
            </xsl:when>
            <xsl:otherwise>
                <xsl:copy-of select="."/>
            </xsl:otherwise>
        </xsl:choose>
    </xsl:template>

</xsl:stylesheet>    

Answer 1:

即使在XSLT2你永远不需要像前缀节点名称标准功能()。 但是,你正在使用撒克逊6是XSLT1,所以你一定不要前缀的功能,否则将不会被识别。 (1个XPath的标准功能都没有在命名空间)

只需使用select="name()"

不过,我不认为你希望你的代码就可以了(但你没有说你要它做什么),但将只适用模板一个元素(顶级文档元素)作为永远不会递归应用模板。

在该过滤器测试为真时<xsl:copy-of select="name()"将熄名称元素的,无标记(所以结果将不能很好地形成XML)。

在该过滤器测试为假的情况下,包括其所有子整个文档元素被复制到输出,并且没有进一步的处理发生。

$f/*/name()

是在XPath2合法的,但不是在XPath中1中,其中使用路径表达式/只可以使用节点不与返回字符串的函数结束。 不知道你想这样做不能提供一个立即更换什么。

 current()/name()

可以写成

 name(current())

XPath中1。

但由于使用的是撒克逊Java实现,为什么不直接使用撒克逊9,而不是撒克逊6和超过十年的价值在XSLT引擎进一步的发展中受益?



Answer 2:

撒克逊6.5.5是一个XSLT 1.0引擎。 命名空间http://www.w3.org/2005/xpath-functions为XPATH 2.0,XSLT 2.0和XSLT 3.0。 XSLT 1.0不承认这个命名空间。 这就是为什么你所得到的错误。

没有XSLT 1.0当量的http://www.w3.org/2005/xpath-functions 。 只需调用你的函数没有前缀。



文章来源: xpath-functions does not identify an external Java class
标签: xml xslt