Kendall/Alex,
Adding the default namespace solved the issue (see the modified query below).
The output indeed has the namespace
<drug xmlns="http://www.drugbank.ca"> <ATC5>Lepirudin</ATC5> <ATC4>Direct thrombin inhibitors</ATC4> <ATC3>ANTITHROMBOTIC AGENTS</ATC3> <ATC2>ANTITHROMBOTIC AGENTS</ATC2> <ATC1>BLOOD AND BLOOD FORMING ORGANS</ATC1> </drug>
However, this is not a problem for me as I serialize it into tab-separated format.
So I am good now.
Thanks! Ron
declare default element namespace "http://www.drugbank.ca";
for $drug in db:open('DrugBankFail')/drugbank/drug where not(empty($drug/atc-codes/atc-code)) return <drug> { <ATC5> { string-join(distinct-values($drug/name), ' | ') } </ATC5>, <ATC4> { string-join(distinct-values($drug/atc-codes/atc-code/level[string-length(@code) = 5]), ' | ') } </ATC4>, <ATC3> { string-join(distinct-values($drug/atc-codes/atc-code/level[string-length(@code) = 4]), ' | ') } </ATC3>, <ATC2> { string-join(distinct-values($drug/atc-codes/atc-code/level[string-length(@code) = 3]), ' | ') } </ATC2>, <ATC1> { string-join(distinct-values($drug/atc-codes/atc-code/level[string-length(@code) = 1]), ' | ') } </ATC1> } </drug>
On September 1, 2017 at 5:07:35 PM, Kendall Shaw (kendall.shaw@workday.com) wrote:
On 9/1/17, 1:04 PM, "basex-talk-bounces@mailman.uni-konstanz.de on behalf of Martin Honnen" <basex-talk-bounces@mailman.uni-konstanz.de on behalf of martin.honnen@gmx.de> wrote:
On 01.09.2017 22:01, Alexander Holupirek wrote:
On 1. Sep 2017, at 19:41, Ron Katriel rkatriel@mdsol.com wrote: Is there a way simpler way around this - other than modifying the input header to remove the namespace declaration?
declaring a default element in your XQuery might help?
declare default element namespace "https://urldefense.proofpoint.com/v2/url?u=http-3A__www.drugbank.ca&d=DwICaQ&c=DS6PUFBBr_KiLo7Sjt3ljp5jaW5k2i9ijVXllEdOozc&r=JgwnBEpN1c-DDmq-Up2QMq9rrGyfWK0KtSpT7dxRglA&m=txjXxCSiNw_iW8D4o67JHNWxnyvM5vySI1NZIbu5_aI&s=53cXA-gr8txDllT9Vth7fcG5TfJLR7SbBp_PXu-POYg&e= "; for $drug in doc('drugbank.Lepirudin.ATC.fail.xml')/drugbank/drug where not(empty($drug/atc-codes/atc-code)) return <drug> {
But that would also put the result elements into that namespace, not sure whether that is wanted.
If all of the documents are similar and there is enough code to justify the effort of pre-processing the documents to change the default namespace to no namespace, you could do that:
declare namespace e = "https://urldefense.proofpoint.com/v2/url?u=http-3A__example.com&d=DwIGaQ... ";
declare function e:strip-namespaces($node as node()) as node() { typeswitch ($node) case $node as document-node() return document { $node/node()/e:strip-namespaces(). } case $node as element() return element {local-name($node)} { $node/@*, $node/node()/e:strip-namespaces(). } default return $node };
for $drug in e:strip-namespaces(db:open('DrugBankFail'))/drugbank/drug where not(empty($drug/atc-codes/atc-code)) return <drug> { <ATC5> { string-join(distinct-values($drug/name), ' | ') } </ATC5>, <ATC4> { string-join(distinct-values(for $level in $drug/atc-codes/atc-code/level return if (fn:string-length($level/@code) = 5) then $level/text() else ()), ' | ') } </ATC4>, <ATC3> { string-join(distinct-values(for $level in $drug/atc-codes/atc-code/level return if (fn:string-length($level/@code) = 4) then $level/text() else ()), ' | ') } </ATC3>, <ATC2> { string-join(distinct-values(for $level in $drug/atc-codes/atc-code/level return if (fn:string-length($level/@code) = 3) then $level/text() else ()), ' | ') } </ATC2>, <ATC1> { string-join(distinct-values(for $level in $drug/atc-codes/atc-code/level return if (fn:string-length($level/@code) = 1) then $level/text() else ()), ' | ') } </ATC1> } </drug>