Xpath to return list of values

后端 未结 1 919
故里飘歌
故里飘歌 2021-01-25 13:05

I have the following XPATH /OMRequest/Record/Customer/PhoneList/Phone/text() which works well when there is only one Phone in PhoneList. H

1条回答
  •  野趣味
    野趣味 (楼主)
    2021-01-25 13:54

    Alone, /OMRequest/Record/Customer/PhoneList/Phone/text() will already select multiple such text nodes if they exist in the document.

    If you're only getting the first one, then you're likely passing the nodeset to another function, which is only operating on the first node of the nodeset (using XPath 1.0 terminology and constructs).

    For example, in XPath 1.0,

    string(/OMRequest/Record/Customer/PhoneList/Phone/text())
    

    only takes the string value of the first of the selected text nodes:

    7702958254
    

    Other functions, and other calls from hosting languages, can behave similarly.

    If you want to operate on all selected text nodes, in XPath 1.0 you'll have to iterate in the hosting language outside of XPath. XPath 2.0 has sequences rather than nodesets and has additional options for operating on sequences within XPath itself.

    0 讨论(0)
提交回复
热议问题