I am new to XSLT.I have an XML document and I am using the XSL for converting the XML in to an HTML table.The XML is response from an server to web client.In this case It is IE9 browser.The XSLT processing is done by browser.The number of "ch3" nodes ranges from 1 to 100000.
Below is the sample code of what I am doing .
In the below xsl code the variable is created in every loop.I like to know what is the effect of this creation on the browser memory.Also will this have any performance impacts?
============XMLDoc=======
<?xml version="1.0" encoding="ISO-8859-1"?>
<root>
<ch1>
<ch2>
<ch3 a="bosy" b="" c="5" d="nobody"/>
......
</ch2>
</ch1>
</root>
============XMLDoc=======
============XSLSheet=======
<?xml version="1.0" encoding="ISO-8859-1"?>
<xsl:transform version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="root/ch1">
......
<xsl:for-each select="ch1/ch">
<xsl:variable name="color">
<xsl:choose>
<xsl:when test="@c = '5'">orange</xsl:when>
<xsl:when test="@c = '4'">red</xsl:when>
<xsl:when test="@c = '3'">white</xsl:when>
<xsl:when test="@c = '2'">gree</xsl:when>
<xsl:when test="@c = '1'">yellow</xsl:when>
<xsl:when test="@c = '0'">blue</xsl:when>
</xsl:choose>
</xsl:variable>
.............
</xsl:for-each>
.............
<xsl-template>
</xsl:transform>
============XSL Sheet=======
I think XSLT variables are pretty cheap. In general, I wouldn't worry about the performance unless you actually have a problem with it. You might want to generate one of these 100000-node documents to see if the performance is acceptable.
That's definitely implementation specific, it'll potentially vary between browsers.
However, a variable in this context is no longer required after each iteration of the for-each loop, so any self respecting XSLT processor should never need to have 100000 values in memory, the memory can be freed after each iteration.
You need to address performance top-down not bottom-up. Do you know your performance requirements? Can you measure the performance you are currently achieving? Is there a gap, and if so, can you quantify it? At this stage you can start drilling down to analyze the causes, e.g. by doing controlled experiments to measure the effect of changing the design in particular ways. Speculating as to whether particular constructs are inefficient is part of this process, but the only way to get an answer is to make measurements.