[xquery-talk] XQuery 3 try/catch and duplicate attributes

Christian Grün christian.gruen at gmail.com
Thu Dec 19 10:31:10 PST 2013


Hi David,

> […]
>   try {attribute id { "new-id" }} catch * {()},
> […]
>
> but it doesn't trap the error (in any XQuery 3 processor I've checked). The
> try/catch will work only if put around the entire element constructor.

The reason for this is that the attribute constructor itself is
correct. The error occurs when trying to add the newly created
attribute to the element.

The following query should work:

let $element := <el att1="one" att2="two" id="old-id">text</el>
return element new {
  $element/attribute(),
  if($element/@id) then () else attribute id { "new-id" },
  $element/node()
}

Hope this helps,
Christian



More information about the talk mailing list