Using XSL Parameters

Home » Using XSL Parameters

The following tip was sent to me by Ben Cline, and is posted verbatim. Thanks Ben.
Ben writes …
I found something lacking in the Macromedia documentation and nearly everything I’ve read about CF. It’s the use of XSL parameters. I found a way to successfully do this, and have tried to send something to Macromedia about this, but have never gotten a response back. As you know, using XSL parameters is something that vastly improves the usability of XSL transformations.
All of the code in this tip will use cfscript. If you are unfamiliar with xml, xsl, and xpath, refer to xml documentation.
The key to increasing the productivity of xsl stylesheets comes through xsl:params. Most xml implementations of xml parsers and transformers carry the option of loading up an xsl sheet with parameters.
Before using xsl, it is important that xml be defined as the source document. After the xml has been created, xsl will be made for transforming the xml. Creating an xsl transform to execute the same every time betrays the flexibility that xsl brings to xml. Content output from an xsl transform should instead be dynamic. This can be accomplished by sending variable data into xsl through the use of parameters. During the process of creating an xsl page, the variables for holding dynamic information can be created at the top of an xsl file. The code below shows a parameter within xsl for text color. Notice no value is placed on the xsl:param line, usually indicated by select=””.

One response to “Using XSL Parameters”

  1. Massimo Foti Avatar
    Massimo Foti

    Dan Switzer used the same approach for a clever UDF:
    Another possibility is use Java, I wrote a bunch of dedicated UDFs this way. One for manipulating XSLT code as string using parameters:
    This one instead read XSLT directely from files:
    The benefit of the second UDF is that by reading XSLT from files it handles include and import inside XSLT templates, something not possible out of the box.
    Both my UDFs are available from the italian CFUG, together with other stuff like UDF for validating XML against a DTD:
    The code is written and commented in english, same for the demo files. Hope they could help

Leave a Reply