[XML-DEV Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Re: RE: Namespaces Best Practice

  • From: Evan Lenz <elenz@x...>
  • To: Paul Spencer <paul.spencer@a...>,Jonathan Borden <jborden@m...>, xml-dev@l...
  • Date: Wed, 19 Sep 2001 09:47:57 -0700

best practice template
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.


PURCHASE STYLUS STUDIO ONLINE TODAY!

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.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
 

Stylus Studio has published XML-DEV in RSS and ATOM formats, enabling users to easily subcribe to the list from their preferred news reader application.


Stylus Studio Sponsored Links are added links designed to provide related and additional information to the visitors of this website. they were not included by the author in the initial post. To view the content without the Sponsor Links please click here.

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.