<?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" />
  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" />
  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函数的前缀.
