Re: [xsl] bizzare number problem

Subject: Re: [xsl] bizzare number problem
From: "Vasu Chakkera" <vasucv@xxxxxxxxxxx>
Date: Wed, 26 Jan 2005 14:19:43 -0000
Yep that was clear from the translate bit...
what is /malwareDirectory/variants/ doing there before the translate???
That doesnt look like a proper xpath to me

vasu
----- Original Message ----- 
From: <tom.kirkpatrick@xxxxxxxxxxxx>
To: <xsl-list@xxxxxxxxxxxxxxxxxxxxxx>
Sent: Wednesday, January 26, 2005 2:08 PM
Subject: Re: [xsl] bizzare number problem


> there is curly braces around the xpath bit of the attribute value:
>
>  {translate(document('/malwareDirectory/fami
> lies/index.xml')/malwareVariantFamilies/malwareFamily[@id
> = $id]/variant[position() = 1]/@id, '/', '-')}
>
>
>
> In plain english. This looks up
> /malwareVariantFamilies/malwareFamily[@id = $id]/variant[position() =
> 1]/@id
>
> in the document '/malwareDirectory/families/index.xml'
>
>
> the value of /malwareVariantFamilies/malwareFamily[@id =
> $id]/variant[position() = 1]/@id
> will result in something lik 'W32/Netsky.a' - The corrisponding filename
> will be 'W32-Netsky.a'
>
>
> So the translate() changes '/' to '-' in the id attribute of
> /malwareVariantFamilies/malwareFamily[@id = $id]/variant[position() = 1]
> in the document '/malwareDirectory/families/index.xml'
>
>
>
>
>
>
>
> "Vasu Chakkera" <vasucv@xxxxxxxxxxx>
> 26/01/2005 13:55
> Please respond to xsl-list
>
>
>         To:        <xsl-list@xxxxxxxxxxxxxxxxxxxxxx>
>         cc:
>         Subject:        Re: [xsl] bizzare number problem
>
>
> <a
>
href="/malwareDirectory/variants/{translate(document('/malwareDirectory/fami
> lies/index.xml')/malwareVariantFamilies/malwareFamily[@id
> = $id]/variant[position() = 1]/@id, '/', '-')}.xml">
>
> The above statement is a bit confusing. Could you please translate this
> for
> us in plain english ??
> One other thing there  should be curly braces around any xpath statement
> or
> function , when it is used as a value of an attribute ( attribute value
> template )
> Refer : http://www.dpawson.co.uk/xsl/sect2/N1575.html
>
> Cheers
> Vasu
> ----- Original Message -----
> From: <tom.kirkpatrick@xxxxxxxxxxxx>
> To: <xsl-list@xxxxxxxxxxxxxxxxxxxxxx>
> Sent: Wednesday, January 26, 2005 1:09 PM
> Subject: Re: [xsl] bizzare number problem
>
>
> > Ok. The complete template is:
> >
> >   <xsl:template name="displayPrevalence">
> >     <xsl:param name="year"/>
> >     <xsl:param name="month" select="'NA'"/>
> >     <xsl:param name="items" select="100"/>
> >     <xsl:param name="method" select="'normal'"/>
> >     <!-- start the table -->
> >     <rawhtml>
> >       <table class="layout vcard">
> >         <tr class="greybox">
> >           <th class="leftContent" style="width:100px !important;">
> >                 Virus Name
> >               </th>
> >           <th>
> >                 Prevalence
> >               </th>
> >           <th class="leftContent" style="width:60px !important;">
> >                 Percentage
> >               </th>
> >               <xsl:if test="$method != 'lite'">
> >           <th class="leftContent" style="width:60px !important;">
> >                 Instances
> >               </th>
> >               </xsl:if>
> >         </tr>
> >             <!-- ensure month has a leading 0 (if set) -->
> >             <xsl:variable name="prevMonth" select="format-number($month,
> > '00')"/>
> >             <!-- do the rows for a specific month-->
> >             <xsl:for-each
> >
>
select="document('/malwareDirectory/prevalence/index.xml')/malwarePrevalence
> /malwareFamily/entry[@date
> > = concat($year,$prevMonth)]">
> >               <xsl:sort order="descending" select="@instances"
> > data-type="number"/>
> >               <xsl:if test="position() &lt;= $items">
> >               <xsl:variable name="id" select="../@id"/>
> >                 <tr>
> >                   <th class="leftContent">
> >                     <xsl:choose>
> >                       <xsl:when
> >
>
test="document('/malwareDirectory/families/index.xml')/malwareVariantFamilie
> s/malwareFamily[@id
> > = $id]/variant">
> >                         <a
> >
>
href="/malwareDirectory/variants/{translate(document('/malwareDirectory/fami
> lies/index.xml')/malwareVariantFamilies/malwareFamily[@id
> > = $id]/variant[position() = 1]/@id, '/', '-')}.xml">
> >                           <xsl:value-of select="$id"/>
> >                         </a>
> >                       </xsl:when>
> >                       <xsl:otherwise>
> >                         <xsl:value-of select="$id"/>
> >                       </xsl:otherwise>
> >                     </xsl:choose>
> >                   </th>
> >                   <td>
> >                     <xsl:variable name="currentNumber"
> > select="ceiling(@percentage) * 0.95"/>
> >                     <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="{$currentNumber}"/>
> >                     <img src="/images/bgraph.gif" height="15"
> > align="center" style="border:0px; padding:0px; margin:0px;"/>
> >                      <xsl:value-of select="$currentNumber"/> -
> > <xsl:value-of select="ceiling(@percentage * 0.95)"/>
> >                   </td>
> >                   <td><xsl:value-of select="@percentage"/></td>
> >                   <xsl:if test="$method != 'lite'">
> >                     <td><xsl:value-of select="@instances"/></td>
> >                   </xsl:if>
> >                 </tr>
> >               </xsl:if>
> >             </xsl:for-each>
> >       </table>
> >     </rawhtml>
> >   </xsl:template>
> >
> >
> >
> > I call it with a call like this:
> >
> >                   <xsl:call-template name="displayPrevalence">
> >                     <xsl:with-param name="year" select="'2004"/>
> >                     <xsl:with-param name="month" select="'11'"/>
> >                     <xsl:with-param name="items" select="5"/>
> >                     <xsl:with-param name="method" select="'lite'"/>
> >                   </xsl:call-template>
> >
> >
> >
> > I am processing with Apache::AxKit
> >
> > I have narrowed the problem down to the choose element:
> >
> >                     <xsl:choose>
> >                       <xsl:when
> >
>
test="document('/malwareDirectory/families/index.xml')/malwareVariantFamilie
> s/malwareFamily[@id
> > = $id]/variant">
> >                         <a
> >
>
href="/malwareDirectory/variants/{translate(document('/malwareDirectory/fami
> lies/index.xml')/malwareVariantFamilies/malwareFamily[@id
> > = $id]/variant[position() = 1]/@id, '/', '-')}.xml">
> >                           <xsl:value-of select="$id"/>
> >                         </a>
> >                       </xsl:when>
> >                       <xsl:otherwise>
> >                         <xsl:value-of select="$id"/>
> >                       </xsl:otherwise>
> >                     </xsl:choose>
> >
> > If I remove that it works fine. If I keep that, $currentNumber comes out
> > as '-2.0465678427e23 +10'!
> >
> > --
> > Tom David Kirkpatrick
> > Virus Bulletin Web Developer, Virus Bulletin
> >
> > Tel: +44 1235 555139
> > Web: www.virusbtn.com
>
>
>
>
> -- 
> Tom David Kirkpatrick
> Virus Bulletin Web Developer, Virus Bulletin
>
> Tel: +44 1235 555139
> Web: www.virusbtn.com

Current Thread