我正在嘗試列印不在data:fruit. 就我而言,我期望Pineapple, Kiwi. 我正在訪問data:fruitXSLT xml 配置中的'select="document('')/*/data:fruit/attribute/@value"'. 目前我收到以下錯誤。
錯誤:
在第 24 行執行 XSLT 時出錯:URIResolver 決議“針對”時拋出的例外。原子化 fn:string-join() 的第一個引數時發現
請檢查以下 xsltfiddle 鏈接: https ://xsltfiddle.liberty-development.net/jyfAiC7/4
xsl
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:exsl="http://exslt.org/common"
xmlns:set="http://exslt.org/sets"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
extension-element-prefixes="exsl"
version="2.0">
<xsl:output method="xml" indent="yes" encoding="UTF-8"/>
<data:fruit>
<attribute value="Pineapple" />
<attribute value="Kiwi" />
<attribute value="Apple" />
<attribute value="Orange" />
<attribute value="Banana" />
<attribute value="Cherry" />
<attribute value="Peach" />
</data:fruit>
<xsl:template match="/">
<xsl:variable name="fruitMissing">
<xsl:for-each select="document('')/*/data:fruit/attribute/@value">
<xsl:variable name="fruit" select="."/>
<xsl:if test="count(//root/details/item/line[contains(.,$fruit)])=0"><xsl:value-of select="."/>,</xsl:if>
</xsl:for-each>
</xsl:variable>
<xsl:value-of select="$fruitMissing"/>
</xsl:template>
</xsl:stylesheet>
xml
<?xml version="1.0" encoding="ISO-8859-1"?>
<root>
<header/>
<details>
<item>
<line>14.04.22 5:04:30;Apple;Finished</line>
</item>
<item>
<line>14.04.22 3:36:42;Apple;Finished</line>
</item>
<item>
<line>14.04.22 4:03:47;Orange;Finished</line>
</item>
<item>
<line>14.04.22 2:40:33;Orange;Finished</line>
</item>
<item>
<line>14.04.22 3:37:12;Banana;Finished</line>
</item>
<item>
<line>14.04.22 3:36:59;Cherry;Finished</line>
</item>
<item>
<line>14.04.22 3:36:57;Peach;Finished</line>
</item>
</details>
<summary/>
<statistics/>
<exceptions/>
</root>
uj5u.com熱心網友回復:
我建議你這樣做:
XSLT 2.0
<xsl:stylesheet version="2.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="text" encoding="UTF-8"/>
<xsl:key name="existing-fruit" match="item" use="tokenize(line, ';')[2]" />
<xsl:variable name="fruit">
<attribute value="Pineapple" />
<attribute value="Kiwi" />
<attribute value="Apple" />
<attribute value="Orange" />
<attribute value="Banana" />
<attribute value="Cherry" />
<attribute value="Peach" />
</xsl:variable>
<xsl:template match="/" >
<xsl:variable name="xml" select="." />
<xsl:value-of select="$fruit/attribute[not(key('existing-fruit', @value, $xml))]/@value" separator=","/>
</xsl:template>
</xsl:stylesheet>
除了更短、更高效之外,它還避免了對line.
演示:https ://xsltfiddle.liberty-development.net/jyfAiC7/5
uj5u.com熱心網友回復:
試試這個XSLT2:
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:exsl="http://exslt.org/common"
xmlns:set="http://exslt.org/sets"
xmlns:data="http://mulocal/host"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
extension-element-prefixes="exsl"
version="2.0">
<xsl:output method="xml" indent="yes" encoding="UTF-8"/>
<data:fruit>
<attribute value="Pineapple" />
<attribute value="Kiwi" />
<attribute value="Apple" />
<attribute value="Orange" />
<attribute value="Banana" />
<attribute value="Cherry" />
<attribute value="Peach" />
</data:fruit>
<xsl:template match="/">
<xsl:variable name="varInput" select="root"/>
<xsl:for-each select="document('')/*/data:fruit/attribute/@value">
<xsl:variable name="fruit" select="."/>
<xsl:if test="count($varInput/details/item/line[contains(.,$fruit)])=0">
<xsl:value-of select="."/><xsl:text>,</xsl:text>
</xsl:if>
</xsl:for-each>
</xsl:template>
</xsl:stylesheet>
結果:
<?xml version="1.0" encoding="UTF-8"?>Pineapple,Kiwi,
轉載請註明出處,本文鏈接:https://www.uj5u.com/ruanti/471891.html
