Global Parameters

XSLT allows you to define parameters whose scope is the entire stylesheet. You can define default values for these parameters, and you can pass values to those parameters externally to the stylesheet. Before we talk about how to pass in values for global parameters, we’ll show you how to create them. Any parameters that are top-level elements (any <xsl:param> elements whose parent is <xsl:stylesheet>) are global parameters. Here’s an example:

<?xml version="1.0"?>
<!-- params.xsl -->
<xsl:stylesheet version="1.0" 

  <xsl:output method="text"/>

  <xsl:param name="startX"/>
  <xsl:param name="baseColor"/>

  <xsl:template match="/">
    <xsl:text>&#xA;Global parameters example&#xA;&#xA;</xsl:text>

    <xsl:text>The value of startX is: </xsl:text>
    <xsl:value-of select="$startX"/>
    <xsl:text>&#xA;The value of baseColor is: </xsl:text>
    <xsl:value-of select="$baseColor"/>


How you pass values for global parameters depends on the XSLT processor you’re using. We’ll go through some examples here for all the usual suspects. Let’s say we want to pass the numeric value 50 as the value for startX, and the string value magenta as the default value for baseColor. The following list describes the commands you’d use to do that:


To pass global parameters to Xalan, you can define them on the Xalan command line:

java org.apache.xalan.xslt.Process -in blank.xml -xsl params.xsl -param startX ...

Get XSLT, 2nd Edition now with the O’Reilly learning platform.

O’Reilly members experience live online training, plus books, videos, and digital content from nearly 200 publishers.