Subject: RE: [xsl] which is faster? From: "Andrew Welch" <ajwelch@xxxxxxxxxxxxxxx> Date: Fri, 4 Feb 2005 09:59:50 -0000 |
> I have a template which does a lookup from an exernal file. > Currently I am > doing it like so. That all looks fine, one area you could see some improvement though is that for each iteration (of the first ten <malwareFamily> elements) you do: <xsl:variable name="month" select="document('/global/autodate.xml')/date/month[@position = $month_position]/@name"/> Which would be much faster if you used a key: <xsl:variable name="autodate" select="document('/global/autodate.xml')"/> <xsl:key name="autodate_month" match="month" use="@position"/> With in XSLT 1.0: <xsl:for-each select="$autodate"> <xsl:value-of select="key('autodate_month', $month_position)/@name"/> </xsl:for-each> Or in XSLT 2.0: <xsl:value-of select="key('autodate_month', $month_position, $autodate)/@name"/> cheers andrew > <!------------- > <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" > > select="document('/malwareDirectory/prevalence/index.xml')/mal > warePrevalence"/> > > <!-- do the rows --> > <xsl:for-each select="$malwarePrevalence/malwareFamily[@id = > $malwareFamilyId]/entry"> > <xsl:sort order="descending" select="@date"/> > <xsl:if test="position() <= $items"> > <xsl:variable name="year" select="substring(@date, 1, 4)"/> > <xsl:variable name="month_position" select="substring(@date, 5, > 6)"/> > <xsl:variable name="month" > select="document('/global/autodate.xml')/date/month[@position = > $month_position]/@name"/> > > <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 /> > > </xsl:if> > </xsl:for-each> > </xsl:template> > <!------------- > > 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"?> > <malwarePrevalence> > <malwareFamily id="1099"> > <entry date="199504" instances="1" percentage="0.9"/> > </malwareFamily> > <malwareFamily id="10_Past_3.748"> > <entry date="199808" instances="1" percentage="0.5"/> > </malwareFamily> > <malwareFamily id="2K-674"> > <entry date="199602" instances="1" percentage="0.3"/> > </malwareFamily> > <malwareFamily id="2lines"> > <entry date="199705" instances="1" percentage="0.3"/> > </malwareFamily> > <malwareFamily id="A&A.506"> > <entry date="199611" instances="1" percentage="0.1"/> > </malwareFamily> > <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> > <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"/> > </malwareFamily> > </malwarePrevalence> > <!------------- > > 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 |
---|
|
<- Previous | Index | Next -> |
---|---|---|
[xsl] which is faster?, tom . kirkpatrick | Thread | RE: [xsl] which is faster?, tom . kirkpatrick |
[xsl] which is faster?, tom . kirkpatrick | Date | Re: [xsl] Matching a list of attrib, David Carlisle |
Month |