1

suppose we have the following XML document:

<visits>
<folder>
    <consultation date="2015-07-01" doctor="d4"> ... </consultation>
    <consultation date="2016-05-02" doctor="d1"> ... </consultation>
    <consultation date="2020-01-01" doctor="d3"> ... </consultation>
    <consultation date="2021-12-02" doctor="d2"> ... </consultation>
    <patient id="p2">
        <name>aaaa</name>
        <phone>..</phone>
    </patient>
</folder>
<folder>
    <consultation date="2017-01-01" doctor="d2"> ... </consultation>
    <consultation date="2019-01-01" doctor="d4"> ... </consultation>
    <patient id="p1">
        <name>bbbbb</name>
        <phone>...</phone>
    </patient>
</folder>
<doctor id="d1">
    <speciality>gynecologist</speciality>
</doctor>
<doctor id="d2">
    <speciality>cardiologist</speciality>
</doctor>
<doctor id="d3">
    <speciality>gynecologist</speciality>
</doctor>
<doctor id="d4">
    <speciality>cardiologist</speciality>
</doctor>
in XPath 1.0, I want to get the patients who have seen doctors of all specialties.

Here is my attempt:

    //patient[count (../consultation[????]) =
    count(//doctor[not (speciality = preceding-sibling::doctor/speciality)])]

1 Answer 1

2

I do not know of any XPath-1.0 solution, but if you can use XPath-2.0, the following path does work:

/visits/folder[patient[every $x in /visits/doctor/@id satisfies $x=../consultation/@doctor]]

This expression selects all <folder> elements that match the required condition.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.