Skip to Main Content
Programming ColdFusion MX, 2nd Edition
book

Programming ColdFusion MX, 2nd Edition

by Rob Brooks-Bilson
August 2003
Intermediate to advanced content levelIntermediate to advanced
1140 pages
68h 45m
English
O'Reilly Media, Inc.
Content preview from Programming ColdFusion MX, 2nd Edition

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 ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Programming ColdFusion

Programming ColdFusion

Rob Brooks-Bilson

Publisher Resources

ISBN: 0596003803Supplemental ContentErrata Page