下面的XSLT轉換會在我嘗試使用函數node-name()時顯示錯誤。xpath-functions不標識外部Java類
Error: E[Saxon6.5.5]The URI http://www.w3.org/2005/xpath-functions does not identify an external Java class
<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>
謝謝。這適用於該測試線。實際上,我想運行的代碼是遞歸地運行的代碼。我想要做的是過濾XML文件中的一些元素。 'elementsToBeFilterOut.xml'告訴我要讓什麼,最後我想改變它列出要排除的元素。 – 2012-07-25 14:15:43
非常感謝您的第二個提示。我去了我的oXygen的「配置轉換場景」,並將其改爲使用Xason 9引擎,現在確實通過了測試。 – 2012-07-25 15:19:37