我有一个XML,如果Type_Reference / @ Descriptor的值为'Work',我需要从中检索Country_Reference / @ Descriptor的值
<ns1:CanonicalCustomerDetails xmlns:ns1="http://abracadabra.Notification/Schemas/v1.0" xmlns:ns0="urn:com.dodom/bsvc">
<Body>
<ns0:Get_Customers_Response ns0:version="">
<ns0:Response_Data>
<ns0:Customer>
<ns0:Customer_Data>
<ns0:Customer_ID>39</ns0:Customer_ID>
<ns0:Personal_Data>
<ns0:Contact_Data>
<ns0:Address_Data>
<ns0:Country_Reference ns0:Descriptor="United Kingdom"></ns0:Country_Reference>
<ns0:Address_Line_Data ns0:Descriptor="Address Line 1" ns0:Type="ADDRESS_LINE_1">8 Palio Street</ns0:Address_Line_Data>
<ns0:Postal_Code>12345</ns0:Postal_Code>
<ns0:Usage_Data>
<ns0:Type_Data ns0:Primary="1">
<ns0:Type_Reference ns0:Descriptor="Work" />
</ns0:Type_Data>
</ns0:Usage_Data>
</ns0:Address_Data>
<ns0:Address_Data>
<ns0:Country_Reference ns0:Descriptor="United States"></ns0:Country_Reference>
<ns0:Address_Line_Data ns0:Descriptor="Address Line 1" ns0:Type="ADDRESS_LINE_1">18 South Street</ns0:Address_Line_Data>
<ns0:Postal_Code>76543</ns0:Postal_Code>
<ns0:Usage_Data>
<ns0:Type_Data ns0:Primary="1">
<ns0:Type_Reference ns0:Descriptor="Home" />
</ns0:Type_Data>
</ns0:Usage_Data>
</ns0:Address_Data>
</ns0:Contact_Data>
</ns0:Personal_Data>
</ns0:Customer_Data>
</ns0:Customer>
</ns0:Response_Data>
</ns0:Get_Customers_Response>
</Body>
</ns1:CanonicalCustomerDetails>
Address_Data节点可以重复。
答案 0 :(得分:0)
此xpath表达式:
//*[local-name()='Country_Reference']/following-sibling::*//*[local-name()='Type_Reference']/@*[.='Work']/ancestor::*/*[local-name()='Country_Reference']/@*
应选择
英国