php “XSLTProcessor::setParameter” function

xmltransform.php
<?php
$xml= new DOMDocument();
$xml-> load(“testparam.xml”);

$xsl= new DOMDocument();
$xsl-> load(“testparam.xsl”);

$xsltproc= new XSLTProcessor();
$xsltproc-> importStylesheet($xsl);

$variable= “myvalue”;    //this part for passing parameter ‘myparam’ to xsl
$xsltproc->setParameter(”, ‘myparam’, $variable);

echo $xsltproc->transformToXML($xml);
?>

——————————————————————————————

testparam.xsl

<?xml version=”1.0″?>
<xsl:stylesheet version=”1.0″ xmlns:xsl=”http://www.w3.org/1999/XSL/Transform”&gt;
<xsl:template match=”/”>
<html>
<body>
–<p style=”color:red;”> Value parameter: <xsl:value-of select=”$myparam”/></p>
–<h2>Parameter works everywhere</h2>
–<table border=”1″>

—–<xsl:for-each select=”mytestnode”>

——–<tr>
———–<td> <xsl:value-of select=”$myparam”/> </td>
——-</tr>

—–</xsl:for-each>
–</table>

</body>
</html>
</xsl:template>
</xsl:stylesheet>

2 thoughts on “php “XSLTProcessor::setParameter” function

Please Leave a Comment

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s