param and variable are immutable. They can be global or local
<xsl:param>
<xsl:param
name="name"
select="expression" as="dataType" >
<!-- Content:template -->
</xsl:param>
<!-- Content:template -->
</xsl:param>
Then you can use $name to represent the selected expression. You have to explicitly supple the param in the command line
example:
java -cp saxon9ee.jar net.sf.saxon.Transform -t -s:HelloWorld.xml -xsl:HelloWorld.xsl -o:c:\temp.html
<xsl:variable>
variable can be global if it is defined as a child of xsl:stylesheet or it can be local if defined inside template
<xsl:variable
name="name"
select="expression" as="dataType">
<!-- Content:template -->
</xsl:variable>
<!-- Content:template -->
</xsl:variable>
example:
<xsl:variable name="color" select="'red'" />
<xsl:variable name="dueDate" select="'2003-12-08'" as="xs:date" />
Occurrence indicator
Any of the preceding sequence types can be followed by an occurrence indicator. These indicators are the same as Those in DTDs
? - optional
* - zero or more
+ - one or more
<xsl:variable name="programs" select="Program" as = "element()+" />
Constructing Sequence containing atomic values
<xsl:variable name="seq" as="xs:integer *">
<xsl:for-each select="1 to 5">>
<xsl:sequence select=". * ."/>
</xsl:for-each/>
</xsl:variable>
This produces (1, 4, 9, 16, 25)
<xsl:with-param>
The <xsl:with-param> element defines the value of a parameter to be passed into a template.
The template that needs a param elementToDump:
<xsl:template name="dumpDebugData">
<xsl:param name="elementToDump" />
<xsl:for-each select="$elementToDump/@*">
<xsl:text> </xsl:text> <!-- newline char -->
<xsl:value-of select="name()" /> : <xsl:value-of select="." />
</xsl:for-each>
</xsl:template>
Use a <xsl:with-param> to pass the parameter:
<xsl:call-template name="dumpDebugData">
<xsl:with-param name="elementToDump" select="some/xpath" />
</xsl:call-template>
Tunneling Param
A parameter passed to a template may be defined as a tunnel parameter. Tunnel parameters have the property that they are automatically passed on by the called template to any further templates that it calls, and so on recursively.] Tunnel parameters thus allow values to be set that are accessible during an entire phase of stylesheet processing, without the need for each template that is used during that phase to be aware of the parameter.
Tunnel parameters are automatically passed through templates. To use them, the tunnel attribute on <xsl:param> and <xsl:with-param> is given the value 'yes'.