Re: [xsl] Order of call-template

Subject: Re: [xsl] Order of call-template
From: Michael Kay <mike@xxxxxxxxxxxx>
Date: Fri, 22 Jun 2012 17:42:30 +0100
There is a very high likelihood that any XSLT processor will execute these instructions in the order you write them, but it's not guaranteed by the spec. For example, they could be executed in parallel. The only guarantee in the spec is that in the result sequence, <outcode> and its contents will precede <incode> and its contents.

Where processors ARE very likely to muck around with the ordering is when you use variables. If you wrote

<xsl:variable name="i">
<incode>
<xsl:call-template name="getIncode">
<xsl:with-param name="zip" select="'10001'"/>
<xsl:with-param name="id" select="2"/>
</xsl:call-template>
</incode>
</xsl:variable>

<xsl:variable name="o">
<outcode>
<xsl:call-template name="getOutcode">
<xsl:with-param name="zip" select="'10001"/>
<xsl:with-param name="id" select="1"/>
</xsl:call-template>
</outcode>
</xsl:variable>

<xsl:copy-of select="$o, $i"/>

Then you might well find different processors using a different order of execution. Of course, the only way you can tell is if the templates have side-effects (for example, if they call xsl:message).

Michael Kay
Saxonica




On 22/06/2012 17:07, Ming Yu wrote:
I have the following code in my xslt. Will it guarantee the first call-template to be executed before the second one?

<outcode>
<xsl:call-template name="getOutcode">
<xsl:with-param name="zip" select="'10001"/>
<xsl:with-param name="id" select="1"/>
</xsl:call-template>
</outcode>
<incode>
<xsl:call-template name="getIncode">
<xsl:with-param name="zip" select="'10001'"/>
<xsl:with-param name="id" select="2"/>
</xsl:call-template>
</incode>

Thanks!

Ming

Current Thread