XML.orgXML.org
FOCUS AREAS |XML-DEV |XML.org DAILY NEWSLINK |REGISTRY |RESOURCES |ABOUT
OASIS Mailing List ArchivesView the OASIS mailing list archive below
or browse/search using MarkMail.

 


Help: OASIS Mailing Lists Help | MarkMail Help

[Date Prev] | [Thread Prev] | [Thread Next] | [Date Next] -- [Date Index] | [Thread Index]
Re: [xml-dev] RE: Namespace use cases

> * Pitfalls: whats in the default namespace ? should I use an attribute
> or element ? should I embed versioning or any kind of metadata within
> namespace URI ? I don't want to sound like an XML Namespace
> 'apologist' but doesn't every concept have its dark corners and
> nuances to trip up on ?

A common dark corner or nuance is XSLT is generating XHTML (or XForms etc):

<xsl:template match="/">
 <html xmlns="http://www.w3.org/1999/xhtml";>
   <xsl:apply-templates/>
 </html>
</xsl:template>

<xsl:template match="foo">
 <body>asdf</body>
</xsl:template>

generates

<html xmlns="http://www.w3.org/1999/xhtml";>
  <body xmlns="">asdf</body>
</html>

The <body> element is in no namespace, because the namespace is scoped
in the XML-document-that-is-the-stylesheet, not in the XSLT processor
itself, which is non-intuitive for most.

The solution is to ensure that the <body> element in the foo matching
template is in scope for the default namespace change, either by
adding another xmlns declaration, or by moving the the existing one up
to a common ancestor, so you end up with:

<xsl:template match="/">
 <html>
   <xsl:apply-templates/>
 </html>
</xsl:template>

<xsl:template match="foo">
 <body>asdf</body>
</xsl:template>

So no namespace in sight, the xmlns is defined higher up on
xsl:stylesheet).  So now to the unaware it seems you are generating
output in no namespace, but in fact all unprefixed elements are in the
correct namespace...

I can't see a way around this at the moment, just pointing it out as a
common problem...


--
Andrew Welch
http://andrewjwelch.com
Kernow: http://kernowforsaxon.sf.net/


[Date Prev] | [Thread Prev] | [Thread Next] | [Date Next] -- [Date Index] | [Thread Index]


News | XML in Industry | Calendar | XML Registry
Marketplace | Resources | MyXML.org | Sponsors | Privacy Statement

Copyright 1993-2007 XML.org. This site is hosted by OASIS