On 01.09.2017 19:41, Ron Katriel wrote:
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?
I don't think you can avoid the namespace declaration,
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>,
I would shorten lines like the above to e.g.
<ATC4> {
string-join(distinct-values($drug/xs:atc-codes/xs:atc-code/xs:level[string-length(@code)
= 5]), ' | ') } </ATC4>