0

I have variables that I think can be initialized a couple different ways and I want to know if one way may be more efficient or may help improve transformation time when dealing with large amounts of data.

Here are two examples of how I might declare a variable:

<xsl:variable name="sampleVariable" select="$thisNodeSet[string-length($currentName) &gt; 0 and @NAME=$currentname]
                                            | $thisNodeSet[string-length($currentNameInstance) &gt; 0 and contains(@INSTANCE, $currentNameInstance)]
                                            | $thisNodeSet[string-length($currentName) &lt;= 0 and string-length($currentNameInstance) &lt;= 0]" />

OR

<xsl:variable name="sampleVariable">
    <xsl:choose>
         <xsl:when test="string-length($currentName)&gt;0">
                    <xsl:copy-of select="$thisNodeSet[@NAME=$currentname] /> 
         </xsl:when>
         <xsl:when test="string-length($currentNameInstance)&gt;0">
                    <xsl:copy-of select="$thisNodeSet[contains(@INSTANCE, $currentNameInstance)]" />
         </xsl:when>
         <xsl:otherwise>
                    <xsl:copy-of select="$thisNodeSet" />
         </xsl:otherwise>
     </xsl:choose>
</xsl:variable>

I was unsure how each operation would be storing the nodes and wondered if xsl:copy-of would be storing a lot more in memory somehow.

My question is whether or not one of these methods is faster/more efficient or if they will have similar performance on transformation time, memory, or anything else that could be affected by these methods.

Thanks for the help!

EDIT: It is using the MSXML processor

Ibrennan208
  • 1,345
  • 3
  • 14
  • 31
  • The performance will most likely depend on the implementation of the XSLTProcessor. – zx485 Mar 31 '17 at 18:47
  • Oh yea, sorry I didn't include that. I am using MSXML processor. – Ibrennan208 Mar 31 '17 at 19:01
  • Put a performance wrapper around your TransformXML call (or equivalent) and compare the times.Some examples here http://stackoverflow.com/questions/969290/exact-time-measurement-for-performance-testing – NMGod Mar 31 '17 at 23:05
  • There is actually a difference between the two variable selections. The first variable is selecting nodes in the original `$thisNodeSet` variable. It is not creating new instances of nodes. The second one IS creating copies of the node, and the result is known as a "Result Tree Fragment". In XSLT 1.0, you will need the `node-set` extension function to manipulate the second variable. – Tim C Apr 01 '17 at 08:17
  • @TimC So initially I was thinking that as well, I was just unsure. So theoretically, the second method would be more memory exhaustive in situations with large nodesets, correct? – Ibrennan208 Apr 01 '17 at 16:36
  • Yes, as it is creating copies of nodes, it would require more memory. – Tim C Apr 01 '17 at 17:38
  • Using the union operator in variable 1 causes the $thisNodeSet variable to be parsed three times. It might be helpful to rework the select to use only one filter and use and's or's and parenthesis. Let us know. – John Ernst Apr 03 '17 at 04:51

0 Answers0