This is the mail archive of the xsl-list@mulberrytech.com mailing list .


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

RE: using <xsl:variable>


Dhruv,

You are falling into the common mistake that most people go through. You may
not change a value in the XSL once it has been set once, and this includes
variables. This is to make the language side-effect free, and so make its
processing time shorter.

So you may ask "why call it a variable?". The answer to this is that it *is*
a variable in the sense that at the time of writing the XSL, the value of
that particular node is not known.

However, in your case it should be possible to get around your problem with
something like this (though without the source XML I can't be sure...):

<xsl:template match="figure">
<xsl:variable name="fig" select="position()"/>
<xsl:value-of select="$fig"/>
------
</xsl:template>

The value of the "fig" variable cannot change once it has been set in the
template, but is "reset" every time the template is called (think of it like
a local variable in function based programming). Hence, you will see the fig
variable incrementing every time the template is called, which is (I think)
what you wanted.

If is not (for example, you just want a count), then email the list with a
more specific breakdown of your problem...

Hope this helps,

Ben


 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]