Re: [xsl] which is faster?

Subject: Re: [xsl] which is faster?
From: tom.kirkpatrick@xxxxxxxxxxxx
Date: Fri, 4 Feb 2005 11:27:27 +0000
OK. I'm sorry, that last post was really unclear.

I'll try again.

In the following code. you can see what I am trying to do. That is to call 
the 'displayPrevalenceReport' template from within the 'article' template. 
Now you see where I have gone:

    <!-- set up keys -->
  <xsl:key name="autodateMonth" match="month" use="@position"/>

This line of code is messing the whole thing up. I am not even using the 
key at the moment as you can see. Now I have managed to rectify the 
problem by removing the following lines of code (just the if statement): 

<xsl:if test = 
= current()/@id]">

So without this if statement in there, the <xsl:key> element causes no 
trouble. The reason I use this if statement, is that I need to be sure 
that the required document exists, otherwise when I try to load data from 
it, and it doesn't exist, the whole stylesheet ceeses to work.

I hope that has made it a little clearer?

So to summarise: The presence of both that xsl:if statement and the 
xsl:key staement stops the stylesheet working. If I remove one or the 
other, everything is fine...

<?xml version = "1.0"?>

        Virus Bulletin Stylesheet
                ** VB Article **
                Tom Kirkpatrick - webmaster@xxxxxxxxxxxx
                Last Edited: 01-Nov 04

        xmlns:xsl = "";
        xmlns:vbtn ="";
        version = "1.0">
        <xsl:output method = "xml" indent = "yes"/>
        <xsl:param name="request.uri"/>
        <xsl:template match = "article">
                        <!-- do embeded variant overview info -->
                        <xsl:for-each select = 
                        <xsl:if test = 
= current()/@id]">
              <xsl:call-template name="displayPrevalenceReport">
                <xsl:with-param name="malwareFamilyId" select="@id"/>
                <xsl:with-param name="items" select="5"/>
                <xsl:with-param name="method" select="'lite'"/>

    <!-- set up keys -->
  <xsl:key name="autodateMonth" match="month" use="@position"/>

  <!-- start the PrevalenceReport template -->
  <xsl:template name="displayPrevalenceReport">
    <xsl:param name="malwareFamilyId"/>
    <xsl:param name="items" select="100"/>
    <xsl:param name="method" select="'normal'"/>
    <!-- load in required indexes -->
    <xsl:variable name="malwarePrevalence" 
    <!-- start the table -->
      <table class="layout">
        <!-- 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, 6)"/>
            <xsl:variable name="month" 
select="document('/global/autodate.xml')/date/month[@position = 
              <td width="80">
                <xsl:value-of select="concat($month, ' ', $year)"/>
                <img src="/images/ggraph.gif" height="15" align="center" 
style="border:0px; padding:0px; margin:0px;" width="{ceiling(@percentage) 
* 0.95}%"/>
              <td width="40">
                <xsl:value-of select="@percentage"/>%
                <xsl:if test="$method = 'normal' ">
                  <td width="100"><i>(<xsl:value-of select="@instances"/> 
                <xsl:if test="$method = 'full' ">
                  <td width="40"><xsl:value-of select="@instances"/></td>
        <!-- finish up -->

David Carlisle <davidc@xxxxxxxxx>
04/02/2005 11:06
Please respond to xsl-list

        To:        xsl-list@xxxxxxxxxxxxxxxxxxxxxx
        Subject:        Re: [xsl] which is faster?

> I call this template from two different places. When called from within
> one template everything is fine, however when called from another
> template, the very presence of the <xs:key> element stops the thing from
> working.

I don't understand what you are saying here. xsl:key can't be in a
template it has to be at the top level and consequently the
corresponding key() function will work in in any template.
If you think that isn't happening you will have to give a better
description or a small example of what you are doing.


This e-mail has been scanned for all viruses by Star. The
service is powered by MessageLabs. For more information on a proactive
anti-virus service working around the clock, around the globe, visit:

Tom David Kirkpatrick
Virus Bulletin Web Developer, Virus Bulletin

Tel: +44 1235 555139

Current Thread