File: xslt.xml

package info (click to toggle)
phpdoc 20020310-1
  • links: PTS
  • area: main
  • in suites: woody
  • size: 35,272 kB
  • ctags: 354
  • sloc: xml: 799,767; php: 1,395; cpp: 500; makefile: 200; sh: 140; awk: 51
file content (584 lines) | stat: -rw-r--r-- 19,259 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
<?xml version="1.0" encoding="iso-8859-1"?>
<!-- $Revision: 1.32 $ -->
 <reference id="ref.xslt">
  <title>XSLT functions</title>
  <titleabbrev>XSLT</titleabbrev>

  <partintro>
   <sect1 id="xslt.partintro">
    <title>Introduction</title>

    <sect2 id="xslt.intro">
     <title>About XSLT and Sablotron</title>
     <para>
      XSLT (Extensible Stylesheet Language (XSL)
      Transformations) is a language for transforming XML
      documents into other XML documents.  It is a standard
      defined by The World Wide Web consortium (W3C). 
      Information about XSLT and related technologies can be
      found at <ulink url="&url.xslt;">&url.xslt;</ulink>.
     </para>
    </sect2>

    <sect2 id="xslt.install">
     <title>Installation</title>
     <para>
      This extension uses <productname>Sablotron</productname>
      and <productname>expat</productname>, which can both be
      found at <ulink
      url="&url.sablotron;">&url.sablotron;</ulink>. Binaries
      are provided as well as source.
     </para>
     <para>
      On UNIX, run <command>configure</command> with the <option
      role="configure">--enable-xslt --with-xslt-sablot</option>
      options.  The <productname>Sablotron</productname> library
      should be installed somewhere your compiler can find it. 
     </para>
    </sect2>

    <sect2 id="xslt.about">
     <title>About This Extension</title>
     <para>
      This PHP extension provides a processor independent API to XSLT
      transformations.  Currently this extension only supports the Sablotron
      library from the Ginger Alliance.  Support is planned for other 
      libraries, such as the Xalan library or the libxslt library.
     </para>
     <note>
      <simpara>
       This extension is different than the sablotron extension distributed with
       versions of PHP prior to PHP 4.1, currently only the new XSLT extension in 
       PHP 4.1 is supported.  If you need support for the old extension, please ask
       your questions on the php-general@lists.php.net mailing list.
      </simpara>
     </note>
    </sect2>

   </sect1>
  </partintro>

  <refentry id="function.xslt-set-log">
   <refnamediv>
    <refname>xslt_set_log</refname>
    <refpurpose>Set the log file to write log messages to</refpurpose>
   </refnamediv>
   <refsect1>
    <title>Description</title>
     <methodsynopsis>
      <type>void</type><methodname>xslt_set_log</methodname>
      <methodparam><type>resource</type><parameter>xh</parameter></methodparam>
      <methodparam><type>mixed</type><parameter>log</parameter></methodparam>
     </methodsynopsis>
    <para>
     <variablelist>
      <varlistentry>
       <term><parameter>xh</parameter></term>
       <listitem>
    <simpara>
     A reference to the XSLT parser.
    </simpara>
       </listitem>
      </varlistentry>
      <varlistentry>
       <term><parameter>log</parameter></term>
       <listitem>
       <simpara>
       This parameter is either a boolean value which toggles logging on and off, or a
       string containing the logfile in which log errors too.
       </simpara>
       </listitem>
      </varlistentry> 
     </variablelist></para>
    <para>
    This function allows you to set the file in which you want XSLT log messages to, 
    XSLT log messages are different than error messages, in that log messages are not 
    actually error messages but rather messages related to the state of the XSLT processor.
    They are useful for debugging XSLT, when something goes wrong.
    </para>
    <para>
    By default logging is disabled, in order to enable logging you must first call 
    <function>xslt_set_log</function> with a boolean parameter which enables logging, then if 
    you want to set the log file to debug to, you must then pass it a string containing the 
    filename:
     <example>
      <title>
      Using the XSLT Logging features
      </title>
      <programlisting role="php">
<![CDATA[
<?php

$xh = xslt_create();
xslt_set_log($xh, true);
xslt_set_log($xh, getcwd() . 'myfile.log');

$result = xslt_process($xh, 'dog.xml', 'pets.xsl');
print($result);

xslt_free($xh);
?>
]]>
      </programlisting>
     </example>
    </para>
   </refsect1>
  </refentry>

  <refentry id="function.xslt-create">
   <refnamediv>
    <refname>xslt_create</refname>
    <refpurpose>Create a new XSLT processor.</refpurpose>
   </refnamediv>
   <refsect1>
    <title>Description</title>
     <methodsynopsis>
      <type>resource</type><methodname>xslt_create</methodname>
      <void/>
     </methodsynopsis>
    <para>
     Create and return a new XSLT processor resource for manipulation by the
     other XSLT functions.
    </para>
   </refsect1>
  </refentry>

  <refentry id="function.xslt-errno">
   <refnamediv>
    <refname>xslt_errno</refname>
    <refpurpose>Return a error number</refpurpose>
   </refnamediv>
   <refsect1>
    <title>Description</title>
     <methodsynopsis>
      <type>int</type><methodname>xslt_errno</methodname>
       <methodparam><type>resource</type><parameter>xh</parameter></methodparam>
     </methodsynopsis>
    <para>
     Return an error code describing the last error that occured on the 
     passed XSLT processor.
    </para>
   </refsect1>
  </refentry>

  <refentry id="function.xslt-error">
   <refnamediv>
    <refname>xslt_error</refname>
    <refpurpose>Return a error string</refpurpose>
   </refnamediv>
   <refsect1>
    <title>Description</title>
     <methodsynopsis>
      <type>mixed</type><methodname>xslt_error</methodname>
       <methodparam><type>resource</type><parameter>xh</parameter></methodparam>
     </methodsynopsis>
    <para>
     Return a string describing the last error that occured on the 
     passed XSLT processor.
    </para>
    <para>
     <example>
      <title>
      Handling errors using the <function>xslt_error</function> and 
      <function>xslt_errno</function> functions.
      </title>
      <programlisting role="php">
<![CDATA[
<?php

$xh = xslt_create();
$result = xslt_process($xh, 'dog.xml', 'pets.xsl');
if (!$result) {
    die(sprintf("Cannot process XSLT document [%d]: %s", 
                xslt_errno($xh), xslt_error($xh)));
}

print($result);

xslt_free($xh);
?>
]]>
      </programlisting>
     </example>
    </para>
   </refsect1>
  </refentry>

  <refentry id="function.xslt-free">
   <refnamediv>
    <refname>xslt_free</refname>
    <refpurpose>Free XSLT processor</refpurpose>
   </refnamediv>
   <refsect1>
    <title>Description</title>
     <methodsynopsis>
      <type>void</type><methodname>xslt_free</methodname>
       <methodparam><type>resource</type><parameter>xh</parameter></methodparam>
     </methodsynopsis>
    <para>
     Free the XSLT processor identified by the given handle.
    </para>
   </refsect1>
  </refentry>

  <refentry id="function.xslt-process">
   <refnamediv>
    <refname>xslt_process</refname>
    <refpurpose>Perform an XSLT transformation</refpurpose>
   </refnamediv>
   <refsect1>
    <title>Description</title>
     <methodsynopsis>
      <type>mixed</type><methodname>xslt_process</methodname>
       <methodparam><type>resource</type><parameter>xh</parameter></methodparam>
       <methodparam><type>string</type><parameter>xml</parameter></methodparam>
       <methodparam><type>string</type><parameter>xsl</parameter></methodparam>
       <methodparam choice="opt"><type>string</type><parameter>result</parameter></methodparam>
       <methodparam choice="opt"><type>array</type><parameter>arguments</parameter></methodparam>
       <methodparam choice="opt"><type>array</type><parameter>parameters</parameter></methodparam>
     </methodsynopsis>
    <para>
     The xslt_process() function is the crux of the new XSLT extension.  It
     allows you to perform an XSLT transformation using almost any type of
     input source.  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).
    </para>
    <para>
     The simplest type of transformation with the <function>xslt_process()</function>
     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...
    </para>
    <example>
     <title>Using the <function>xslt_process</function> to transform an XML file and a XSL file 
     to a new XML file</title>
     <programlisting role="php">
<![CDATA[
<?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<br>\n";
    print "<pre>\n";
    readfile('result.xml');
    print "</pre>\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);

?>
]]>
     </programlisting>
    </example>
    <para>
     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 <function>xslt_process</function> 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...
    </para>
    <para>
     <example>
     <title>Using the <function>xslt_process</function> to transform an XML file and a XSL file 
     to a variable containing the resulting XML data</title>
     <programlisting role="php">
<![CDATA[
<?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<br>\n";
    print "<pre>\n";
    print $result;
    print "</pre>\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);

?>
]]>
      </programlisting>
     </example>
    </para>
    <para>
     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 &quot;argument&quot; syntax, comes to the 
     rescue.  Instead of files as the XML and XSLT arguments to the <function>xslt_process</function>
     function, you can specify &quot;argument place holders&quot; which are then subsituted by values
     given in the arguments array (5th parameter to the <function>xslt_process</function> function).  
     The following is an example of processing XML and XSLT into a result variable without the use 
     of files at all.
    </para>
    <para>
     <example>
     <title>Using the <function>xslt_process</function> to transform a variable containing XML data 
     and a variable containing XSL data into a variable containing the resulting XML data</title>
     <programlisting role="php">
<![CDATA[
<?php
// $xml and $xsl contain the XML and XSL data

$arguments = array(
     '/_xml' => $xml,
     '/_xsl' => $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<br>\n";
    print "<pre>\n";
    print $result;
    print "</pre>\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);
?>
]]>
      </programlisting>
     </example>
    </para>
    <para>
     Finally, the last argument to the <function>xslt_process</function> function is any parameters
     that you want to pass to the XSLT document.  These parameters can then be accessed within
     your XSL files using the &lt;xsl:param name=&quot;parameter_name&quot;&gt; instruction.
    </para>
   </refsect1>
  </refentry>

  <refentry id="function.xslt-set-sax-handler">
   <refnamediv>
    <refname>xslt_set_sax_handler</refname>
    <refpurpose>Set SAX handlers for a XSLT processor</refpurpose>
   </refnamediv>
   <refsect1>
    <title>Description</title>
     <methodsynopsis>
      <type>void</type><methodname>xslt_set_sax_handler</methodname>
       <methodparam><type>resource</type><parameter>xh</parameter></methodparam>
       <methodparam><type>array</type><parameter>handlers</parameter></methodparam>
     </methodsynopsis>
    <para>
     Set SAX handlers on the resource handle given by 
     <parameter>xh</parameter>. SAX handlers should be a two dimensional array 
     with the format (all top level elements are optional):
     <informalexample>
      <programlisting role="php">
<![CDATA[
array(
[document] => 
    array(
        start document handler,
        end document handler
    ),
[element] => 
    array(
        start element handler,
        end element handler
    ),
[namespace] => 
    array(
        start namespace handler,
        end namespace handler
    ),
[comment] => comment handler,
[pi] => processing instruction handler,
[character] => character data handler
)
]]>
     </programlisting>
    </informalexample>
    </para>
   </refsect1>
  </refentry>

  <refentry id="function.xslt-set-scheme-handler">
   <refnamediv>
    <refname>xslt_set_scheme_handler</refname>
    <refpurpose>Set Scheme handlers for a XSLT processor</refpurpose>
   </refnamediv>
   <refsect1>
    <title>Description</title>
     <methodsynopsis>
      <type>void</type><methodname>xslt_set_scheme_handler</methodname>
       <methodparam><type>resource</type><parameter>xh</parameter></methodparam>
       <methodparam><type>array</type><parameter>handlers</parameter></methodparam>
     </methodsynopsis>
    <para>
     Set Scheme handlers on the resource handle given by 
     <parameter>xh</parameter>. Scheme handlers should be an array with the
     format (all elements are optional):
     <informalexample>
      <programlisting role="php">
<![CDATA[
array(
[get_all] => get all handler,
[open] => open handler,
[get] => get handler,
[put] => put handler,
[close] => close handler
)
]]>
     </programlisting>
    </informalexample>
    </para>
   </refsect1>
  </refentry>

  <refentry id="function.xslt-set-error-handler">
   <refnamediv>
    <refname>xslt_set_error_handler</refname>
    <refpurpose>Set an error handler for a XSLT processor</refpurpose>
   </refnamediv>
   <refsect1>
    <title>Description</title>
     <methodsynopsis>
      <type>void</type><methodname>xslt_set_error_handler</methodname>
       <methodparam><type>resource</type><parameter>xh</parameter></methodparam>
       <methodparam><type>mixed</type><parameter>handler</parameter></methodparam>
     </methodsynopsis>
    <para>
     Set an error handler function for the XSLT processor given by <parameter>xh</parameter>,
     this function will be called whenever an error occurs in the XSLT transformation
     (this function is also called for notices).
    </para>
   </refsect1>
  </refentry>

  <refentry id="function.xslt-set-base">
   <refnamediv>
    <refname>xslt_set_base</refname>
    <refpurpose>Set the base URI for all XSLT transformations</refpurpose>
   </refnamediv>
   <refsect1>
    <title>Description</title>
     <methodsynopsis>
      <type>void</type><methodname>xslt_set_base</methodname>
       <methodparam><type>resource</type><parameter>xh</parameter></methodparam>
       <methodparam><type>string</type><parameter>uri</parameter></methodparam>
     </methodsynopsis>
    <para>
     Sets the base URI for all XSLT transformations, the base URI is used 
     with Xpath instructions to resolve document() and other commands which 
     access external resources.
    </para>
   </refsect1>
  </refentry>

  <refentry id="function.xslt-set-encoding">
   <refnamediv>
    <refname>xslt_set_encoding</refname>
    <refpurpose>Set the encoding for the parsing of XML documents</refpurpose>
   </refnamediv>
   <refsect1>
    <title>Description</title>
     <methodsynopsis>
      <type>void</type><methodname>xslt_set_encoding</methodname>
       <methodparam><type>resource</type><parameter>xh</parameter></methodparam>
       <methodparam><type>string</type><parameter>encoding</parameter></methodparam>
     </methodsynopsis>
    <para>
     Set the output encoding for the XSLT transformations.  When using the 
     Sablotron backend this option is only available when you compile 
     Sablotron with encoding support.
    </para>
   </refsect1>
  </refentry>

  <refentry id='function.xslt-set-sax-handlers'>
   <refnamediv>
    <refname>xslt_set_sax_handlers</refname>
    <refpurpose>
     Set the SAX handlers to be called when the XML document gets processed
    </refpurpose>
   </refnamediv>
   <refsect1>
    <title>Description</title>
     <methodsynopsis>
      <type>void</type><methodname>xslt_set_sax_handlers</methodname>
      <methodparam><type>resource</type><parameter>processor</parameter></methodparam>
      <methodparam><type>array</type><parameter>handlers</parameter></methodparam>
     </methodsynopsis>
    <para>
     &warn.undocumented.func;
    </para>
   </refsect1>
  </refentry>



  <refentry id='function.xslt-set-scheme-handlers'>
   <refnamediv>
    <refname>xslt_set_scheme_handlers</refname>
    <refpurpose>
     Set the scheme handlers for the XSLT processor
    </refpurpose>
   </refnamediv>
   <refsect1>
    <title>Description</title>
     <methodsynopsis>
      <type>void</type><methodname>xslt_set_scheme_handlers</methodname>
      <methodparam><type>resource</type><parameter>processor</parameter></methodparam>
      <methodparam><type>array</type><parameter>handlers</parameter></methodparam>
     </methodsynopsis>
    <para>
     &warn.undocumented.func;
    </para>
   </refsect1>
  </refentry>


 </reference>

<!-- Keep this comment at the end of the file
Local variables:
mode: sgml
sgml-omittag:t
sgml-shorttag:t
sgml-minimize-attributes:nil
sgml-always-quote-attributes:t
sgml-indent-step:1
sgml-indent-data:t
indent-tabs-mode:nil
sgml-parent-document:nil
sgml-default-dtd-file:"../../manual.ced"
sgml-exposed-tags:nil
sgml-local-catalogs:nil
sgml-local-ecat-files:nil
End:
vim600: syn=xml fen fdm=syntax fdl=2 si
vim: et tw=78 syn=sgml
vi: ts=1 sw=1
-->