user641605
user641605

Reputation: 421

XPath to match multiple nodes depending on siblings child value

I am trying to select a file with Xpath . If the Xpath finds a matching value in:

(//Party/PartyIdentification/ID[text()="6655779999"]) OR (//Party/PartyTaxScheme/CompanyID[text()="US6655779999"] AND TaxScheme/ID = DEY) OR (//Party/PartyTaxScheme/CompanyID[text()="US6655779999"] AND TaxScheme/ID = BSY)

it selects the right file.

I started off using: //BuyerParty/Party/PartyIdentification/ID[text()="6655779999"] and it works perfect!

But I can't figure out how to extend the xpath to also check the other two paths with their DEY and BSY conditions. I spend weeks so far and turned the forum inside out to find an answer, but with no luck.

The reson for this OR condition is that one, two or all three of the elements might exist in the xml file. I never know which one prior. I need to get at least one match of the three matching criteria above to be sure to select the right file.

Any ideas on how to solve this?

<ROOT>
<BuyerParty>
    <Party>
        <PartyIdentification>
            <ID>6655779999</ID>
        </PartyIdentification>
        <PartyName>
            <Name>Charly</Name>
        </PartyName>
        <Address>
            <StreetName>El Cajon Boulevard</StreetName>
            <CityName>San Diego</CityName>
            <PostalZone>92104</PostalZone>
            <Country>
                <IdentificationCode>US</IdentificationCode>
            </Country>
        </Address>
        <PartyTaxScheme>
            <CompanyID>US11432112341</CompanyID>
            <TaxScheme>
                <ID>DEY</ID>
            </TaxScheme>
        </PartyTaxScheme>
        <PartyTaxScheme>
            <CompanyID>US1143211234</CompanyID>
            <TaxScheme>
                <ID>BSY</ID>
            </TaxScheme>
        </PartyTaxScheme>
        <Contact>
            <Telephone>555-5555555</Telephone>
        </Contact>
    </Party>
</BuyerParty>

Upvotes: 0

Views: 751

Answers (1)

Joel M. Lamsen
Joel M. Lamsen

Reputation: 7173

you can use the | (or) selector

//Party/PartyIdentification/ID[text()="6655779999"]|//Party/PartyTaxScheme/CompanyID[following-sibling::TaxScheme/ID = 'DEY' or following-sibling::TaxScheme/ID = 'BSY'][text()="US11432112341"]

Upvotes: 2

Related Questions