XmlTransform()

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.

XmlTransform( xml=any, xsl=string, parameters=struct );

Returns: String

Argument Description
xml
any, required

An XML document in string format, or an XML document object

Alias: xmlNode, xmlObj, xmlDoc, node

xsl
string, required

A string containing XSL text

Alias: xslString, xslText

Unimplemented Argument(s)

Argument Description
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

* unimplemented *

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>
		';
	<span class="nv">xml_stream</span> <span class="o">=</span> <span class="err">&#39;</span>
		<span class="o">&lt;</span><span class="err">?</span><span class="nv">xml</span> <span class="nv">version</span><span class="o">=</span><span class="s2">&quot;1.0&quot;</span> <span class="nv">encoding</span><span class="o">=</span><span class="s2">&quot;UTF-8&quot;</span><span class="err">?</span><span class="o">&gt;</span>
		<span class="o">&lt;</span><span class="nv">notes</span><span class="o">&gt;</span>
			<span class="o">&lt;</span><span class="nv">note</span><span class="o">&gt;</span>
				<span class="o">&lt;</span><span class="nv">to</span><span class="o">&gt;</span><span class="nv">Alice</span><span class="o">&lt;/</span><span class="nv">to</span><span class="o">&gt;</span>
				<span class="o">&lt;</span><span class="nv">from</span><span class="o">&gt;</span><span class="nv">Bob</span><span class="o">&lt;/</span><span class="nv">from</span><span class="o">&gt;</span>
				<span class="o">&lt;</span><span class="nv">heading</span><span class="o">&gt;</span><span class="nv">Reminder</span><span class="o">&lt;/</span><span class="nv">heading</span><span class="o">&gt;</span>
				<span class="o">&lt;</span><span class="nv">body</span><span class="o">&gt;</span><span class="nv">Here</span> <span class="o">is</span> <span class="nv">the</span> <span class="nv">message</span> <span class="nv">you</span> <span class="nv">requested.</span><span class="o">&lt;/</span><span class="nv">body</span><span class="o">&gt;</span>
			<span class="o">&lt;/</span><span class="nv">note</span><span class="o">&gt;</span>
			<span class="o">&lt;</span><span class="nv">note</span><span class="o">&gt;</span>
				<span class="o">&lt;</span><span class="nv">to</span><span class="o">&gt;</span><span class="nv">Bob</span><span class="o">&lt;/</span><span class="nv">to</span><span class="o">&gt;</span>
				<span class="o">&lt;</span><span class="nv">from</span><span class="o">&gt;</span><span class="nv">Alice</span><span class="o">&lt;/</span><span class="nv">from</span><span class="o">&gt;</span>
				<span class="o">&lt;</span><span class="nv">heading</span><span class="o">&gt;</span><span class="nv">Your</span> <span class="nv">request</span><span class="o">&lt;/</span><span class="nv">heading</span><span class="o">&gt;</span>
				<span class="o">&lt;</span><span class="nv">body</span><span class="o">&gt;</span><span class="nv">I</span> <span class="nv">got</span> <span class="nv">your</span> <span class="nv">message</span><span class="p">;</span> <span class="nv">all</span> <span class="o">is</span> <span class="nv">well.</span><span class="o">&lt;/</span><span class="nv">body</span><span class="o">&gt;</span>
			<span class="o">&lt;/</span><span class="nv">note</span><span class="o">&gt;</span>
		<span class="o">&lt;/</span><span class="nv">notes</span><span class="o">&gt;</span><span class="err">&#39;</span><span class="p">;</span>
	<span class="nv">xml_document</span> <span class="o">=</span> <span class="nf">XmlParse</span><span class="p">(</span><span class="nv">xml_stream</span><span class="p">);</span>
	<span class="nf">echo</span><span class="p">(</span><span class="nf">xmlTransform</span><span class="p">(</span><span class="nv">xml_document</span><span class="p">,</span><span class="nv">styles</span><span class="p">));</span>

See also