PHP Doku:: Erzeugt einen neuen XSLT-Prozessor - function.xslt-create.html

Verlauf / Chronik / History: (2) anzeigen

Sie sind hier:
Doku-StartseitePHP-HandbuchFunktionsreferenzXML-ManipulationXSLTXSLT Funktionenxslt_create

Ein Service von Reinhard Neidl - Webprogrammierung.

XSLT Funktionen

<<xslt_backend_version

xslt_errno>>

xslt_create

(PHP 4 >= 4.0.3)

xslt_createErzeugt einen neuen XSLT-Prozessor

Beschreibung

resource xslt_create ( void )

Erzeugt eine neue XSLT-Prozessor-Ressource für die Verarbeitung durch andere XSLT-Funktionen und gibt sie zurück.

Rückgabewerte

Gibt bei Erfolg einen XSLT-Prozessor-Linkidentifier zurück, im Fehlerfall wird FALSE zurückgegeben.

Beispiele

Beispiel #1 xslt_create()-Beispiel

<?php
function xml2html($xmldata$xsl)
{
    
/* $xmldata -> Ihr XML */
    /* $xsl -> XSLT-Datei */

    
$path 'include';
    
$arguments = array('/_xml' => $xmldata);
    
$xsltproc xslt_create();
    
xslt_set_encoding($xsltproc'ISO-8859-1');
    
$html =
        
xslt_process($xsltproc'arg:/_xml'"$path/$xsl"NULL$arguments);

    if (empty(
$html)) {
       die(
'XSLT processing error: 'xslt_error($xsltproc));
    }
    
xslt_free($xsltproc);
    return 
$html;
}
?>

Siehe auch


5 BenutzerBeiträge:
- Beiträge aktualisieren...
LW
28.08.2008 10:41
Hello,

I changed the function from myadzel (?) a little bit, so that it now correctly uses either a file OR a string as parameter - WITHOUT producing PHP warnings. See here:

<?php
function xslt ($xml, $xsl) {

   
$xh = @xslt_create();

   
$args['xml'] = ( file_exists( $xml ) )?join ('', file ($xml)):$xml;
   
$args['xsl'] = ( file_exists( $xsl ) )?join ('', file ($xsl)):$xsl;

   
// try with a string
   
$result = @xslt_process ($xh, 'arg:/xml', 'arg:/xsl', NULL, $args);

   
// try with resource
   
if (!$result) { $result = @xslt_process ($xh, $xml, $xsl); }

    @
xslt_free ($xh);
    return
$result;

}
?>

Examples:
echo xslt ('./index.xml', './index.xsl');
echo xslt ('<test><example>An example!</example></test>', './index.xsl');
sxguard-1trail(At)yahoo dot com
6.06.2008 5:12
Hardly can I find this. But, those required dll is not included in the package and no link for download.

It's a pitty that no discussion about this within php.net

  Note   to   Win32   Users:     In   order   to   enable   this   module   on   a   Windows   environment,   you   must   copy   several   files   from   the   DLL   folder   of   the   PHP/Win32   binary   package   to   the   SYSTEM32   folder   of   your   windows   machine.   (Ex:   C:\WINNT\SYSTEM32   or   C:\WINDOWS\SYSTEM32).   For   PHP   <=   4.2.0   copy   sablot.dll     and   expat.dll   to   your   SYSTEM32   folder.   For   PHP   >=   4.2.1   copy   sablot.dll,   expat.dll   and   iconv.dll   to   your   SYSTEM32   folder.
myadzel at gmail dot com
20.03.2007 17:26
All for a long time know about a problem xslt-transformation in php.
We shall try a trivial way, knowing, that xslt_process () accepts string or resources in it's parameters.

function xslt ($xml, $xsl) {

    $xh = @xslt_create();

    $args['xml'] = join ('', file ($xml));
    $args['xsl'] = join ('', file ($xsl));

    // try with a string
    $result = @xslt_process ($xh, 'arg:/xml', 'arg:/xsl', NULL, $args);

    // try with resource
    if (!$result) { $result = @xslt_process ($xh, $xml, $xsl); }

    @xslt_free ($xh);
    return $result;

}

For example: echo xslt ('./index.xml', './index.xsl');
Kerry Kobashi
29.03.2005 5:29
It should be noted that xslt_create() will return FALSE in the case of failure (Sablotron processor could not be created).

This, obtained from looking at the source code extension.
garth at webconexion dot net
18.09.2003 14:23
In order to pass PHP variables into an XSL document you need to do the following:

Firstly I created the following function to use:

function GetXHTML($sXML, $sXSL, $aParameters)
{
    $hXML = xslt_create();
    $aArguments = array('/_xml' => $sXML, '/_xsl' => $sXSL);
    $sXHTML = xslt_process($hXML, 'arg:/_xml', 'arg:/_xsl', NULL, $aArguments, $aParameters);
    xslt_free($hXML);
    return $sXHTML;
}

Then call it like thus, passing the XML and XSL as a string with the final parameter being an array which can contain as many values as you wish to pass in:

$sXHTML = GetXHTML($sXML, $sXSL, array("age"=>"26"));

Then in the XSL document you need the following:

<xsl:param name="age" />

Then where you want to display the value of age you do this:

<xsl:value-of select="$age" />

Thanks now.



PHP Powered Diese Seite bei php.net
The PHP manual text and comments are covered by the Creative Commons Attribution 3.0 License © the PHP Documentation Group - Impressum - mail("TO:Reinhard Neidl",...)