XSL Parameters

XSL Parameters Overview

Publish Control Files (PCF) can specify arbitrary parameters to be passed to the referenced XSL stylesheets. In this way, parameters were defined in each processing instruction of the PCF (the pcf-stylesheet declaration), allowing a single XSL stylesheet to service multiple targets. However, new implementations can make use of a number of global XSLT variables that are available. These are declared within the ou-variables.xsl and can be used in other XSLs. See:

OU Campus XSLT Variables

Defining the Parameters

Parameters are passed to the XSLT engine as an attribute of the pcf-stylesheet instruction. Multiple parameters can be passed at once, and are referenced in name=value pairs separated by semicolons.

<?pcf-stylesheet path="/xsl/index.xsl" params="image=test.jpg;caption=test image" extension="html"?>

In the above example, two parameters are being passed to the XSL stylesheet: image, with the value test.jpg, and caption, with the value test image.

Since parameters are defined in each pcf-stylesheet instruction, the PCF can pass different parameters (or the same parameters with different values) for each processing instruction.

<?pcf-stylesheet path="/xsl/index.xsl" params="image=test.jpg;caption=test image" extension="html"?>
<?pcf-stylesheet path="/xsl/index.xsl" params="pagestyle=mobile;image=test-mobile.jpg;caption=test image" extension="html" alternate="yes"?>
<?pcf-stylesheet path="/xsl/index.xsl" params="columns=15" extension="csv" alternate="yes"?> 

For more up-to-date information about the pcf-stylesheet declaration:

PCF Overview

Accessing the Parameters in an XSL Stylesheet

Parameters that are being passed in to an XSL file must be declared in the XSL stylesheet before they can be accessed. In order to declare parameters globally in the XSL file, an xsl:param element must be defined and named for each parameter, just inside of the opening xsl:stylesheet element.

<xsl:param name="image"/>
<xsl:param name="caption"/>

Once they are defined, parameters can then be referenced inside of the XSL stylesheet using an xsl:value-of element.

<xsl:value-of select="$image"/>
<xsl:value-of select="$caption"/>