[xsl] Optimisation -- premature?

Subject: [xsl] Optimisation -- premature?
From: "John Horner" <Horner.John@xxxxxxxxxx>
Date: Mon, 12 Feb 2007 10:07:56 +1100
I have a transformation which sometimes, depending on circumstances,
creates bunch of variables used in an external function.

Let's say that logic is like this:

<xsl:if test="a_certain_flag_is_set">
   <xsl:variable name="foo" select="foo"/>
   <xsl:variable name="bar" select="bar"/>
   <xsl:variable name="baz" select="baz"/>
   <xsl:value-of select="namespace:function($foo,$bar,$baz)"/>
</xsl:if>

That's OK except that elsewhere in the stylesheet, if a different and
mutually exclusive flag is set, I need to create exactly the same
variables

<xsl:if test="a_different_flag_is_set">
   <xsl:variable name="foo" select="foo"/>
   <xsl:variable name="bar" select="bar"/>
   <xsl:variable name="baz" select="baz"/>
   <xsl:value-of select="namespace:function($foo,$bar,$baz)"/>
</xsl:if>

I want to be more efficient about this, and would rather do this at the
top of the stylesheet

<xsl:if test="a_certain_flag_is_set
              or
              a_different_flag_is_set">
   <xsl:variable name="foo" select="foo"/>
   <xsl:variable name="bar"select="bar"/>
   <xsl:variable name="baz" select="baz"/>
</xsl:if>

That is, create them once, if they're going to be needed by either
function later in the processing. Because of the way scope works in XSL,
I can't do this, can I? So, which of the two less efficient methods is
best -- create them every time the process runs, although I may not need
them, or duplicate their creation locally in the separate if-elements?

It's not a problem as such, the process works just fine, but it's
bugging me a little that I can't do it the "right" way.

=============================================================================
=
The information contained in this email and any attachment is confidential
and
may contain legally privileged or copyright material.   It is intended only
for
the use of the addressee(s).  If you are not the intended recipient of this
email, you are not permitted to disseminate, distribute or copy this email or
any attachments.  If you have received this message in error, please notify
the
sender immediately and delete this email from your system.  The ABC does not
represent or warrant that this transmission is secure or virus free.   Before
opening any attachment you should check for viruses.  The ABC's liability is
limited to resupplying any email and attachments
=============================================================================
=

Current Thread