..
Cold Fusion can very easily make the transformation to an XML file using XSLT CFHTTP the command to retrieve the XML file, even remote.
Before moving on to the CFML code example, create an XML file and an XSLT file test, the first and the second will be called database.xml style.xsl. Here are the codes:
database.xml
<? Xml version = "1.0"?>
<database>
<record>
<name> Joseph </ name>
<Last Green </ name>
</ Record>
<record>
<name> Antonio </ name>
<Last White </ surname>
</ Record>
<record>
<name> Mario </ name>
<Last Smith </ name>
</ Record>
</ Database>
style.xsl
<? Xml version = "1.0" encoding = "ISO-8859-1"?>
<Xsl: stylesheet version = "1.0"
xmlns: xsl = "http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/">
<h1> User List </ h1>
<table border="1">
<tr>
<th align="left"> Name </ th>
<th align="left"> Last Name </ th>
</ Tr>
<xsl:for-each select="database/record">
<tr>
<td> <xsl:value-of select="nome"/> </ td>
<td> <xsl:value-of select="cognome"/> </ td>
</ Tr>
</ Xsl: for-each>
</ Table>
</ Xsl: template>
</ Xsl: stylesheet>
Follow the links below for more information on XML and XSLT .
Moving on to the CFML code.
Let's start with the location of the XML file, using the method of sending data and not resolve the URL of the file:
<CFHTTP Url="database.xml" method="GET" resolveurl="false">Now localize the XSLT file:
<CFSET Mio_xslt = ExpandPath("style.xsl")>
After we read the XSLT file located:
<CFFILE ACTION="READ" FILE="#mio_xslt#" VARIABLE="var_xslt">Physically carry out the transformation mapping the XML file and the XSLT file using the XMLTransform ():
Result = <CFSET XMLTransform(CFHTTP.fileContent, var_xslt)>Outputting the result of the transformation on the page:
<cfoutput> # result # </ cfoutput>Here is the complete code of the application:
<CFHTTP Url="database.xml" method="GET" resolveurl="false">
<CFSET Mio_xslt = ExpandPath("style.xsl")>
<CFFILE ACTION="READ" FILE="#mio_xslt#" VARIABLE="var_xslt">
Result = <CFSET XMLTransform(CFHTTP.fileContent, var_xslt)>
<cfoutput> # result # </ cfoutput>
| |
ASP (Advanced)
Full course for creating dynamic Web sites. From 39 €. |
| |
MS Access (Advanced)
Learn how to create and manage databases quickly and easily. Starting from 29 €. |
| |
MySQL (Course)
Management of open-source database. From 39 €. |