“apply-templates”
In XSL, one way to call a template, just like calling a function, is to use “apply-templates” keyword.
A variation of this is not to specify mode
, then anything that matches ‘product’ node will be processed in the second template.
By specifying mode
, this will allow you to pick and use the chosen template, just like calling a function with its signature.
It is all jolly good if that’s all you want to do. But you may want to pass some parameters to the second template, in order to archive more complicated tasks, just like a normal function call in other programming languages.
This is what got me scratch my head so hard that I start to hear squeaking noise. What’s more annoying is that it turns out to be simple, in XSL world.
A with-param
node is what I needed.
Despite the straight forward looking syntax, there are some catches:
tunnel
keyword is required to create a tunnel so that parameters can be passed through, more here
select
keyword takes an XPath expression and returns the resulting value as parameter, to use for a string input, ‘descending’, DO use single quotes for it to work
- use
$
to quote the parameter in the subsequent template
“call-template”
Another way to call a template is to use call-template
keyword as suggested here.
What Else?
Ermm, can’t we just all agree not to use XSL :)