Name

XmlTransform

Synopsis

                  
                  XmlTransform(XmlString|XmlDocObj, XslString)

Performs an XSLT (eXtensible Stylesheet Language Transformation) on an XML string or document object using an XSL (eXtensible Style Language) string. The results are returned as a string. The following example reads in an XML document containing employee names and titles:

<?xml version='1.0' standalone='yes'?>
<company>
  <employee>
    <name>Pere Money</name>
    <title>President</title>
  </employee>
  <employee>
    <name>Aaron Ridge</name>
    <title>Analyst</title>
  </employee>
  <employee>
    <name>Martin Grant</name>
    <title>Manager</title>
  </employee>
</company>

The example then reads in a simple XSL file for formatting the XML as HTML:

<xsl:stylesheet 
  xmlns:xsl="http://www.w3.org/1999/XSL/Transform" 
  version="1.0">
  <xsl:output method="html"/>
          
  <xsl:template match="/company">
    <html>
      <head>
        <title>Employees</title>
      </head>
      <body>
      <table border="1"> 
        <tr>
          <th>Name</th>
          <th>Title</th>
        </tr>
      <xsl:apply-templates select="employee"/>
      </table>
      </body>
    </html>
  </xsl:template>
  
  <xsl:template match="employee">
    <tr>
      <td><xsl:value-of select="name"/></td>
      <td><xsl:value-of select="title"/></td>
    </tr>
  </xsl:template>
</xsl:stylesheet>

Finally, the XML is transformed using XmlTransform( ), and the resulting HTML table is output to the browser:

<cffile action="read" file="d:\cfusionmx\wwwroot\programmingcf\b\employee.xml" variable="MyXml"> <cffile action="read" file="d:\cfusionmx\wwwroot\programmingcf\b\employee.xsl" variable="MyXsl"> <cfset Transformed ...

Get Programming ColdFusion MX, 2nd Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.