[XSL-LIST Mailing List Archive Home] [By Thread] [By Date]

Re: [xsl] bizzare number problem


Subject: Re: [xsl] bizzare number problem
From: tom.kirkpatrick@xxxxxxxxxxxx
Date: Wed, 26 Jan 2005 13:09:17 +0000

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')/malwareVariantFamilies/malwareFamily[@id 
= $id]/variant">
                        <a 
href="/malwareDirectory/variants/{translate(document('/malwareDirectory/families/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')/malwareVariantFamilies/malwareFamily[@id 
= $id]/variant">
                        <a 
href="/malwareDirectory/variants/{translate(document('/malwareDirectory/families/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


Current Thread