Thanks Martin. Below is the modified query with the namespace specification and usage. It works but is cumbersome.
Is there a way simpler way around this - other than modifying the input header to remove the namespace declaration?
Thanks, Ron
declare namespace xs="http://www.drugbank.ca";
for $drug in db:open('DrugBankFail')/xs:drugbank/xs:drug where not(empty($drug/xs:atc-codes/xs:atc-code)) return <drug> { <ATC5> { string-join(distinct-values($drug/xs:name), ' | ') } </ATC5>, <ATC4> { string-join(distinct-values(for $level in $drug/xs:atc-codes/xs:atc-code/xs:level return if (fn:string-length($level/@code) = 5) then $level/text() else ()), ' | ') } </ATC4>, <ATC3> { string-join(distinct-values(for $level in $drug/xs:atc-codes/xs:atc-code/xs:level return if (fn:string-length($level/@code) = 4) then $level/text() else ()), ' | ') } </ATC3>, <ATC2> { string-join(distinct-values(for $level in $drug/xs:atc-codes/xs:atc-code/xs:level return if (fn:string-length($level/@code) = 3) then $level/text() else ()), ' | ') } </ATC2>, <ATC1> { string-join(distinct-values(for $level in $drug/xs:atc-codes/xs:atc-code/xs:level return if (fn:string-length($level/@code) = 1) then $level/text() else ()), ' | ') } </ATC1> } </drug>
On September 1, 2017 at 12:48:21 PM, Martin Honnen (martin.honnen@gmx.de) wrote:
On 01.09.2017 18:03, Ron Katriel wrote:
The attached 4 files that should let you reproduce the issue. The XML files are the minimal imports (fail, work) and the XQ files are the queries (fail, work). Below is the output from the query that works. The one that fails returns nothing.
It appears to be the usual problem of dealing with a default namespace in the input XML, your path drugbank/drug would select elements in no namespace unless you set up a default element namespace (which however with XQuery would also change the namespace of the result elements) or declare a prefix in your query for the input XML namespace and use that or as a third option use a wildcard *:drugbank/*:drug.