PHP: XSLTProcessor->setParameter() - Manual

downloads | documentation | faq | getting help | mailing lists | reporting bugs | php.net sites | links | conferences | my php.net

search for in the

XSLTProcessor->transformToDoc() XSLTProcessor->removeParameter()

Last updated: Sat, 27 Jan 2007

view this page in

# XSLTProcessor->setParameter()

(no version information, might be only in CVS)

XSLTProcessor->setParameter() -- Set value for a parameter

## Описание

class XSLTProcessor {
bool setParameter ( string namespace, string name, string value )
}class XSLTProcessor {
bool setParameter ( string namespace, array options )
}

Sets the value of one or more parameters to be used in subsequent transformations with XSLTProcessor. If the parameter doesn't exist in the stylesheet it will be ignored.

## Список параметров

`namespace`

  The namespace URI of the XSLT parameter.

`name`

  The local name of the XSLT parameter.

`value`

  The new value of the XSLT parameter.

`options`

  An array of `name => value` pairs. This syntax is available since PHP 5.1.0.

## Возвращаемые значения

Возвращает `TRUE` в случае успешного завершения или `FALSE` в случае возникновения ошибки.

## Примеры

Пример 1. Changing the owner before the transformation

`<?php
$collections = array(
'Marc Rutkowski' => 'marc',
'Olivier Parmentier' => 'olivier'
);
$xsl = new DOMDocument;
$xsl->load('collection.xsl');
// Configure the transformer
$proc = new XSLTProcessor;
$proc->importStyleSheet($xsl); // attach the xsl rules
foreach ($collections as $name => $file) {
// Load the XML source
$xml = new DOMDocument;
$xml->load('collection_' . $file . '.xml');
$proc->setParameter('', 'owner', $name);
$proc->transformToURI($xml, 'file:///tmp/' . $file . '.html');
}
?>`

## Смотрите также

XSLTProcessor->getParameter()
XSLTProcessor->removeParameter()

add a note User Contributed Notes
XSLTProcessor->setParameter()
heinemann dot juergen at hjcms dot de
07-Mar-2006 03:39
`Example for how it works.
<?xml version = '1.0' encoding = 'utf-8' ?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml"
indent="yes"
encoding="ISO-8859-15"
doctype-system = "-//W3C//DTD XHTML 1.0 Transitional//EN"
doctype-public = "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"
/>
<xsl:template match="docs">
<html>
<head>
<title>
<xsl:text>Example</xsl:text>
</title>
</head>
<body>
<xsl:for-each select="block">
<div>
<xsl:value-of select="." />
</div>
</xsl:for-each>
</body>
</html>
</xsl:template>
</xsl:stylesheet>
------------------
<?php
$dom = new DomDocument( '1.0', 'utf-8' );
$xsl = new XSLTProcessor;
$xsl->setParameter( 'block', 'xmlns', 'http://www.w3.org/1999/xhtml' );
$style = realpath( "./my_stylesheet.xslt" );
$dom->load( $style );
$xsl->importStyleSheet( $dom );
$dom->loadXML( '<docs>
<block>Howto set xhtml Transitional Namespaces width php</block>
<block>see http://www.php.net</block>
</docs>' );
$out = $xsl->transformToXML( $dom );
var_dump( '<pre>',
htmlentities( $out, ENT_QUOTES, 'utf-8' ),
$xsl->getParameter( 'block', 'xmlns' ),
$xsl->getParameter( 'docs', 'xmlns' ),
'</pre>' );
?>`
Stoke A
11-Aug-2005 03:40
`XSLTProcessor::removeParameter() won't work on parameters set via XSLTProcessor::setParameter(string namespace, array options) in 5.1+ -- they need to be set and removed one by one.`
add a note
XSLTProcessor->transformToDoc() XSLTProcessor->removeParameter()

Last updated: Sat, 27 Jan 2007
show source | credits | stats | sitemap | contact | advertising | mirror sites
Copyright © 2001-2007 The PHP Group
All rights reserved.
This mirror generously provided by: Yahoo! Inc.
Last updated: Sat Mar 10 10:36:09 2007 PST