加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

xml – 带有fn前缀的XPath函数URL不起作用

发布时间:2020-12-16 22:51:15 所属栏目:百科 来源:网络整理
导读:以下XLST代码工作正常: – ?xml version="1.0"?xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0"xsl:template match="/" xsl:for-each select="bookstore/book" xsl:if test="starts-with(author,'W')" !-- Line 1 -- xsl:v
以下XLST代码工作正常: –

<?xml version="1.0"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" 
                version="1.0">
<xsl:template match="/">
    <xsl:for-each select="bookstore/book">
        <xsl:if test="starts-with(author,'W')">    <!-- Line 1 -->
            <xsl:value-of select="title" />
            &#160; by 
            <xsl:value-of select="author" />
            <br/>
        </xsl:if>
    </xsl:for-each>
</xsl:template>
</xsl:stylesheet>

在这里,我直接在第1行使用XPath String function start-with().

现在,根据W3Schools,添加XPath函数的命名空间(http://www.w3.org/2005/xpath-functions),以下代码不起作用: –

<?xml version="1.0"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" 
                xmlns:fn="http://www.w3.org/2005/xpath-functions" version="1.0">
<xsl:template match="/">
    <xsl:for-each select="bookstore/book">
        <xsl:if test="fn:starts-with(author,'W')">  <!-- Line 2 -->
            <xsl:value-of select="title" />
            &#160; by 
            <xsl:value-of select="author" />
            <br/>
        </xsl:if>
    </xsl:for-each>
</xsl:template>
</xsl:stylesheet>

在这里,我使用XPath函数,其前缀附加到命名空间.

IE显示“错误:命名空间’http://www.w3.org/2005/xpath-functions‘不包含任何功能”
我检查了URL,它确实有功能.

我哪里错了?如果我可以将所有XPath函数与Transform URL本身一起使用,那么为什么提供了一个单独的XPath函数URL?

解决方法

Now,as per W3Schools,adding the namespace for XPath functions
(http://www.w3.org/2005/xpath-functions),the following code does not
work :-

Here,I am using the XPath function with its prefix attached to the
namespace.

IE shows that “Error: Namespace
‘http://www.w3.org/2005/xpath-functions’ does not contain any
functions”

尽量避免“w3schools”.了解原因:http://w3fools.com/.

F&您尝试使用的O命名空间是在发布W3C XPath 1.0和XSLT 1.0建议多年后创建的.它只涉及XPath 2.0函数,XPath 1.0 / XSLT 1.0处理器不知道这个命名空间.

即使使用XPath 2.0 / XSLT 2.0,也没有必要使用命名空间 – 任何不带前缀的函数名都被认为是在这个命名空间中.

解:

只需不添加任何标准XPath函数的前缀.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读