User Guide

Table Of Contents
Extracting data with XPath 869
Transforming documents with XSLT
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)
stylesheet. (When stored in a file, XSL stylesheets typically have the suffix xsl.) 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 stylesheet in string format, and returns the transformed document as a string.
The following code:
1.
Reads the simpletransform.xsl stylesheet file into a string variable.
2.
Uses the stylesheet to transform the mydoc XML document object.
3.
Saves the resulting transformed document in a second file.
<cffile action="read"
file="C:\CFusionMX7\wwwroot\testdocs\simpletransform.xsl"
variable="xslDoc">
<cfset transformedXML = XmlTransform(mydoc, xslDoc)>
<cffile action="write"
file="C:\CFusionMX7\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 stylesheets, see the W3C website at
www.w3.org/Style/XSL/. There are also several books available on using XSL and XSLT.
Extracting data with XPath
XPath is a language for addressing parts of an XML document. Like XSL, XPath is a W3C
specification. One of the major uses of XPath is in XSL transformations. However, XPath has
more general uses. In particular, it can extract data from XML documents, such as complex data
set representations. Thus, XPath is another data querying tool.
XPath uses a pattern called an XPath expression to specify the information to extract from an
XML document. For example, the simple XPath expression /employee/name selects the name
elements in the employee root element.
The
XmlSearch function uses XPath expressions to extract data from XML document objects.
The function takes an XML document object and an XPath expression in string format, and
returns an array of XML document objects containing the elements that meet the expression
criteria.