note 46928 deleted from function.xsl-xsltprocessor-get-parameter by didou
| From: | didou@php.net | Date: | Mon, 27 Dec 2004 22:30:21 +0000 |
| Subject: | note 46928 deleted from function.xsl-xsltprocessor-get-parameter by didou | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-82378@lists.php.net to get a copy of this message | ||
Note Submitter: gem at rellim dot com
----
Here is an example of getParameter(), setParameter() and removeParameter()
<?php
# enable all warnings
ini_set('error_reporting', E_ALL | E_STRICT);
# a simple xsl template as a string
$xsl_str = <<<EOT
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:param name="version" >3</xsl:param>
</xsl:stylesheet>
EOT;
# load the XSL template into a DOM document
$xsl = new DomDocument;
$xsl->loadXML( $xsl_str );
# create a new processor object
$proc = new xsltprocessor;
# this shows the new proc is empty and reading an empty param is not a PHP Warning
echo "Step 1: " . $proc->getParameter("","version") .
"\n";
# import the Style Sheet in to the processor
$proc->importStyleSheet($xsl);
# unable to read param "version" from proc with default name space
echo "Step 2: " . $proc->getParameter("","version") .
"\n";
# unable to read param "version" from proc with specified name space
echo "Step 3: " . $proc->getParameter("http://www.w3.org/1999/XSL/Transform"
,"version") . "\n";
# set param "version"
$proc->setParameter("","version", 2);
# read back param "version"
echo "Step 4: " . $proc->getParameter("","version") .
"\n";
# remove param "version"
$proc->removeParameter("","version");
# attempt to read removed param "version"
echo "Step 5: " . $proc->getParameter("","version") .
"\n";
?>
Run it and you get these results with PHP 5.0.2:
# php tmp.php
Step 1:
Step 2:
Step 3:
Step 4: 2
Step 5:
Looks like if you want to read a parameter from an XSL template you need to get it from the DOM
object and not the xlstprocessor object.