Xavier,
 
Each time you use the syntax <xsl:variable name="x".../> you are declaring a new local variable, not modifying the existing one!
 
Since your output text occurs before the new declaration, the global value is output displayed and this is always ten.
 
Try moving the fo:block section to after the declaration of the new variable.
 
Phil Dickinson
Aicom Limited
 
-----Original Message-----
From: xavier gibouin [mailto:[EMAIL PROTECTED]
Sent: 05 November 2002 17:59
To: [EMAIL PROTECTED]
Subject: Re: incrementing variable

hi this is my xsl code :
 
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:fo="http://www.w3.org/1999/XSL/Format" xmlns:svg="http://www.w3.org/Graphics/SVG/SVG-19990812.dtd">
<xsl:variable name="x" select="10"/>
 <xsl:template name="codebarre">
  <xsl:variable name="index" select="string-length(codebarre)"/>
  
  <xsl:param name="i" select="0"/>
 
  <xsl:if test="$i &lt; $index">
   <xsl:choose>
    <xsl:when test="substring(codebarre,$i+1,1)='1'">
     <fo:block><xsl:value-of select="$x"/></fo:block>
     <xsl:variable name="x" select="$x + 4"/>
    </xsl:when>
    <xsl:when test="substring(codebarre,$i+1,1)='2'">
     <fo:block><xsl:value-of select="$x"/></fo:block>
     <xsl:variable name="x" select="$x + 1.5"/>
    </xsl:when>
    <xsl:when test="substring(codebarre,$i+1,1)='3'">
     <fo:block><xsl:value-of select="$x"/></fo:block>
     <xsl:variable name="x" select="$x + 3"/>
    </xsl:when>
    <xsl:when test="substring(codebarre,$i+1,1)='4'">
     <fo:block><xsl:value-of select="$x"/></fo:block>
     <xsl:variable name="x" select="$x + 1.5"/>
    </xsl:when>
   </xsl:choose>
 
   <xsl:call-template name="codebarre">
    <xsl:with-param name="i" select="$i+1"/>
   </xsl:call-template>
 
  </xsl:if>
 </xsl:template>
</xsl:stylesheet>
 
this code always writes
10
10
10
10
10
...
 
$x is not incremented
 
any ideas?
 
thanks a lot
 
Xavier Gibouin
Axonie
Espace Mercoeur
8, rue Mercoeur
44000 Nantes
02.40.48.53.23
[EMAIL PROTECTED]
----- Original Message -----
Sent: Tuesday, November 05, 2002 5:52 PM
Subject: Re: variable and svg


put braces around the variable when it is outside an xsl tag:

      <rect height="50" width="4.0" x="{$x}" y="0.0"/>

Reply via email to