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

search for in the

XSLTProcessor::registerPHPFunctions> <XSLTProcessor::hasExsltSupport
[edit] Last updated: Fri, 25 May 2012

view this page in

XSLTProcessor::importStylesheet

(PHP 5)

XSLTProcessor::importStylesheetImporte une feuille de style

Description

void XSLTProcessor::importStylesheet ( object $stylesheet )

Cette méthode importe une feuille de style dans le XSLTProcessor pour transformations.

Liste de paramètres

stylesheet

La feuille de style importée en tant qu'objet DOMDocument ou objet SimpleXMLElement.

Valeurs de retour

Aucune valeur n'est retournée.

Historique

Version Description
5.2.8 Accepte de nouveau SimpleXMLElement depuis PHP 5.2.6 alors qu'il était cassé auparavant.



add a note add a note User Contributed Notes XSLTProcessor::importStylesheet
mishak@mishak 16-Jun-2011 05:09
actually return value is bool, returns true on success and false on error.
kevin at metalaxe dot com 17-Nov-2007 03:26
Just for reference, as of this writing, this function does not support importing multiple stylesheets. The following will output only the stylesheet transformation of the second imported sheet:

<?php

# LOAD XML FILE
$XML = new DOMDocument();
$XML->load( 'data.xml' );

# START XSLT
$xslt = new XSLTProcessor();

# IMPORT STYLESHEET 1
$XSL = new DOMDocument();
$XSL->load( 'template1.xsl' );
$xslt->importStylesheet( $XSL );

#IMPORT STYLESHEET 2
$XSL = new DOMDocument();
$XSL->load( 'template2.xsl' );
$xslt->importStylesheet( $XSL );

#PRINT
print $xslt->transformToXML( $XML );
?>

This wasn't documented and quite dissapointing.
fcartegnie 21-Jul-2007 06:11
PHP5 xsl processor has a different behaviour than PHP4's one with CDATA sections. (see http://bugs.php.net/bug.php?id=29837)
Loaded XSL sheet CDATA sections does not allow, by default, output-escaping handling (everything in the CDATA is escaped by default).

So in this case you can't build your XSL Dom the usual way:
    $xsldom = DomDocument::loadXML(file_get_contents('sheet.xsl'));

and must go through this one (allowing LIBXML_NOCDATA parameter):
    $xsldom = new DomDocument;
    $xsldom->load('sheet.xsl', LIBXML_NOCDATA);

Then the CDATA output-escaping behaviour will be correct.
diesel at spbnet dot ru 19-Mar-2007 09:07
This is not a problem. You may set DOMDocument's documentURI property.
Something like this

<?php
$xsl
= new DOMDocument('1.0','UTF-8');
    
$xsl->loadXML(file_get_contents('/foo/bar/somefile.xsl');
$xsl->documentURI = '/foo/bar/somefile.xsl';

$xslProc = new XSLTProcessor();
$xslProc->importStylesheet($xsl);
?>

and document('other.xsl') will work fine!
bbrosseau at gmail 01-Mar-2005 08:46
For those who wants to use external documents, it is important not to use the DomDocument::loadXML because the processor will not have the path to look for other files
 
So if you want to transform some xml with a pre-generated stylesheet $f:

<?php
$f
= 'somestylesheet.xsl';
$xsl = DomDocument::loadXML(file_get_contents($f));
?>

document('other.xml') will not work with relative path and <?php $xsl = DomDocument::load($f); ?> will!

 
show source | credits | sitemap | contact | advertising | mirror sites