Whatever message this page gives is out now! Go check it out!

Transforming XML documents using XSLT

Last update:
May 18, 2026
The Extensible Stylesheet Language Transformation (XSLT) technology transforms an XML document into another format or representation. For example, one common use of XSLT is to convert XML documents into HTML for display in a browser. XSLT has many other uses, including converting XML data to another format, such as converting XML in a vocabulary used by an order entry application into a vocabulary used by an order fulfillment application.
XSLT transforms an XML document by applying an Extensible Stylesheet Language (XSL) style sheet. (When stored in a file, XSL style sheets typically have the .xsl extension.) ColdFusion provides the XmlTransform function to apply an XSL transformation to an XML document. The function takes an XML document in string format or as an XML document object, and an XSL style sheet in string format, and returns the transformed document as a string.

The following code:

  • Reads the simpletransform.xsl style sheet file into a string variable.
  • Uses the style sheet to transform the mydoc XML document object.
  • Saves the resulting transformed document in a second file.

<cffile action="read" file="C:\CFusion\wwwroot\testdocs\simpletransform.xsl"
variable="xslDoc">
<cfset transformedXML = XmlTransform(mydoc, xslDoc)>
<cffile action="write" file="C:\CFusion\wwwroot\testdocs\transformeddoc.xml"
output=transformedXML>
      
XSL and XSLT are specified by the World Wide Web Consortium (W3C). For detailed information on XSL, XSLT, and XSL style sheets, see the W3C website at www.w3.org/Style/XSL/. Several books are available on using XSL and XSLT.
IMPORTANT
If you call XmlTransform() with an XML string, ColdFusion parses that XML before applying the XSLT. Starting in this release, XML containing a <!DOCTYPE ...> declaration is rejected unless you pass ALLOWDOCTYPEDECLARATION=true in the params struct.
<cfset params = {
    ALLOWDOCTYPEDECLARATION = true,
    ALLOWEXTERNALENTITIES = false,
    ENTITYEXPANSIONLIMIT = 1000
}>

<cfset transformedXML = XmlTransform(myXmlString, xslDoc, params)>
This setting applies to the input XML string only. It does not change how the XSL stylesheet itself is processed.

Share this page

Was this page helpful?
We're glad. Tell us how this page helped.
We're sorry. Can you tell us what didn't work for you?
Thank you for your feedback. Your response will help improve this page.

On this page