我需要能夠跟蹤文檔中任何特定值的位置。我會使用XSL,但是我正在使用的生態系統可以防止這種情況發生。我正在使用Java Saxon-HE 9.7.0-2處理器。屬性不匹配時返回空字符串屬性匹配時返回文本
XML
<test>
<value cat="fiction">At the edge of the orchard</value>
<value cat="mythology">Hero with a thousand faces</value>
<value cat="fiction">Spill simmer falter wither</value>
</test>
的XPath
for $a in /test
return
(if ($a/value[@cat="mythology"]) then
$a/value[@cat="mythology"] else
"")
我想看到什麼回來的是:
""
"Hero with a thousand faces"
""
什麼我目前看到的是:
"Hero with a thousand faces"
Link to videlibri xpath tester
謝謝;它更接近我所需要的,但現在我處於解析回報的位置。我得到這個XPath是:" " "英雄千面" " "解析是有風險的,我因爲在現實中是什麼在那個文本塊是不受約束的。如果我不能想出更好的東西,我仍然可能不得不採用這種解決方案。 – BDF