xmlxpathxqueryexist-dbopenehr

XPath-Query with wildcard not working


It is driving me crazy.

Can someone tell me why this query does not work:

xquery version "3.0";
for $item in collection("openkernel/openehr_ehr/archetyped/")
let $uid:=$item//uid/value
where $uid="51160740-171e-487c-a04d-eae267f7079a"
return $item

Must be something stupid, I know. The double slash before //uid/value is because I want to use the query generic

The XML-document I am trying to find resides in this collection, and is this:

<openehr-ehr_rm-Composition.composition.v1 xmlns="http://rosa.openkernel/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://rosa.openkernel/ file:/openehr-ehr_rm-Composition.composition.v1.xsd">
<Composition archetype_id="openehr-ehr_rm-Composition.composition.v1">
    <archetype_id>
        <value>openehr-ehr_rm-Composition.composition.v1</value>
    </archetype_id>
    <category>
        <defining_code>
            <code_string>431</code_string>
            <terminology_id>
                <value>openehr</value>
            </terminology_id>
        </defining_code>
        <value>persistent</value>
    </category>
    <something>a composition</something>
    <uid>
        <value>0e15d0f2-0b59-4df7-88f8-27be87e1e2ac</value>
    </uid>
    <content archetype_id="openehr-ehr_rm-ADMIN_ENTRY.admin_entry.v1" archetype_node_id="at0002">
        <archetype_id>
            <value>openehr-ehr_rm-ADMIN_ENTRY.admin_entry.v1</value>
        </archetype_id>
        <an_item>nono</an_item>
        <an_other_item>an_other_item</an_other_item>
        <something>an admin_entry</something>
        <uid>
            <value>51160740-171e-487c-a04d-eae267f7079a</value>
        </uid>
    </content>
</Composition>
</openehr-ehr_rm-Composition.composition.v1>

Thanks, very much Bert


Solution

  • You need to take the namespace into account, see http://www.w3.org/TR/xquery/#id-default-namespace:

    declare default element namespace "http://rosa.openkernel/";