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?
>
> ```xquery
> 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&c=fi2D4-9xMzmjyjREwHYlAw&r=44jDQvzmnB_-ovfO6Iusj0ItciJrcWMOQQwd2peEBBE&m=YSzbfFL7VzDX4Li6Hx94Vo4zuzV75tcGCx9voTLtZkE&s=GSAT27ZXA2uk--ZZ1p4N_Cvrph3gKf2uqCsogwVfjq0&e= ";
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>