xslt_process

(PHP 4 >= 4.0.3)

xslt_process -- Transform XML data through a string containing XSL data

Description

bool xslt_process (string xsl_data, string xml_data, string result)

Waarschuwing

Deze functie is EXPERIMENTEEL. Dat betekent, dat het gedrag van deze functie, deze functienaam, in concreto ALLES dat hier gedocumenteerd is in een toekomstige uitgave van PHP ZONDER WAARSCHUWING kan veranderen. Wees gewaarschuwd, en gebruik deze functie op eigen risico.

The xslt_process() takes a string containing the XSLT stylesheet as its first argument, it takes a second string containing the XML data you want to transform and then a third string containing the results of the transformation. xslt_process() will return TRUE on success and FALSE on failure, to get the error number and error string if an error occurs use the xslt_errno() and xslt_error() functions.

Voorbeeld 1. Using the xslt_process() to transform three strings


<?php

$xslData = '<xsl:stylesheet
  version="1.0"
  xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

<xsl:template match="article">
    <table border="1" cellpadding="2" cellspacing="1">
        <tr>
            <td width="20%">
             &#160;
            </td>
            <td width="80%">
                <h2><xsl:value-of select="title"/></h2>
                <h3><xsl:value-of select="author"/></h3>
                <br/>
                
                <xsl:copy-of select="p"/>
            </td>
        </tr>
    </table>
</xsl:template>

</xsl:stylesheet>';

$xmlData = '<?xml version="1.0"?>
<article>
    <title>Learning German</title>
    <author>Sterling Hughes</author>
    <p>
        Essential phrases:
        <br/>
        K&#246;nnen Sie mir sagen, wo die Toilette ist?<br/>
        Ein grosses Bier, bitte!<br/>
        Noch eins, bitte.<br/>
    </p>
</article>';

if (xslt_process($xslData, $xmlData, $result)) {
    echo "Here is the brilliant in-depth article on learning";
    echo " German: ";
    echo "<br>\n<br>";
    echo $result;
} else {
    echo "There was an error that occurred in the XSL transformation...\n";
    echo "\tError number: " . xslt_errno() . "\n";
    echo "\tError string: " . xslt_error() . "\n";
    exit;
}
?>