1. param_1-input.xml

  2. <?xml version="1.0"?>
  3. <languages>
  4.   <english>bread</english>
  5.   <danish>brød</danish>
  6.   <french>pain</french>
  7. </languages>
  1. param_1-stylesheet.xsl

  2. <?xml version="1.0"?>
  3. <xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
  4.   <xsl:param name="language" select="'en'"/>
  5.   <xsl:output indent="yes"/>
  6.   <xsl:template match="/">
  7.     <languages>
  8.       <xsl:choose>
  9.         <xsl:when test="$language = 'fr'"><xsl:value-of select="languages/frensh"/></xsl:when>
  10.         <xsl:when test="$language = 'da'"><xsl:value-of select="languages/danish"/></xsl:when>
  11.         <xsl:otherwise><xsl:copy-of select="languages/english"/></xsl:otherwise>
  12.       </xsl:choose>
  13.     </languages>
  14.   </xsl:template>
  15. </xsl:stylesheet>
  1. param_1-output

  2. <?xml version="1.0" encoding="UTF-8"?>
  3. <languages>
  4.   <english>bread</english>
  5. </languages>


When used at global level (child of xsl:stylesheet), xsl:param acts like an external variable picking up its value from outside. When the transformation takes place at the command line a parameter can be passed in. XML Editors has a dialog box where external parameters can be declared. When a programming language is host for the transformation, it has a "parameter" class that can be used to make a parameter object passing parameters into the transformation process.

See: http://www.xmlplease.com/transform-xml-xslt10 for example in .net.

Updated 2009-03-19