note 75024 added to function.xsl-xsltprocessor-set-parameter
| From: | brettz9 at osu1 dot php dot net | Date: | Wed, 09 May 2007 03:27:26 +0000 |
| Subject: | note 75024 added to function.xsl-xsltprocessor-set-parameter | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-126347@lists.php.net to get a copy of this message | ||
It seems heinemann's usage is not correct and does not achieve the intended result.
This method's purpose is to change a global <xsl:param> value in the XSL stylesheet--not
to change an attribute of any other element. <xsl:param> basically lets you set up a
stylesheet which can be customized (as from PHP) externally (without needing to tamper with the
original XSL file).
Here's an example of usage (that will work):
Stylesheet:
<?xml version="1.0"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:param name="print_something" select="defaultstring"/>
<xsl:template match="/mydoc">
<p style="color:red;">Printed parameter: <xsl:value-of
select="$print_something"/></p>
</xsl:template>
</xsl:stylesheet>
Script:
<?php
$dom = new DOMDocument();
$xsl = new XSLTProcessor;
$xsl->setParameter( '', 'print_something', "Now I've overridden the
default!");
$style = realpath( "./my_stylesheet.xslt" );
$dom->load($style);
$xsl->importStyleSheet($dom);
$dom->loadXML('<mydoc></mydoc>');
$out = $xsl->transformToXML( $dom );
var_dump( '<pre>',
htmlentities( $out, ENT_QUOTES, 'utf-8' ),
$xsl->getParameter('', 'print_something'),
'</pre>' );
?>
gives:
string(5) "
"
string(143) "<?xml version="1.0"?>
<p style="color:red;">Printed parameter: Now I've overridden the
default!</p>
"
string(32) "Now I've overridden the default!"
string(6) "
"
Notice that at present adding a namespace will not work. The only option at present is to set the
first parameter for namespace to an empty string (though you can add the prefix with colon to the
second argument for name in order to set the parameter for a namespace-prefixed parameter name).
See http://bugs.php.net/bug.php?id=30622
----
Server IP: 60.191.90.110
Probable Submitter: 218.18.226.215
----
Manual Page -- http://www.php.net/manual/en/function.xsl-xsltprocessor-set-parameter.php
Edit -- https://master.php.net/note/edit/75024
Del: integrated -- https://master.php.net/note/delete/75024/integrated
Del: useless -- https://master.php.net/note/delete/75024/useless
Del: bad code -- https://master.php.net/note/delete/75024/bad+code
Del: spam -- https://master.php.net/note/delete/75024/spam
Del: non-english -- https://master.php.net/note/delete/75024/non-english
Del: in docs -- https://master.php.net/note/delete/75024/in+docs
Del: other reasons-- https://master.php.net/note/delete/75024
Reject -- https://master.php.net/note/reject/75024
Search -- https://master.php.net/manage/user-notes.php