Re: [xsl] Passing parameters to an indirectly called template after matching.

Subject: Re: [xsl] Passing parameters to an indirectly called template after matching.
From: Abel Braaksma <abel.online@xxxxxxxxx>
Date: Thu, 17 Apr 2008 13:54:04 +0200
Kannan wrote:
Can I pass parameters like this.

Calling_Point => A_Named_Template, do apply-templates => {One or more
matching Templates } => A_Named_Template.

I tried to do this by passing parameters along with apply-templates,
and then passing it again from all matched templates to a named
template where I finally need it, it ended up in infinite loop. When I
just taken out the parameter passing and used global variables it
worked fine.

That you turned into an infinite loop has to do with a bug in your programming logic, not the passing itself. And probably you mean that the recursion went too deeply nested (but this may feel like a "loop"). In XSLT 1.0, the method of programming is certainly viable. But as soon as a new step is required between one and another template, you must remember to pass on the parameters again (which can become a maintenance nightmare)


What you are after is what Michael Kay suggested: the XSLT 2.0 feature of tunneling parameters which can be defined once and will be passed on until it matches a template that defines these parameters (where you must also specify that they are tunneled).

If you have to stick to XSLT 1.0, using global parameters may be the easiest way to go. If you want to modularize or "hide" the variables, you can use an imported stylesheet which defines its own "global" parameters (variables).

Cheers,
-- Abel Braaksma

Current Thread