OASIS Mailing List ArchivesView the OASIS mailing list archive below
or browse/search using MarkMail.

 


Help: OASIS Mailing Lists Help | MarkMail Help

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [xml-dev] RE: Namespaces Best Practice



Paul Spencer wrote:
> I'm late coming to this thread, but am I the only one to disagree with
point
> 1? (I agree totally with 2.)

This is a bit of a struggle for me too. One analogy would be the programming
practice that says "declare variables where you use them." Why have a
namespace declaration at the top of the document, when you're only using
that namespace at one isolated element in the middle of the document?

More significant than an analogy with programming practice is how XPath and
XSLT model namespaces. For every in-scope namespace binding at a given
element, there is a namespace node. This has two immediate practical
implications: 1) performance may degrade as the number of namespace nodes
proliferates, and 2) any copy of that element into the result tree will
include all of its namespace nodes.

I personally am more concerned with #2. More than once have I resorted to
writing the following:

<xsl:template match="/">
  <xsl:apply-templates select="foo/bar"/>
</xsl:template>

<xsl:template match="*">
  <xsl:element name="{name()}" namespace="{namespace-uri()}">
    <xsl:apply-templates select="node()|@*"/>
  </xsl:element>
</xsl:template>

<xsl:template match="@*|text()|comment()|processing-instruction()">
  <xsl:copy/>
</xsl:template>


...when the only reason I didn't just write <xsl:copy-of select="foo/bar"/>
is because I didn't want to include all of the extraneous namespace
declarations in my output.

Perhaps this is a way of forcing me into a good XSLT practice (always using
template rules), but I admit that when I've had control over the source
document, I've sometimes taken the simpler approach of moving namespace
declarations away from the root element and down to the point where they are
actually needed.

Evan Lenz
XYZFind Corp.