Sophie

Sophie

distrib > Mandriva > 9.1 > ppc > media > main > by-pkgid > 0afeee9cca140e167a996902b9a677c5 > files > 2880

php-manual-en-4.3.0-2mdk.noarch.rpm

<HTML
><HEAD
><TITLE
>xslt_process</TITLE
><META
NAME="GENERATOR"
CONTENT="Modular DocBook HTML Stylesheet Version 1.7"><LINK
REL="HOME"
TITLE="PHP Manual"
HREF="index.html"><LINK
REL="UP"
TITLE="XSLT functions"
HREF="ref.xslt.html"><LINK
REL="PREVIOUS"
TITLE="xslt_free"
HREF="function.xslt-free.html"><LINK
REL="NEXT"
TITLE="xslt_set_base"
HREF="function.xslt-set-base.html"><META
HTTP-EQUIV="Content-type"
CONTENT="text/html; charset=ISO-8859-1"></HEAD
><BODY
CLASS="refentry"
BGCOLOR="#FFFFFF"
TEXT="#000000"
LINK="#0000FF"
VLINK="#840084"
ALINK="#0000FF"
><DIV
CLASS="NAVHEADER"
><TABLE
SUMMARY="Header navigation table"
WIDTH="100%"
BORDER="0"
CELLPADDING="0"
CELLSPACING="0"
><TR
><TH
COLSPAN="3"
ALIGN="center"
>PHP Manual</TH
></TR
><TR
><TD
WIDTH="10%"
ALIGN="left"
VALIGN="bottom"
><A
HREF="function.xslt-free.html"
ACCESSKEY="P"
>Prev</A
></TD
><TD
WIDTH="80%"
ALIGN="center"
VALIGN="bottom"
></TD
><TD
WIDTH="10%"
ALIGN="right"
VALIGN="bottom"
><A
HREF="function.xslt-set-base.html"
ACCESSKEY="N"
>Next</A
></TD
></TR
></TABLE
><HR
ALIGN="LEFT"
WIDTH="100%"></DIV
><H1
><A
NAME="function.xslt-process"
></A
>xslt_process</H1
><DIV
CLASS="refnamediv"
><A
NAME="AEN97215"
></A
><P
>    (PHP 4 &#62;= 4.0.3)</P
>xslt_process&nbsp;--&nbsp;Perform an XSLT transformation</DIV
><DIV
CLASS="refsect1"
><A
NAME="AEN97218"
></A
><H2
>Description</H2
>mixed <B
CLASS="methodname"
>xslt_process</B
> ( resource xh, string xmlcontainer, string xslcontainer [, string resultcontainer [, array arguments [, array parameters]]])<BR
></BR
><P
>&#13;     The <B
CLASS="function"
>xslt_process()</B
> function is the crux of the new
     XSLT extension.  It allows you to perform an XSLT transformation using
     almost any type of input source - the containers.  This is accomplished
     through the use of argument buffers -- a concept taken from the Sablotron
     XSLT processor (currently the only XSLT processor this extension supports).
     The input containers default to a filename 'containing' the document to be
     processed. The result container defaults to a filename for the transformed
     document. If the result container is not specified - i.e.
     <TT
CLASS="parameter"
><I
>NULL</I
></TT
> - than the result is returned.
    </P
><P
>&#13;     <DIV
CLASS="warning"
><P
></P
><TABLE
CLASS="warning"
BORDER="1"
WIDTH="100%"
><TR
><TD
ALIGN="CENTER"
><B
>Warning</B
></TD
></TR
><TR
><TD
ALIGN="LEFT"
><P
>&#13;       This function has changed it's arguments, sinceversion 4.0.6. Do NOT
       provide the actual xml or xsl content as 2nd and 3rd argument, as this
       will create a segmentation fault, in Sablotron versions up to and
       including 0.95.
      </P
></TD
></TR
></TABLE
></DIV
>
    </P
><P
>&#13;     Containers can also be set via the <TT
CLASS="parameter"
><I
>$arguments</I
></TT
>
  array (see below).
    </P
><P
>&#13;     The simplest type of transformation with the
     <B
CLASS="function"
>xslt_process()</B
> function is the transformation of an
     XML file with an XSLT file, placing the result in a third file containing
     the new XML (or HTML) document.  Doing this with sablotron is really
     quite easy...
    </P
><TABLE
WIDTH="100%"
BORDER="0"
CELLPADDING="0"
CELLSPACING="0"
CLASS="EXAMPLE"
><TR
><TD
><DIV
CLASS="example"
><A
NAME="AEN97251"
></A
><P
><B
>Example 1. Using the <B
CLASS="function"
>xslt_process()</B
> to transform an XML
     file and a XSL file to a new XML file</B
></P
><TABLE
BORDER="0"
BGCOLOR="#E0E0E0"
CELLPADDING="5"
><TR
><TD
><PRE
CLASS="php"
>&#60;?php

// Allocate a new XSLT processor
$xh = xslt_create();

// Process the document
if (xslt_process($xh, 'sample.xml', 'sample.xsl', 'result.xml')) {
    print "SUCCESS, sample.xml was transformed by sample.xsl into result.xml";
    print ", result.xml has the following contents\n&#60;br&#62;\n";
    print "&#60;pre&#62;\n";
    readfile('result.xml');
    print "&#60;/pre&#62;\n";
}
else {
    print "Sorry, sample.xml could not be transformed by sample.xsl into";
    print "  result.xml the reason is that " . xslt_error($xh) . " and the ";
    print "error code is " . xslt_errno($xh);
}

xslt_free($xh);

?&#62;</PRE
></TD
></TR
></TABLE
></DIV
></TD
></TR
></TABLE
><P
>&#13;     While this functionality is great, many times, especially in a web environment, you want to
     be able to print out your results directly.  Therefore, if you omit the third argument to 
     the <B
CLASS="function"
>xslt_process()</B
> function (or provide a NULL value for the argument), it 
     will automatically return the value of the XSLT transformation, instead of writing it to a 
     file...
    </P
><P
>&#13;     <TABLE
WIDTH="100%"
BORDER="0"
CELLPADDING="0"
CELLSPACING="0"
CLASS="EXAMPLE"
><TR
><TD
><DIV
CLASS="example"
><A
NAME="AEN97258"
></A
><P
><B
>Example 2. Using the <B
CLASS="function"
>xslt_process()</B
> to transform an XML file and a XSL file 
     to a variable containing the resulting XML data</B
></P
><TABLE
BORDER="0"
BGCOLOR="#E0E0E0"
CELLPADDING="5"
><TR
><TD
><PRE
CLASS="php"
>&#60;?php

// Allocate a new XSLT processor
$xh = xslt_create();

// Process the document, returning the result into the $result variable
$result = xslt_process($xh, 'sample.xml', 'sample.xsl');
if ($result) {
    print "SUCCESS, sample.xml was transformed by sample.xsl into the \$result";
    print " variable, the \$result variable has the following contents\n&#60;br&#62;\n";
    print "&#60;pre&#62;\n";
    print $result;
    print "&#60;/pre&#62;\n";
}
else {
    print "Sorry, sample.xml could not be transformed by sample.xsl into";
    print "  the \$result variable the reason is that " . xslt_error($xh) . 
    print " and the error code is " . xslt_errno($xh);
}

xslt_free($xh);

?&#62;</PRE
></TD
></TR
></TABLE
></DIV
></TD
></TR
></TABLE
>
    </P
><P
>&#13;     The above two cases are the two simplest cases there are when it comes to XSLT transformation
     and I'd dare say that they are the most common cases, however, sometimes you get your XML and
     XSLT code from external sources, such as a database or a socket.  In these cases you'll have 
     the XML and/or XSLT data in a variable -- and in production applications the overhead of dumping
     these to file may be too much.  This is where XSLT's "argument" syntax, comes to the 
     rescue.  Instead of files as the XML and XSLT arguments to the <B
CLASS="function"
>xslt_process()</B
>
     function, you can specify "argument place holders" which are then subsituted by values
     given in the arguments array (5th parameter to the <B
CLASS="function"
>xslt_process()</B
> function).  
     The following is an example of processing XML and XSLT into a result variable without the use 
     of files at all.
    </P
><P
>&#13;     <TABLE
WIDTH="100%"
BORDER="0"
CELLPADDING="0"
CELLSPACING="0"
CLASS="EXAMPLE"
><TR
><TD
><DIV
CLASS="example"
><A
NAME="AEN97266"
></A
><P
><B
>Example 3. Using the <B
CLASS="function"
>xslt_process()</B
> to transform a variable containing XML data 
     and a variable containing XSL data into a variable containing the resulting XML data</B
></P
><TABLE
BORDER="0"
BGCOLOR="#E0E0E0"
CELLPADDING="5"
><TR
><TD
><PRE
CLASS="php"
>&#60;?php
// $xml and $xsl contain the XML and XSL data

$arguments = array(
     '/_xml' =&#62; $xml,
     '/_xsl' =&#62; $xsl
);

// Allocate a new XSLT processor
$xh = xslt_create();

// Process the document
$result = xslt_process($xh, 'arg:/_xml', 'arg:/_xsl', NULL, $arguments); 
if ($result) {
    print "SUCCESS, sample.xml was transformed by sample.xsl into the \$result";
    print " variable, the \$result variable has the following contents\n&#60;br&#62;\n";
    print "&#60;pre&#62;\n";
    print $result;
    print "&#60;/pre&#62;\n";
}
else {
    print "Sorry, sample.xml could not be transformed by sample.xsl into";
    print "  the \$result variable the reason is that " . xslt_error($xh) . 
    print " and the error code is " . xslt_errno($xh);
}
xslt_free($xh);
?&#62;</PRE
></TD
></TR
></TABLE
></DIV
></TD
></TR
></TABLE
>
    </P
><P
>&#13;     Finally, the last argument to the <B
CLASS="function"
>xslt_process()</B
>
     function represents an array for any top-level parameters that you want to
      pass to the XSLT document.  These parameters can then be accessed within
     your XSL files using the &#60;xsl:param name="parameter_name"&#62;
     instruction. The parameters must be UTF-8 encoded and their values will be
     interpreted as strings by the Sablotron processor. In other words - you
     cannot pass node-sets as parameters to the XSLT document.
    </P
><DIV
CLASS="note"
><BLOCKQUOTE
CLASS="note"
><P
><B
>Note: </B
>

      Please note that <SPAN
CLASS="emphasis"
><I
CLASS="emphasis"
>file://</I
></SPAN
> is needed in front of path if you use Windows.

     </P
></BLOCKQUOTE
></DIV
></DIV
><DIV
CLASS="NAVFOOTER"
><HR
ALIGN="LEFT"
WIDTH="100%"><TABLE
SUMMARY="Footer navigation table"
WIDTH="100%"
BORDER="0"
CELLPADDING="0"
CELLSPACING="0"
><TR
><TD
WIDTH="33%"
ALIGN="left"
VALIGN="top"
><A
HREF="function.xslt-free.html"
ACCESSKEY="P"
>Prev</A
></TD
><TD
WIDTH="34%"
ALIGN="center"
VALIGN="top"
><A
HREF="index.html"
ACCESSKEY="H"
>Home</A
></TD
><TD
WIDTH="33%"
ALIGN="right"
VALIGN="top"
><A
HREF="function.xslt-set-base.html"
ACCESSKEY="N"
>Next</A
></TD
></TR
><TR
><TD
WIDTH="33%"
ALIGN="left"
VALIGN="top"
>xslt_free</TD
><TD
WIDTH="34%"
ALIGN="center"
VALIGN="top"
><A
HREF="ref.xslt.html"
ACCESSKEY="U"
>Up</A
></TD
><TD
WIDTH="33%"
ALIGN="right"
VALIGN="top"
>xslt_set_base</TD
></TR
></TABLE
></DIV
></BODY
></HTML
>