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

Re: Use of xsl:apply-templates exception with an eleme

Subject: Re: Use of xsl:apply-templates exception with an element
From: Wendell Piez <wapiez@xxxxxxxxxxxxxxxx>
Date: Mon, 28 Sep 2009 12:16:15 -0400
Re:  Use of xsl:apply-templates exception with an eleme
Hi,

In addition to what's been said, one can also probably say fairly that XSLT experts avoid name testing where possible? Why?

1. It is sometimes a source of obscure errors, for example when it's not namespace-safe and our documents have namespaces.

2. It's inelegant, especially compared to available alternatives.

3. It does what XPath is mostly designed to do without it -- XPath already does name testing in a namespace-safe way, without its being explicit -- and thereby deprives the processor of optimization opportunities.

All that having been said, there are corner cases (such as when names are not known in advance), and explicit testing on names may sometimes be allowed by an expert to be the best available solution on balance. (In my experience.)

<xsl:copy-of select="@*[not(node-name(.) = $new/@*/node-name(.))]"/>

... as here.


On the other hand, even here there may be available alternatives. For example -- since this case is hypothetical -- let's say we do this because we want to add to an element any attributes on the current node that would fail to be accounted for by $new since $new does not have an attribute by that name.

We could do:

<xsl:copy-of select="@*"/>
<xsl:copy-of select="$new/@*"/>

In other words, copy all the attributes, then copy the attributes on $new.

The attributes on $new will replace any attributes of the same name copied from the current node.

Again, no name testing is required.

And again, the example is entirely hypothetical.

Cheers,
Wendell



======================================================================
Wendell Piez                            mailto:wapiez@xxxxxxxxxxxxxxxx
Mulberry Technologies, Inc.                http://www.mulberrytech.com
17 West Jefferson Street                    Direct Phone: 301/315-9635
Suite 207                                          Phone: 301/315-9631
Rockville, MD  20850                                 Fax: 301/315-8285
----------------------------------------------------------------------
  Mulberry Technologies: A Consultancy Specializing in SGML and XML
======================================================================

Current Thread

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
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.