[xquery-talk] Default namespace best practices?

R. Mark Volkmann mark at ociweb.com
Tue Mar 8 17:26:29 PST 2005


What timing!  I almost deleted this email, but decided to save it for future
reference.  Two hours later I ran into this exact problem.  Some elements in my
input document aren't in a namespace.  I want my output document to contain
elements that are in a namespace, but I don't want them to be prefixed.

Apparently I can do that with XSLT, but not XQuery.  Unprefixed references to
elements within XPath expressions in my XSLT stylesheet are treated as
references to no namespace.  This allows me to refer to the elements in my
input document that aren't in a namespace.  However, in XQuery (using Saxon)
they are treated as references to the default element namespace.  I seem to be
forced to prefix my output elements so that the default element namespace can
remain set to "".

I can include example XML, XSLT and XQuery if anyone is interested.

Quoting Michael Kay <mhk at mhk.me.uk>:

> 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
> http://www.saxonica.com/
>
>
> > -----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
> >
>
>
> _______________________________________________
> talk at xquery.com
> http://xquery.com/mailman/listinfo/talk
>


--
R. Mark Volkmann
Partner, Object Computing, Inc.


More information about the talk mailing list