If the script is invoking the transformation, then you will find there is a method in the API such as addParameter() that allows the script to bind a value to a global xsl:param defined in the stylesheet.
On the other hand, if the transformation is generating the script as part of its result tree, then there is of course no way the script can set a variable in the transformation because the script will never be executed until the transformation has completed.
Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference