[xquery-talk] Default namespace best practices?

Michael Kay mhk at mhk.me.uk
Tue Mar 8 21:23:40 PST 2005

There are two factors to take into account:

(a) if you define a default element namespace, then you have no simple way
of referring to (or constructing) elements in the non-namespace.

(b) if you don't define a default element namespace, then the elements in
your result document will carry a namespace prefix. This probably means that
when you generate XHTML, it won't be valid against the XHTML DTD, which
requires that elements be unprefixed.

So, if your input is in the non-namespace and you want your output to be
unprefixed, you've got a problem. (This is why XSLT 2.0 decided to have
different default namespaces for the input and the output, but I digress...)

Michael Kay

> -----Original Message-----
> From: talk-bounces at xquery.com 
> [mailto:talk-bounces at xquery.com] On Behalf Of David Sewell
> Sent: 08 March 2005 18:59
> To: talk at xquery.com
> Subject: [xquery-talk] Default namespace best practices?
> A question for people using XQuery to produce XHTML output directly.
> Do you declare the XHTML namespace as your query default, i.e.
>   declare default element namespace "http://www.w3.org/1999/xhtml";
> or do you instead use as the default namespace the primary namespace
> used by your data?
> I realize that from one point of view it's an arbitrary decision, but
> the choice has implications for readability and 
> maintainability of code
> in some cases. Also, if the XML documents you're working with 
> are in no
> namespace, declaring the XHTML namespace as the default means that you
> have no way to address them in path expressions inside element
> constructors without using wildcard namespace prefixes:
>    <p>{ data($mydoc/*:text/*:body/*:title) }</p>
> Any thoughts on pros and cons will be appreciated,
> David
> -- 
> 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/
> _______________________________________________
> talk at xquery.com
> http://xquery.com/mailman/listinfo/talk

More information about the talk mailing list