[XQuery Talk Mailing List Archive Home] [By Date] [By Thread] [By Subject] [By Author] [Recent Entries] [Reply To This Message]

Default namespace best practices?

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

namespace best practices
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 <http://xquery.com/mailman/listinfo/talk>:

> 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: http://xquery.com/mailman/listinfo/talk
> > [mailto:http://xquery.com/mailman/listinfo/talk] On Behalf Of David Sewell
> > Sent: 08 March 2005 18:59
> > To: http://xquery.com/mailman/listinfo/talk
> > Subject:  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: http://xquery.com/mailman/listinfo/talk   Tel: +1 434 924 9973
> > Web: http://www.ei.virginia.edu/
> > _______________________________________________
> > http://xquery.com/mailman/listinfo/talk
> > http://xquery.com/mailman/listinfo/talk
> >
> _______________________________________________
> http://xquery.com/mailman/listinfo/talk
> http://xquery.com/mailman/listinfo/talk

R. Mark Volkmann
Partner, Object Computing, Inc.


Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
First Name
Last Name
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.