[xquery-talk] XHTML namespace and doc() function

David Sewell dsewell at virginia.edu
Wed Jul 7 17:20:25 PDT 2004

I've just been wrestling with a problem that it turns out was discussed
last year on this list, in a brainteaser posted by Jason Hunter:


The basic issue is that we want to generate valid XHTML with XQuery code
that makes use of doc() to retrieve things. So we started out trying
something like this:

	default element namespace = "http://www.w3.org/1999/xhtml"

	 { doc("DPM0029.xml")//body//p }

and discovered the problem that the doc() function here returns null
because it is looking in the XHTML namespace instead of for a local URI,
as someone else pointed out in answer to the brainteaser.

Nobody suggested what the best workaround is, however. Of course we
could omit the XHTML namespace reference and output a bare <html> element,
but let's say we want to be W3C-correct and include it. Are we always
going to have to "shield" doc() calls by putting them in variables
and/or functions external to the element constructors? Is there another
technique? (If not, do other navigation functions like id() have similar

Thanks for helping a newbie,

David S.

David Sewell, Editorial and Technical Manager
Electronic Imprint, The University of Virginia Press
PO Box 400318, Charlottesville, VA 22904-4318 USA
Courier: 310 Old Ivy Way, Suite 302, Charlottesville VA 22903
Email: dsewell at virginia.edu   Tel: +1 434 924 9973
Web: http://www.ei.virginia.edu/

More information about the talk mailing list