最近,我升级了服务器,以下使用Saxonb的XSLT停止工作:
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
exclude-result-prefixes="#all"
version="3.0">
<xsl:output cdata-section-elements="title"/>
<xsl:mode on-no-match="shallow-copy"/>
<xsl:template match="title[ends-with(., 'Apple') or ends-with(., 'Samsung') or ends-with(., 'Banana')]">
<xsl:copy>
<xsl:value-of select="let $words := tokenize(., '\s+')
return (subsequence($words, 1, count($words) - 2), $words[last()], $words[last() - 1])"/>
</xsl:copy>
</xsl:template>
</xsl:stylesheet>我得到了错误:
XPST0003: XPath syntax error at char 0 on line 13 in {let $}:
'let' is not supported in XPath我还没有升级saxonb(Saxon9.1.0.8J来自Saxonica)。有人知道为什么它不能正常工作吗?
发布于 2021-12-01 22:48:36
您可以通过重写模板以使用XSLT let语句而不是XPath 3.0 let语句来绕过对let和任何相关版本或许可复杂性的需求:
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
exclude-result-prefixes="#all"
version="2.0">
<xsl:output cdata-section-elements="title"/>
<xsl:template match="@*|node()">
<xsl:copy>
<xsl:apply-templates select="@*|node()"/>
</xsl:copy>
</xsl:template>
<xsl:template match="title[ ends-with(., 'Apple')
or ends-with(., 'Samsung')
or ends-with(., 'Banana')]">
<xsl:variable name="words" select="tokenize(., '\s+')"/>
<xsl:copy>
<xsl:value-of select="subsequence($words, 1, count($words) - 2),
$words[last()],
$words[last() - 1]"/>
</xsl:copy>
</xsl:template>
</xsl:stylesheet>更新:--我已经用传统的身份转换取代了<xsl:mode on-no-match="shallow-copy"/>,以全面减少从XSLT3.0到XSLT2.0的依赖性。感谢@michael.hor257k的建议。
发布于 2021-12-01 22:58:35
你提到了撒克逊的9.1.0.8J。这是一个非常古老的版本(实际上是2009年),它永远无法运行这个样式表。
我担心,不知怎么的,你的“升级”让你运行了一个更老的撒克逊版本。
目前的版本是10.6。
发布于 2021-12-01 22:01:19
我认为,let绑定是XPath 3的一部分,因为XSLT3.0在Saxon9.8HE之前并不完全支持它,因为这是第一个使用XPath 3建议支持最终XSLT3.0的XPath开源版本。您可能会发现,使用version="3.0"和使用let的XPath 3表达式也可以在9.7和9.6中工作,但在更早的版本(至少是开源版本)中,Saxon是一个具有XPath 2.0支持的XSLT2.0处理器,不支持任何XPath 3表达式(比如let)。
文字错误消息'let' is not supported in XPath可能暗示该版本对XQuery中的let有一些支持,但我不记得细节,也没有检查过。
目前还不清楚您在升级之前使用了哪个版本的Saxon,在升级之后使用了哪个版本,或者您做了什么样的“更新”。
https://stackoverflow.com/questions/70190608
复制相似问题