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

Re: apply-templates and predicates

Subject: Re: apply-templates and predicates
From: David Carlisle <davidc@xxxxxxxxx>
Date: Thu, 28 Apr 2005 10:45:05 +0100
Re:  apply-templates and predicates
  It also increases the chances that the stylesheet will do something unwanted 
  when the schema changes

Not necessarily.

As I've mentioned earlier in this thread I almost always start off with
a template
<xsl:template match="*">
  <xsl:message>unexpected element ...</xsl:message>
<xsl:template>

when I think I have finished and added sufficient templates that 
<xsl:apply-templates/>
generates no more warning messages, then if the input changes on me and
new elements are added the stylesheet doesn't just silently accept the
input, it starts warning again. This mechanism is flexible in that
depending on the context it can be modified  to make the warnings fatal
errors, or no warnings at all, depending on circumstances.

If on the other hand instead of <xsl:apply-templates/> I just have
<xsl:apply-templates select="A|b[@foo]|C/>
because that's the only type of element that I expect to see, and I only
have templates for those elements, then if the schema changes and the
input has new elements, they will be silently ignored.

Similarly if instead of <xsl:apply-templates/> I just have
<xsl:apply-templates select="*[not(self::F)]/>
Because I believed that the only element type that I didn't need to
handle was F, and I didn't want to write an empty template for F, then
if the schema changes and  a new element type appears this will be
handled by the default template (whatever that does) without warning.

It's not a clear cut choice: most stylesheets use both forms to some
extent, but I think that it is definitely the case that in the face of
under specified or changing input, keeping select attributes simple and
putting more logic into the match templates is usually preferable.

David

________________________________________________________________________
This e-mail has been scanned for all viruses by Star. The
service is powered by MessageLabs. For more information on a proactive
anti-virus service working around the clock, around the globe, visit:
http://www.star.net.uk
________________________________________________________________________

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.