This stylesheet and This stylesheet demonstrate different ways of setting xsl:variable, This stylesheet and This stylesheet of setting xsl:param.
A stylesheet can contain several variables of the same name. This stylesheet demonstrates a way how to recover the value of global variable which has the same name as a local one. The This stylesheet demonstrates an incorrect approach. The value of local variable is bounded to xsl:when element. The rest of template therefore sees only the global variable.
Parameters for a template can be passed with xsl:with-param element. If the template contains a xsl:param element with the same name as name attribute of xsl:with-param, this value is used. This stylesheet shows a typical example. If you want to pass a variable, you have to define this variable with xsl:param element. Look at This stylesheet for wrong approach.
A variable can hold a result tree fragment. The operations permitted on a result tree fragment are a subset of those permitted on a node-set. An operation is permitted on a result tree fragment only if that operation would be permitted on a string (the operation on the string may involve first converting the string to a number or boolean). In particular, it is not permitted to use the /, //, and [] operators on result tree fragments. When a permitted operation is performed on a result tree fragment, it is performed exactly as it would be on the equivalent node-set. Compare This stylesheet and This stylesheet.
There is an important difference in variable value specification.