2

I have syntax errors when exclude multiple nodes in element like "Sources" and "Navigators" nodes. But it works if I exclude only one node but not combine before returning the documents.

[(fn:local-name()  != ("Sources","Navigators")]

In Marklogic Qconsole:

  for $x in $uris
  let $doc := fn:doc($x)
  let $copymeta := <meta:Metadata> 
                    { $doc//meta:Metadata/*[(fn:local-name() != ("Sources","Navigators")] }
                   </meta:Metadata> 
  let $newxml := <omd:record>
                   { $copymeta }
                 </omd:record>
  return $newxml
grtjn
  • 20,254
  • 1
  • 24
  • 35
thichxai
  • 1,073
  • 1
  • 7
  • 16

2 Answers2

2

The != operator has unintuitive semantics. See this previous question. When the code finds a *:Sources node, it evaluates as != to "Navigators", and when it finds a *:Navigators node, it evaluates as != to "Sources". And then you get all the nodes.

If you aren't comparing node sequences (so except is not an option), then instead of !=, you can use fn:not(A = B) to get the intended effect. In this case, fn:not(fn:local-name() = ("Sources","Navigators")) should work as you expect.

BenW
  • 408
  • 2
  • 9
1

You have a open parenthesis too many in front of fn:local-name().

However, you could also make use of the except keyword, and a prefix wildcard. You would use it like this:

for $x in $uris
let $doc := fn:doc($x)
let $copymeta := <meta:Metadata> 
                   { $doc//meta:Metadata/(* except (*:Sources, *:Navigators)) }
                 </meta:Metadata> 
let $newxml := <omd:record>
                 { $copymeta }
               </omd:record>
return $newxml

HTH!

grtjn
  • 20,254
  • 1
  • 24
  • 35