xml.transform()

Applies an Extensible Stylesheet Language Transformation (XSLT) to an XML document object that is represented as a string variable. An XSLT converts an XML document to another format or representation by applying an Extensible Stylesheet Language (XSL) stylesheet to it.

xml.transform( xsl=string, parameters=struct )

Returns: String

Argument Description
xsl
string, required

Alias: xslString, xslText

parameters
struct, optional

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.

Alias: params

Examples

styles = '
			<?xml version="1.0" encoding="UTF-8"?>
			<html xsl:version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
				<body style="font-family:Arial;font-size:12pt;background-color:##EEEEEE">
				<xsl:for-each select="notes/note">
					<div style="margin-bottom: 2.0em">
						<div style="background-color:teal;color:white;padding:4px">
							<div style="margin-bottom:1em;font-size: 1.2em; font-style: italic">
								<xsl:value-of select="heading"/>
							</div>
							<div style="font-size: 0.8em">
								From: <xsl:value-of select="from"/>
							</div>
							<div style="font-size: 0.8em">
								To: <xsl:value-of select="to"/>
							</div>
						</div>
						<div style="margin-top:1em;font-size: 0.9em">
							<xsl:value-of select="body"/>
						</div>
					</div>
				</xsl:for-each>
				</body>
			</html>
		';
		xml_stream = '
			<?xml version="1.0" encoding="UTF-8"?>
			<notes>
				<note>
					<to>Alice</to>
					<from>Bob</from>
					<heading>Reminder</heading>
					<body>Here is the message you requested.</body>
				</note>
			</notes>';
		xml_document = XmlParse(xml_stream);
		echo(xml_document.Transform(styles));

See also