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

David Sewell dsewell at virginia.edu
Thu Dec 19 10:21:08 PST 2013

I'm trying to clean up some old code of ours that is throwing server errors when 
fed buggy data. To simplify greatly, the code is something like this:

let $element := <el att1="one" att2="two">text</el>
return element new {
   attribute id { "new-id" },

where the content of $element comes from XML data where <el> is not supposed to 
carry an @id attribute. Of course if the data is buggy and $element has a child 
@id, the above code throws a dynamic error (XQDY0025, duplicate attribute 

I naively thought this might be a quick fix to prevent runtime errors:

xquery version "3.0";
let $element := <el att1="one" att2="two" id="old-id">text</el>
return element new {
   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.

Can someone who understands the 3.0 spec better than I do explain the general 
principle behind this? Is it that the processor cannot be expected to evaluate 
the legality of the constructed element until all its parts have been assembled?


David Sewell, Editorial and Technical Manager
ROTUNDA, The University of Virginia Press
PO Box 400314, Charlottesville, VA 22904-4314 USA
Email: dsewell at virginia.edu   Tel: +1 434 924 9973
Web: http://rotunda.upress.virginia.edu/

More information about the talk mailing list