基于另一个属性值条件的属性值

value of attribute based on value condition of another attribute

我有一个 XML,如果 Type_Reference/@Descriptor 的值为 'Work'[=11=,我需要从中检索 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节点可以重复。

这个 xpath 表达式:

//*[local-name()='Country_Reference']/following-sibling::*//*[local-name()='Type_Reference']/@*[.='Work']/ancestor::*/*[local-name()='Country_Reference']/@*

应该select

United Kingdom