Adding to this, my personal opinion is that try/catches should be a last
resort and you'll be a better programmer for avoiding them. Not to mention,
you can often see performance increases by avoiding them if the code is
something that is called repeatedly and are less likely to unintentionally
mask problems. For example you can do the following (please excuse the
formatting):
xquery version "3.0";
let $element := <el att1="one" att2="two" id="old-id">text</el>
return element new {
$element/attribute(),
if (fn:empty($element/@id)) then attribute id { "new-id" } else (),
$element/node()
}
On Thu, Dec 19, 2013 at 11:31 AM, Christian Grün
<[email protected]>wrote:
> 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
>
> _______________________________________________
> [email protected]
> http://x-query.com/mailman/listinfo/talk
>
_______________________________________________
[email protected]
http://x-query.com/mailman/listinfo/talk