最近我升級了我的服務器,以下帶有 Saxonb-XSLT 的 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-xslt(來自 Saxonica 的 Saxon 9.1.0.8J)。任何人都知道為什么它不能正常作業?
uj5u.com熱心網友回復:
您可以let通過重寫模板以使用 XSLTxsl:variable陳述句而不是 XPath 3.0let陳述句來繞過對任何相關版本或許可復雜性的需求:
<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"/>
為傳統的身份轉換,以完全減少從 XSLT 3.0 到 XSLT 2.0 的整體依賴性。感謝@michael.hor257k的建議。
uj5u.com熱心網友回復:
你提到了 Saxonica 的 Saxon 9.1.0.8J。這確實是一個非常舊的版本(2009 年),它永遠無法運行此樣式表。
我擔心,不知何故,您的“升級”讓您運行了較舊的撒克遜版本。
當前版本是 10.6。
uj5u.com熱心網友回復:
所述let的XPath 3的結合部分我想,因為它不完全在XSLT 3.0 9.8撒克遜之前支持HE因為這是第一撒克遜開源版本,以支持最終XSLT 3.0使用XPath 3建議。您可能會發現在 9.7 和 9.6中使用version="3.0"然后使用XPath 3 運算式let也可以作業,但在更舊的版本中,Saxon(至少是開源版本)是 XSLT 2.0 處理器,支持 XPath 2.0,不支持任何 XPath 3運算式(如let)。
文字錯誤訊息'let' is not supported in XPath可能表明該版本let在 XQuery 中有一些支持,但我不記得詳細資訊,也沒有檢查過。
目前尚不清楚您在升級之前使用了哪個版本的 Saxon,升級之后使用了哪個版本,或者您進行了什么樣的“更新”。
轉載請註明出處,本文鏈接:https://www.uj5u.com/gongcheng/373592.html
上一篇:SVG點按什么順序繪制?
下一篇:如何用字串替換縮寫?
