i hope it will work fine as you want
(don't hesitate to contact me if you need some help...)
We're using xalan (Java) to do XSLT. What we found out is that you can only set a xsl:variable ONCE. So when it's set once, it keeps that value. We work around it by determining the value elsewhere and passing it in through xsl:param
I don't know Xalan.
i'm using Sablotron with PHP.
Sablotron is a XSLT Processor written in C++ (i think it's greter than Java :-)) ).
For more informations i invite you to see Sablotron homepage