2012-04-08 60 views
3

为了使用xpath-functions(特别是fn部分),我包括各个命名空间到我的XSLT样式表,像这样:如何在XSLT 2.0中使用xpath-functions?

<xsl:stylesheet 
    version="2.0" 
    xmlns="http://www.w3.org/1999/xhtml" 
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform" 
    xmlns:fn="http://www.w3.org/2005/xpath-functions" 
> 

specified由W3C。

然而,当我使用fn:document-uri,我的XSLT引擎告诉我,我叫一个未知函数/扩展:

<xsl:variable name="uri" select="fn:document-uri()" /> 

歌剧院说:

This document had an invalid XSLT stylesheet. Error message from the XSLT engine:
Error: XPath expression compilation failed: fn:document-uri()
Details: compilation error (characters 1-17, "fn:document-uri()"): unknown function called: '{ http://www.w3.org/2005/xpath-functions , document-uri }'

火狐说:

Error during XSLT transformation: An unknown XPath extension function was called.

由于xslt 2.0,

xsltproc拒绝转换。

那么,如何正确指定fn命名空间呢?

+0

位掩码有用,没我的回答提供的信息你后,还是你仍然有问题,对此有何看法? – 2012-04-11 02:45:03

+0

@DimitreNovatchev:技术上你有,但一个解决方法会很好(虽然我不认为这是可能的)。这就是为什么我把这个问题延长了一段时间。 – bitmask 2012-04-11 08:06:35

+0

我明确表示符合*的* XSLT 1.0处理器*不能*实现XPath 2.0函数。这很明显意味着没有“解决方法” - 如果在XSLT中需要XPath 2.0,那么它们必须使用XSLT 2.0(或更高版本)处理器。 – 2012-04-11 11:39:11

回答

4

问题是您正在使用XSLT 1.0处理器,并且XSLT 1.0处理器不知道(并且一定不知道)有关XPath 2.0函数的任何内容。

如果您使用真正的XSLT 2.0处理器,您甚至不必指定函数名称空间 - 它是任何前缀函数名称的默认名称空间。

例如,该XSLT 2.0转化

<xsl:stylesheet version="2.0" 
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> 
<xsl:output method="text"/> 

<xsl:template match="/"> 
    <xsl:sequence select="document-uri(.)" /> 
    <xsl:text>&#xA;</xsl:text> 
    <xsl:sequence select="document-uri(document(''))" /> 
</xsl:template> 
</xsl:stylesheet> 

当与撒克逊9.1.5的XSelerator下执行时,产生源XML文档的正确的URL和样式表本身

file:/C:/Program%20Files/Java/jre6/bin/marrowtr.xml 
file:/C:/Program%20Files/Java/jre6/bin/marrowtr.xsl 
-3

您可以使用XPath函数在PHP 请参考以下链接 http://php.net/manual/en/simplexmlelement.xpath.php 我觉得这个例子给你

+3

这个问题是关于在XSLT样式表中调用XPath 2.0函数,而不是关于评估XPath表达式的PHP函数。 – 2013-01-18 10:08:03