xsl-list
[Top] [All Lists]

Re: which is faster?

2005-02-04 04:40:22
correction!

I meant:

//embededMalware/malwareFamily is the current context throughout that loop






tom(_dot_)kirkpatrick(_at_)virusbtn(_dot_)com
04/02/2005 11:38
Please respond to xsl-list

 
        To:        xsl-list(_at_)lists(_dot_)mulberrytech(_dot_)com
        cc: 
        Subject:        Re: [xsl] which is faster?


Right. I have it sussed, although I don't understand it.

<xsl:for-each select = //embededMalware/malwareFamily">
<xsl:if test =
"document('/global/malwareFamilies.xml')/malwareFamilies/malwareFamily[(_at_)id
= 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'"/>
</xsl:call-template>

</xsl:if>
</xsl:for-each>

the problem seems to lay within my use of current()/@id in the predictate
and/or @id as the malwareFamilyId parameter.

If instead, I store the @id attribute in a variable, and then use that
variable throuought the for-each loop it all works ok. Why is this? Surely
the context hasn't changed along the way has it? Looking at that, to me it
looks as if 
document('/global/malwareFamilies.xml')/malwareFamilies/malwareFamily is 
the current contxt throughought the for-each loop, so why does the
reference to @id not work? Why will only work if I extract it into a 
variable?


many thanks






tom(_dot_)kirkpatrick(_at_)virusbtn(_dot_)com
04/02/2005 11:27
Please respond to xsl-list


To:        xsl-list(_at_)lists(_dot_)mulberrytech(_dot_)com
cc:
Subject:        Re: [xsl] which is faster?


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 =
"document('/global/malwareFamilies.xml')/malwareFamilies/malwareFamily[(_at_)id
= 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(_at_)virusbtn(_dot_)com
Last Edited: 01-Nov 04
-->

<xsl:stylesheet
xmlns:xsl = "http://www.w3.org/1999/XSL/Transform";
xmlns:vbtn ="http://www.virusbtn.com/namespaces/malware/1.0/";
xmlns:exsl="http://exslt.org/common";
extension-element-prefixes="exsl"
version = "1.0">

<xsl:output method = "xml" indent = "yes"/>
<xsl:param name="request.uri"/>

<xsl:template match = "article">

<section>
<!-- do embeded variant overview info -->
<xsl:for-each select =
"//embededMalware/malwareFamily">
<xsl:if test =
"document('/global/malwareFamilies.xml')/malwareFamilies/malwareFamily[(_at_)id
= 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'"/>
</xsl:call-template>

</xsl:if>
</xsl:for-each>

</section>
</xsl:template>

<!-- 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"
select="document('/malwareDirectory/prevalence/index.xml')/malwarePrevalence"/>
<!-- start the table -->
<rawhtml>
<table class="layout">
<!-- do the rows -->
<xsl:for-each select="$malwarePrevalence/malwareFamily[(_at_)id =
$malwareFamilyId]/entry">
<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[(_at_)position =
$month_position]/@name"/>
<tr>
<td width="80">
<xsl:value-of select="concat($month, ' ', $year)"/>
</td>
<td>
<img src="/images/ggraph.gif" height="15" align="center"
style="border:0px; padding:0px; margin:0px;" width="{ceiling(@percentage)
* 0.95}%"/>
</td>
<td width="40">
<xsl:value-of select="@percentage"/>%
</td>
<xsl:if test="$method = 'normal' ">
<td width="100"><i>(<xsl:value-of select="@instances"/>
instances)</i></td>
</xsl:if>
<xsl:if test="$method = 'full' ">
<td width="40"><xsl:value-of select="@instances"/></td>
</xsl:if>
</tr>
</xsl:if>
</xsl:for-each>
<!-- finish up -->
</table>
</rawhtml>
</xsl:template>

</xsl:stylesheet>







David Carlisle <davidc(_at_)nag(_dot_)co(_dot_)uk>
04/02/2005 11:06
Please respond to xsl-list


To:        xsl-list(_at_)lists(_dot_)mulberrytech(_dot_)com
cc:
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.

David

________________________________________________________________________
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:
http://www.star.net.uk
________________________________________________________________________

--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--




--
Tom David Kirkpatrick
Virus Bulletin Web Developer, Virus Bulletin

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


--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--




--
Tom David Kirkpatrick
Virus Bulletin Web Developer, Virus Bulletin

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


--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--




-- 
Tom David Kirkpatrick
Virus Bulletin Web Developer, Virus Bulletin

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


--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--



<Prev in Thread] Current Thread [Next in Thread>