<html>
<head>
<link href="mmres://user_interface_reference.css" rel="stylesheet" type="text/css">
<title>XMLTRANSFORM</title>
</head>
<body bgcolor="#FFFFFF" text="#000000">
   <div id="Description">
   <table cellpadding="0" cellspacing="0" border="0" width="100%" class="main">
      <tr> 
         <td valign="top" class="name">XMLTRANSFORM</td>
         <td valign="top" nowrap class="compatibility">&nbsp;</td>
      </tr>
      <tr>
         <td colspan="2" class="divider"><img src="dwres:18084" width="100%" height="1"></td>
      </tr>


    </td>
  </tr>
  <tr>
    <td valign="top" colspan="2" class="description"><span class="title">Description</span>
<p>
Applies an Extensible Stylesheet Language Transformation (XSLT) to XML. The XML can be in string format or an XML document object.
</p>
    </td>
  </tr>
  <tr>
    <td valign="top" colspan="2" class="CLEARSEPARATION">&nbsp;</td>
  </tr>
  <tr>
    <td valign="top" colspan="2" class="description"><span class="title">Returns</span>
<p>
A string containing the results of applying the XSLT to the XML.
</p>
    </td>
  </tr>
  <tr>
    <td valign="top" colspan="2" class="CLEARSEPARATION">&nbsp;</td>
  </tr>
  <tr>
    <td valign="top" colspan="2" class="description"><span class="title">Category</span>
<p>
Conversion functions, XML functions
</p>
    </td>
  </tr>
  <tr>
    <td valign="top" colspan="2" class="CLEARSEPARATION">&nbsp;</td>
  </tr>
  <tr>
    <td valign="top" colspan="2" class="description"><span class="title">Function syntax</span><pre>XmlTransform(xml, xsl[, parameters])
</pre>    </td>
  </tr>
  <tr>
    <td valign="top" colspan="2" class="CLEARSEPARATION">&nbsp;</td>
  </tr>
  <tr>
    <td valign="top" colspan="2" class="description"><span class="title">See also</span>
<p>
cfxml, XmlFormat, XmlNew, XmlParse, XmlSearch, XmlValidate; Chapter&#160;35, "Using XML and WDDX" in ColdFusion MX Developer's Guide
</p>
    </td>
  </tr>
  <tr>
    <td valign="top" colspan="2" class="CLEARSEPARATION">&nbsp;</td>
  </tr>
  <tr>
    <td valign="top" colspan="2" class="description"><span class="title">History</span>
<p>
ColdFusion&#160;MX&#160;7: Added the parameters parameter and the ability to use a file for the XSL.
</p>

<p>
ColdFusion&#160;MX: Added this function.
</p>
    </td>
  </tr>
  <tr>
    <td valign="top" colspan="2" class="CLEARSEPARATION">&nbsp;</td>
  </tr>
  <tr>
    <td valign="top" colspan="2" class="description"><span class="title">Parameters</span>
<p>

</p>
    </td>
  </tr>
  <tr>
    <td valign="top" colspan="2" class="CLEARSEPARATION">&nbsp;</td>
  </tr>
  <tr>
    <td valign="top" colspan="2" class="description"><span class="title">Usage</span>
<p>
An XSLT converts an XML document to another format or representation by applying an Extensible Stylesheet Language (XSL) stylesheet to it. XSL, including XSLT syntax is specified by the World Wide Web Consortium (W3C). For detailed information on XSL and XSLT, see the W3C website at www.w3.org/Style/XSL/</a>.
</p>

<p>
If the XSLT code contains include statements with relative paths, ColdFusion resolves them relative to the location of the XSLT file, or for an XSL string, the location of the current ColdFusion page.
</p>
    </td>
  </tr>
  <tr>
    <td valign="top" colspan="2" class="CLEARSEPARATION">&nbsp;</td>
  </tr>
  <tr>
    <td valign="top" colspan="2" class="description"><span class="title">Example</span>
<p>
The following example converts an XML document that represents a customer order into an HTML document with the customer name and a table with the order items and quantities:
</p>

<p>
The custorder.xml file that represents a customer order has the following lines:
</p>
<pre>&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt;
&lt;order id=&quot;4323251&quot;&gt;
   &lt;customer firstname=&quot;Philip&quot; lastname=&quot;Cramer&quot; accountNum=&quot;21&quot;/&gt;
   &lt;items&gt;
      &lt;item id=&quot;43&quot;&gt;
         &lt;name&gt;Deluxe Carpenter&amp;apos;s Hammer&lt;/name&gt;
         &lt;quantity&gt;1&lt;/quantity&gt;
         &lt;unitprice&gt;15.95&lt;/unitprice&gt;
      &lt;/item&gt;
      &lt;item id=&quot;54&quot;&gt;
         &lt;name&gt;36&amp;quot; Plastic Rake&lt;/name&gt;
         &lt;quantity&gt;2&lt;/quantity&gt;
         &lt;unitprice&gt;6.95&lt;/unitprice&gt;
      &lt;/item&gt;
      &lt;item id=&quot;68&quot;&gt;
         &lt;name&gt;Standard paint thinner&lt;/name&gt;
         &lt;quantity&gt;3&lt;/quantity&gt;
         &lt;unitprice&gt;8.95&lt;/unitprice&gt;
      &lt;/item&gt;
   &lt;/items&gt;
&lt;/order&gt;
</pre>
<p>
The custorder.xsd XSLT file that transforms the XML to HTML that displays the customer's name, and the items and quantities ordered has the following lines:
</p>
<pre>&lt;?xml version=&quot;1.0&quot;?&gt;
&lt;xsl:stylesheet version=&quot;1.0&quot; xmlns:xsl=&quot;http://www.w3.org/1999/XSL/
Transform&quot;&gt;
&lt;xsl:output method=&quot;html&quot; doctype-public=&quot;-//W3C//DTD HTML 4.0 Transitional//
EN&quot; /&gt;
   &lt;xsl:template match=&quot;/&quot;&gt;
      &lt;html&gt;
         &lt;body&gt;
            &lt;table border=&quot;2&quot; bgcolor=&quot;yellow&quot;&gt;
               &lt;tr&gt;
                  &lt;th&gt;Name&lt;/th&gt;
                  &lt;th&gt;Price&lt;/th&gt;
               &lt;/tr&gt;
               &lt;xsl:for-each select=&quot;breakfast_menu/food&quot;&gt;
                  &lt;tr&gt;
                     &lt;td&gt;
                        &lt;xsl:value-of select=&quot;name&quot;/&gt;
                     &lt;/td&gt;
                     &lt;td&gt;
                        &lt;xsl:value-of select=&quot;price&quot;/&gt;
                     &lt;/td&gt;
                  &lt;/tr&gt;
               &lt;/xsl:for-each&gt;
            &lt;/table&gt;
         &lt;/body&gt;
      &lt;/html&gt;
   &lt;/xsl:template&gt;
&lt;/xsl:stylesheet&gt;
</pre>
<p>
The CFML file has the following lines:
</p>
<pre>&lt;cffile action=&quot;read&quot; file=&quot;C:\CFusionMX7\wwwroot\examples\custorder.xsl&quot; 
variable=&quot;xmltrans&quot;&gt;
&lt;cfset xmldoc = XmlParse(&quot;C:\CFusionMX7\wwwroot\examples\custorder.xml&quot;)&gt;
&lt;cfoutput&gt;#XmlTransform(xmldoc, xmltrans)#&lt;/cfoutput&gt;
</pre>
         </td>
      </tr>
   </table>
   </div>
<div id="XML ">
<table border="0" cellspacing="0" cellpadding="0" width="100%">
<tr>  
<td valign="top" class="name">XML </td>
  <td valign="top" nowrap class="compatibility">&nbsp;</td>
  </tr>
  <tr>
  <td colspan="2" class="divider"><img src="dwres:18084" width="100%" height="1"></td>
  </tr>


<p>An XML document in string format, or an XML document object</p>

  </td>
  </tr>
  </table>
</div>
<div id="XSL">
<table border="0" cellspacing="0" cellpadding="0" width="100%">
<tr>  
<td valign="top" class="name">XSL</td>
  <td valign="top" nowrap class="compatibility">&nbsp;</td>
  </tr>
  <tr>
  <td colspan="2" class="divider"><img src="dwres:18084" width="100%" height="1"></td>
  </tr>


<p>XSLT transformation to apply; can be any of the following:</p>
<p>Any of the following:</p><ul>

<li>A string containing XSL text.</li>

<li>The name of an XSTLT file. Relative paths start at the directory containing the current CFML page. </li>

<li>The URL of an XSLT file; valid protocol identifiers include http, https, ftp, and file. Relative paths start at the directory containing the current CFML page. </li>
</ul>


  </td>
  </tr>
  </table>
</div>
<div id="PARAMETERS">
<table border="0" cellspacing="0" cellpadding="0" width="100%">
<tr>  
<td valign="top" class="name">PARAMETERS</td>
  <td valign="top" nowrap class="compatibility">&nbsp;</td>
  </tr>
  <tr>
  <td colspan="2" class="divider"><img src="dwres:18084" width="100%" height="1"></td>
  </tr>


<p>A structure containing XSL template parameter name-value pairs to use in transforming the document. The XSL transform defined in the xslString parameter uses these parameter values in processing the XML.</p>

  </td>
  </tr>
  </table>
</div>

  </body>
</html>
