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

Re: calling template with name passed in a variable

Subject: Re: calling template with name passed in a variable
From: Wendell Piez <wapiez@xxxxxxxxxxxxxxxx>
Date: Mon, 21 Dec 2009 12:10:55 -0500
Re:  calling template with name passed in a variable
Hi Piotr,

At 11:12 AM 12/19/2009, you wrote:
Let's say someone needs to handle a new type some day. He asks me how to do this and then I would like to avoid having to explain how code that is concerned with matching and applying his new template works. He doesn't have to know this, he probably doesn't even care.

He doesn't need to know this if he doesn't need to code XSLT, true, but if he does, maybe he's better off knowing this. :-)

I wish I could just say add your template anywhere and name it the same as the type it handles. Wouldn't that be cleaner?

It would seem cleaner, yes. But it would only hide the dirt.

This example is not the best one to illustrate the above situation because matching in this case is really simple but we could imagine much more complex matching logic involving many templates not just one.

Those of us who have done it (and yes, these techniques have been tried) know that template matching scales very well. It's also, for reasons explained earlier, more robust.

So far the best argument you have given for not using the mechanism proposed is "it's confusing to people who don't know the language and can't be bothered to learn it". I admit this is sometimes a problem, but I'm not sure it's a problem with XSLT.

As my output is a source code I prefer fatal errors to producing invalid output.

There are certainly ways to trap these errors besides generating a complile-time error in your XSLT. :-)

Note that the XSLT language is designed so that the processor knows
all possible call requests and all possible callable templates at
compile time.  It can do optimization and rewriting based on this
knowledge, which cannot be done if the call were dynamically resolved.

In this case it looks like I would have to first generate new xsl based on the original xsl and then execute this new one.
For example having this definition in the original xsl (possibly added my someone else)

<xsl:template name="MyNewType1">
   code for THIS type

I would produce the following definition

<xsl:template match="xsd:element[@type='MyNewType1']">
   <xsl:call-template name="MyNewType1/>

This is a creative approach. But if it were me, I admit I would just document how they should write the actual XSLT (which isn't that different, I think), and hope that they would either do that correctly without complaint, or be inspired to learn enough about XSLT that they were content with it.

There is also the remote possibility that you get a user who actually knows enough XSLT to be suspicious about writing new templates that can't possibly be called from modules they haven't written....


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


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.
First Name
Last Name
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.