[xsl] which is faster?

Subject: [xsl] which is faster?
From: tom.kirkpatrick@xxxxxxxxxxxx
Date: Fri, 4 Feb 2005 09:27:55 +0000
I have a template which does a lookup from an exernal file. Currently I am 
doing it like so.

<xsl:template name="displayPrevalenceReport">
  <xsl:param name="malwareFamilyId"/>
  <xsl:param name="items" select="10"/>
  <xsl:param name="method" select="'normal'"/>
  <!-- load in required indexes -->
  <xsl:variable name="malwarePrevalence" 

  <!-- do the rows -->
  <xsl:for-each select="$malwarePrevalence/malwareFamily[@id = 
    <xsl:sort order="descending" select="@date"/>
    <xsl:if test="position() &lt;= $items">
      <xsl:variable name="year" select="substring(@date, 1, 4)"/>
      <xsl:variable name="month_position" select="substring(@date, 5, 
      <xsl:variable name="month"
 select="document('/global/autodate.xml')/date/month[@position = 

      <xsl:value-of select="concat($month, ' ', $year)"/>

      <img src="/images/bgraph.gif" height="15" align="center" 
style="border:0px; padding:0px; margin:0px;"/>

      <img src="/images/ggraph.gif" height="15" align="center" 
style="border:0px; padding:0px; margin:0px;" width="{ceiling(@percentage) 
* 0.95}%"/>

      <img src="/images/bgraph.gif" height="15" align="center" 
style="border:0px; padding:0px; margin:0px;"/>

      <xsl:value-of select="@percentage"/>% <br/>

      <xsl:value-of select="@instances"/> instances <br />


The external file looks a bit like this (although it actually contains 
about 12000 lines of code and is about 600k on disk):

<?xml version="1.0"?>
  <malwareFamily id="1099">
    <entry date="199504" instances="1" percentage="0.9"/>
  <malwareFamily id="10_Past_3.748">
    <entry date="199808" instances="1" percentage="0.5"/>
  <malwareFamily id="2K-674">
    <entry date="199602" instances="1" percentage="0.3"/>
  <malwareFamily id="2lines">
    <entry date="199705" instances="1" percentage="0.3"/>
  <malwareFamily id="A&amp;A.506">
    <entry date="199611" instances="1" percentage="0.1"/>
  <malwareFamily id="ABC">
    <entry date="199712" instances="1" percentage="0.2"/>
    <entry date="199801" instances="2" percentage="0.4"/>
    <entry date="199802" instances="1" percentage="0.2"/>
    <entry date="199803" instances="2" percentage="0.5"/>
    <entry date="199805" instances="2" percentage="0.5"/>
  <malwareFamily id="Angelina">
    <entry date="199709" instances="2" percentage="0.7"/>
    <entry date="199802" instances="7" percentage="1.6"/>
    <entry date="199804" instances="4" percentage="1.0"/>
    <entry date="199805" instances="2" percentage="0.5"/>
    <entry date="199806" instances="1" percentage="0.2"/>
    <entry date="199808" instances="5" percentage="2.4"/>
    <entry date="199809" instances="2" percentage="0.9"/>
    <entry date="199810" instances="1" percentage="0.2"/>
    <entry date="199811" instances="2" percentage="0.5"/>
    <entry date="199903" instances="23" percentage="0.4"/>
    <entry date="199908" instances="1" percentage="0.05"/>
    <entry date="199910" instances="1" percentage="0.05"/>

So as you can see, first I load the external file into a variable for easy 
access, then I do a for-each loop on the specific parts of the file I want 
to proecss. What I want to know is if I am going about this in a decent 
manor, or if I am making the computer do unnessecary work.

The problem (if there is one) probably lays with the call to the external 
file. Perhaps I should be using keys somehow to speed it all up? Or 
perhaps I should load only the parts of that external file into this 
stylesheet rather than the entire document. Or seing as I only want to 
process the first 10 elements, is there a way to load only those ones into 
the stylesheet?

Many thanks to anyone who can give me some pointers.

Tom David Kirkpatrick
Virus Bulletin Web Developer, Virus Bulletin

Tel: +44 1235 555139
Web: www.virusbtn.com

Current Thread