0
我的xml如下所示。重點是在第三級:<name>
,<address>
等。我想找到父母<customer>
的位置。使用計數來獲取父節點位置的xPath
我使用「count(../preceding-sibling::*) + 1
」,但它在節點爲空時不返回計數。我該如何解決?謝謝。
<record>
<customer>
<name>Sue A</name> -- return 1
<address>123 Main St</address> -- return 1
<phone></phone> -- missing
<status>A</status> -- return 1
</customer>
<customer>
<name>John B</name> -- return 2
<address></address> -- missing
<phone>123-456-7890</phone> -- return 2
<status></status> -- missing
</customer>
…
</record>
請提供證明問題的[mcve]。您在評估XPath時忽略瞭如何建立當前節點。 – kjhughes