XSLT is a declarative or functional language, not a procedural language, so there is no defined order of execution, and therefore no update of variables. Seems strange at first and it requires a different way of thinking about your problem, but you end up writing much better code as a result.
Questions like this always remind me of the COBOL programmers who used to ask "how do I achieve this without a GOTO statement"? Once you start thinking in a declarative functional way, the question never occurs to you.
Rather than looking at your procedural code and trying to reverse engineer it, I would suggest you try describing your problem: what is the output to be, as a function of the input? Try to describe the relationship of one to the other without describing a procedure for doing the work. Then you should find that this description translates very naturally into a functional program.
Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference