Is it possible to apply a template to the result of a call-template?
For example, the xml and 2 xslt below.
index.xml:
Is there any way to apply a template to the result of
in index.xsl?
Yes, this is called multi-pass processing. The only peculiarity is that in XSLT 1.0 you must apply the implementation-dependent xxx:node-set()
extension function to any intermediate result, which in general will be of the infamous RTF (Result Tree Fragment) type and thus will need to be converted to a regular tree.
Here is a complete example of multi-pass processing (I am using xsl:apply-templates
and not xsl:call-template
, but you can freely modify this example to use named templates and xsl:call-template
instead):
when this transformation is applied on the following XML document:
01
02
03
04
05
06
07
08
09
10
the wanted result ( the content of any num
elements is doubled in the first pass, then squared in the second pass) is produced:
4
16
36
64
100
144
196
256
324
400
II. In XSLT 2.0
The RTF "type" was abolished, so it is much more easier to specify multi-pass processing, which becomes almost indistinguishable from functional composition, as the following equivalent transformation shows:
when this transformation is applied on the same XML document (above), the same correct result is produced:
4
16
36
64
100
144
196
256
324
400