PHP: XSLT 関数 - Manual
PHP  
downloads | documentation | faq | getting help | mailing lists | | php.net sites | links | my php.net 
search for in the  
<xsl_xsltprocessor_transform_to_xmlxslt_backend_info>
view the version of this page
Last updated: Tue, 21 Dec 2004

CXXXI. XSLT 関数

導入

このPHP拡張モジュールは、APIに独立なXSLT変換を提供します。現在、 この拡張モジュールは、Ginger AllianceによるSablotronライブラリの みをサポートします。Xalanライブラリまたはlibxsltライブラリのよう な他のライブラリのサポートも計画されています。

XSLT (Extensible Stylesheet Language (XSL) Transformations) は、XMLドキュメントを他のXMLドキュメントに変換 する言語です。XSLTは、World Wide Web コンソーシアム (W3C) により 標準化されています。XSLTに関する情報と関連技術については、 から得ることができま す。

注意: この拡張は、PHP 4.1より前のバージョンPHPで配布されていた sablotron拡張モジュールとは異なっており、現在、PHP 4.1の新しい XSLT拡張モジュールのみがサポートされています。古い拡張モジュー ルのサポートが必要な場合は、PHPのメーリングリストに質問して下さい。

要件

この拡張モジュールは、Sablotonおよび expat を使用します。これらは、共に から得ること が可能です。 実行バイナリがソースコードと同様に配布されています。

インストール手順

UNIXでは、オプション --enable-xslt --with-xslt-sablotを指定 してconfigure を実行します。ライブラリ Sablotron をコンパイラが見付けられる 場所にインストールする必要があります。

Sablotronにリンクされているのと 同じライブラリとPHPがリンクされていることを確認して下さい。 設定オプション --with-expat-dir=DIR --with-iconv-dir=DIR は、これらの指定を行う際に有用です。 サポートに質問する際に、常にこれらのディレクティブや、他のバージョン のライブラリが使用するシステムのどこかにインストールされて いるかどうかについて述べるようにして下さい。 普通は、全てのバージョン番号を知らせて下さい。

JavaScript E-XSLTサポート: SablotronをJavaScriptサポートを付けてコ ンパイルした場合、オプション --with-sablot-js=DIRを指定する必 要があります。

Win32ユーザへの注意: このモジュールをWindows環境で使用するには、 sablot.dllをPHP/Win32バイナリパッケージのDLLフォ ルダから使用するWindowsマシンのSYSTEM32フォルダ(例: C:\WINNT\SYSTEM32またはC:\WINDOWS\SYSTEM32)へコピーする必要がありま す。 PHP <= 4.2.0 の場合、sablot.dllexpat.dllを SYSTEM32フォルダにコピーしてください。 PHP >= 4.2.1 の場合、sablot.dll, expat.dll, iconv.dllを SYSTEM32フォルダにコピーしてください。

実行用の設定

この拡張モジュールは設定ディレクティブを全く定義しません。

リソース型

この拡張モジュールはリソース型を全く定義しません。

定義済みの定数

これらの定数は、この拡張モジュールで定義されており、 この拡張モジュールがPHP内部にコンパイルされているか実行時に動的にロー ドされるかのどちらかの場合のみ使用可能です。

XSLT_OPT_SILENT (integer)

ログ出力とエラー報告を全てドロップします。 将来追加される全てのバックエンドについて共通のオプションです。

XSLT_SABOPT_PARSE_PUBLIC_ENTITIES (integer)

Sablotronがpublicエンティティを パースするようにします。デフォルトではオフになっています。

XSLT_SABOPT_DISABLE_ADDING_META (integer)

HTML出力のときに "Content-Type" メタタグを追加しません。 Sablotronのコンパイル時にデフォルト値が セットされます。

XSLT_SABOPT_DISABLE_STRIPPING (integer)

空白の除去を抑制します。(データファイルに対してのみ)

XSLT_SABOPT_IGNORE_DOC_NOT_FOUND (integer)

Consider unresolved documents (the document() function) non-lethal.

XSLT_ERR_UNSUPPORTED_SCHEME (integer)

Error return code, for scheme handlers.

目次
xslt_backend_info --  Returns the information on the compilation settings of the backend
xslt_backend_name --  Returns the name of the backend
xslt_backend_version --  Returns the version number of Sablotron
xslt_create -- 新規のXSLTプロセッサを作成する
xslt_errno -- カレントエラー番号を返す
xslt_error -- カレントのエラー文字列を返す
xslt_free -- XSLT プロセッサを開放する
xslt_getopt --  Get options on a given xsl processor
xslt_process -- XSLデータを有する文字列によりXMLデータを変換する
xslt_set_base -- 全てのXSLT変換用の基準URIを設定する
xslt_set_encoding --  XMLドキュメントをパースするエンコーディングを設定する
xslt_set_error_handler -- XSLTプロセッサ用のエラーハンドラを設定する
xslt_set_log -- Set the log file to write log messages to
xslt_set_object --  Sets the object in which to resolve callback functions
xslt_set_sax_handler -- XSLTプロセッサに SAX ハンドラを設定する
xslt_set_sax_handlers --  XMLドキュメントを処理する際にコールされるSAXハンドラを設定する
xslt_set_scheme_handler -- XSLTプロセッサ用にスキーマハンドラを設定する
xslt_set_scheme_handlers --  XSLTプロセッサに関するスキーマハンドラを設定する
xslt_setopt --  Set options on a given xsl processor


add a note add a note User Contributed Notes
XSLT 関数
Kerry Kobashi
17-Oct-2004 04:40
In regards to getting XSLT extensions (or any extension) working with PHP 5 on Windows.

Assuming you downloaded PHP and extracted it to the c:/php directory:

1) Move your PHP.INI file to the c:/php directory
PHP.INI isn't being picked up from the Windows system directory. I've read lots of people having problems with this so this should kill the probs once and for all. Validate with phpinfo.

2) All Windows extensions are in the C:/PHP/EXT directory. To get PHP to load these modify PHP.INI:
   extension_dir = "c:/php/ext/"

No, you *don't* need to copy the DLLs into the Windows system directory. Avoid DLL hell!

3) Load the XSL extension:
   extension=php_xsl.dll
schvenk
05-Oct-2004 02:04
I've spent the last day tracking down a weird problem with Sablotron and the 4.3.6 PHP extension on Mac OS 10.3, and thought maybe I could save someone else the same hassle.

I originally had a working installation and use the Sablotron XSLT extension for much of my site. Yesterday I tried to open a page and got a Sablotron error:

Cannot open file '????/path/to/xslt/file'

The question marks at the beginning weren't always question marks, but were always several gibberish characters. No matter what I tried I got this error. I looked into problems with text encodings (the only change being more interesting gibberish), reinstalled the OS, reinstalled PHP...nothing. Ultimately it looks like all directories on the path to the XSLT file must have read permissions for the Web server. My home directory didn't. As soon as I changed that, the problem went away.
arossato at istitutocolli dot org
28-Aug-2004 08:12
It is possible to create the xslt extension as a shared object module statically linked with salbot and expat (I needed it for a project hosted in sourceforge where the sablot library is available).
Compile the module as usual:
cd ext/xslt
phpize
./configure --enable-module=so --enable-xslt=shared --with-xslt-sablot --with-expat
make

Then create a statically linked module:
gcc -Wl,-Bstatic -shared  xslt.lo sablot.lo  -o xslt.so  /usr/local/lib/libsablot.a /usr/local/lib/libexpat.a --static-libgcc

change /usr/local/lib/libsablot.a and /usr/local/lib/libexpat.a according to the right path on your system.

You're done!
My xslt.so is 5.2M...
tom at kornack dot com
24-Aug-2004 10:09
If you're wrangling with a plist in Mac OS X: here a bit of code to convert the plist into xml using xslt and then accessing it using simplexml. This was modified from . Please do post improvements. This has been tested against iPhoto's AlbumData as well as iTunes' data. Enjoy!

<?php
$xsl
= new DomDocument();
$xsl->load("plistConvert.xsl");
$inputdom = new DomDocument();
$inputdom->load("iTunes Music Library.xml");
$proc = new XsltProcessor();
$proc->registerPhpFunctions();
$xsl = $proc->importStylesheet($xsl);
$newdom = $proc->transformToDoc($inputdom);
$sxe = simplexml_import_dom($newdom);
print(
'<pre>');
print_r($sxe->dict);
print(
'</pre>');
?>

Here's the plistConvert.sxl file:

<?xml version='1.0'?>
<xsl:stylesheet xmlns:xsl  ="" version="1.0">
<xsl:output method="xml" indent="yes"/>

<xsl:template match="/plist">
  <propertylist>
   <xsl:apply-templates/>
  </propertylist>
</xsl:template>

<xsl:template match="dict">
  <dict>
   <xsl:for-each select="key">
     <xsl:variable name='n1' select='translate(., " ", "_")'/>
     <xsl:variable name='pName'>
       <xsl:choose>
           <!-- Need to do this because number tags like <0> are not valid?! -->
         <xsl:when test='contains("0123456789", substring($n1, 1, 1))'>
           <xsl:value-of select='concat("number_", $n1)'/>
         </xsl:when>
         <xsl:otherwise>
           <xsl:value-of select='$n1'/>
         </xsl:otherwise>
       </xsl:choose>
     </xsl:variable>

     <xsl:element name="{$pName}">
       <xsl:for-each select='following-sibling::*[1]'>
         <xsl:choose>
           <xsl:when test='name() = "dict"'>
             <xsl:apply-templates select='.'/>
           </xsl:when>

           <xsl:when test='name() = "array"'>
             <xsl:attribute name="array">collection</xsl:attribute>
             <xsl:apply-templates/>
           </xsl:when>

           <xsl:when test='name() = "string"'>
             <xsl:value-of select='.'/>
           </xsl:when>

           <xsl:when test='name() = "integer"'>
<!--              <xsl:attribute name="type">integer</xsl:attribute> -->
             <xsl:value-of select='.'/>
           </xsl:when>

           <xsl:when test='name() = "date"'>
<!--              <xsl:attribute name="type">date</xsl:attribute> -->
             <xsl:value-of select='.'/>
           </xsl:when>

           <xsl:when test='name() = "true"'>True</xsl:when>
           <xsl:when test='name() = "false"'>False</xsl:when>
           <xsl:when test='name() = "real"'>
             <xsl:value-of select='.'/>
           </xsl:when>
           <xsl:when test='name() = "data"'>
             <xsl:value-of select='.'/>
           </xsl:when>
          
           <xsl:otherwise>
             <xsl:message>pListConverter: <xsl:value-of select='name()'/> not implemented!
             </xsl:message>
           </xsl:otherwise>
         </xsl:choose>
       </xsl:for-each>
     </xsl:element>
   </xsl:for-each>
  </dict>
</xsl:template>

<!-- don't pass text thru -->
<xsl:template match="text()|@*">
</xsl:template>

</xsl:stylesheet>
m dot rovis at inet dot hr
12-Jun-2004 12:52
I ended up banging my head against the virtual but very painful wall
made of wrong compilation planning, when I tried to install and use
Charlie's JavaScript engine with Sablotron and PHP on Apache1 server,
and I only returned onto the right road thanks to Petr Cimprich from
Ginger Alliance...

Forget Charlie's JS engine (I don't know about SpiderMonkey) w/ PHP in
case anyone is considering it!

More can be read on sablist, in our thread entitled misleadingly (by
what I planned to install when I started):
"Sablotron and Charlie with apache2 (and php4)"
(I ended up w/ Apache1 and w/o Charlie) at:
09-Apr-2004 07:13
In win2k with all files ( data, programs ... ) encoded in UTF-8,
the header of the xml file MUST NOT contain something like :
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>

Do not put any header and you will not have the error:
Warning: Sablotron error on line 1: XML parser error 4: not well-formed (invalid token)
dev_uio
02-Dec-2003 07:48
for those installing on windows, you need to follow this step

Windows configurations
The Win32 binaries available via the PHP site come with the Sablotron extension already built in. Therefore, upon downloading, installing, and configuring the most recent Win32 distribution, open up your php.ini file and uncomment the line:

;extension=php_sablot.dll
Uncommenting the line simply involves removing the semicolon.

taken from:
will at NOSPAM dot wdp dot ndo dot co dot uk
16-Nov-2003 10:09
As an update to the previous advice about the undefined references problem when installing PHP with Sablotron, PHP 4.3.4 has a new EXTRA_LDFLAGS_PROGRAM line added to the Makefile. Make sure to add -lstdc++ to this line as well as the EXTRA_LDFLAGS line.
crtn at users dot sourceforge dot net
23-Jun-2003 12:03
If you are using Debian packages for PHP and Apache and XSLT, you will probably need to upgrade to the UNSTABLE package for PHP. The stable and testing versions of php are too far behind and using them with sablotron will cause apache to segfault.
crtn at users dot sourceforge dot net
08-Jun-2003 04:41
Another way to get around the EXPAT-SABLOTRON problems (seg faults) is supposedly to recompile apache with:
--disable-rule=EXPAT
d dot brotherstone at pobox dot com
27-May-2003 04:14
If you get problems with undefined references to gxx_s type stuff, UPDATE LIBTOOL!  I found 1.4.1 worked for some configurations, 1.4.3 worked for almost none, but 1.5 worked for every combination of Sablotron/gettext/sybase/zlib/postgres --with options I tried. 

Make sure you follow the advice of adding -lstdc++ to EXTRA_LD_FLAGS in Makefile after you've run ./configure, and BEFORE you've run make (if you issue make, you'll need to do a make clean before you make again, after changing the Makefile, or it still won't work reliably).

Cheers, Dave.
shanx at REMOVEME dot shanx dot com
19-May-2003 07:18
For recent versions of PHP, XSLT install instructions for Windows and Apache are here:



Cheers.
DrTebi at NOSPAM dot yahoo dot NOSPAM dot com
13-May-2003 04:37
I would like to add that there is no problem to install PHP with Sablotron on a Gentoo Linux system ().

Just make sure you emerged the expat and sablotron packages like so:

emerge expat
emerge sablotron

After this, there should be no linking problem or whatsoever:

./configure --with-xslt --with-sablotron
make

and you should be set ;-)
thomas at xciteit dot com
25-Apr-2003 06:13
I got into serious troubles using xslt transforming, while using PHP Build Version 4.2.2. It didn't find the module all the time, as well as it occured at several people, as I read above.

Just upgrade to PHP 4.3.1. All the required libraries are included with the distribution (you better use the manual setup, not the php installer). Follow the setup instructions, which are partly a bit chaotic, but should get you done within about five minutes.

Note: If you use your old php.ini, make sure, you quote out the php_ctype.dll, since it seems, to be built in since 4.3 (had several errors "redefinition of <function-name>" occuring when [re]starting apache).

If any libraries can not be found again, make sure the php4ts.dll resides in the same directory as php.exe or the php4<yourserver>.dll. Alse be sure to use php4apache2.dll, if you are running Apache Version 2.x. Also (lib)expat.dll and the rest of the above mentioned files should be able to be found (reside in a directory, that can be accessed through the path). I just checked and tested removing all files I moved to the system32 directory. You just need the files "expat.dll" and "sablot.dll" there. I removed "xmltok.dll", "xmlparse.dll" and "iconv.dll" again, and it still works fine.
You can find everything at

Regards Thomas Karl
www.xciteit.com
ohlesbeauxjours at yahoo dot fr
20-Mar-2003 08:18
In reply to Jaron, who needed to evaluate PHP code inside the stylesheet, look at a post I sent about xslt_set_scheme_handlers().
Scheme handlers are very useful, since they allow the XSLT engine and PHP to fully interact (they will communicate through XML strings).

With xslt_set_scheme_handlers(), you can give the XSLT engine an advanced access to the file system (or even to the other I/O interfaces), and perform various tasks (checking the existence of a file, creating new files "on the fly", deleting, etc...)
... all that in only one stylesheet :)

baptiste
nemilya at mail dot ru
20-Feb-2003 06:59
If you want to experiment with xslt-technology, try php-based application xmlSiteMaker for site generation:
aargh at 44rgh dot net
14-Oct-2002 10:47
Compilation on RedHat 7.0 PHP-4.1.2-7.0.4.
Compilation failed when providing --enable-xslt --with-xslt-sablot --with-sablot-js.
Problem was that an additonal flag needed to be specified or the build would fail complaining that js-libs ... could not be found.

LIBS="-lttf -lpng -ljpeg -lz -lnsl -ljs"; export LIBS

The additional flag "-ljs" needed to be set.
jw at shapers dot nl
27-Sep-2002 03:09
In addition to "tk dot lists at fastmail dot fm"'s comment on Windows dependencies: You'll also need iconv.dll in your SYSTEM32 folder. At least, that's what I needed to get it working on my PHP4.2.3-Win install.
gbarattoKILLSPAMMERS at superb dot net
18-Sep-2002 05:55
Regarding the `__gxx_personality_v0' problem described by [email protected], you have to use LDFLAGS=-lstdc++  as well before configuring php (and not apache) when compiling php as a shared object.

Thank you Dennis
matthias-at-mlienau.de
30-Aug-2002 12:52
For those guys who mess up with compiling the current Sablotron 0.95 sources from gingerall.com:

Here is a patch which corrects a typo.
Or - go to src/engine/domprovider.cpp and change "voiD" to "void" in line 558 and compile again...

*** domprovider.cpp.diff        Thu Aug 29 23:32:59 2002
--- domprovider.cpp    Thu Aug 29 23:32:14 2002
***************
*** 555,561 ****
   if (external) cdelete(external);
  }
 
! void DOMProviderUniversal::setExtProvider(DOMHandler *domh, voiD *data)
  {
   if (external) cdelete(external);
   if (domh)
--- 555,561 ----
   if (external) cdelete(external);
  }
 
! void DOMProviderUniversal::setExtProvider(DOMHandler *domh, void *data)
  {
   if (external) cdelete(external);
   if (domh)
tk dot lists at fastmail dot fm
26-Aug-2002 08:35
INSTALLING PHP XSLT ON WINDOWS

Thanks to a wonderful program which lists dependecy heirachies for windows executables (and .dll files), I was able to track down the problem. What the PHP manual neglects to tell you (it only has instructions for Unix) is that you need to find sablot.dll, I suspect that php_xslt.dll is just a stub which calls this program. Now sablot also needs libexpat.dll (which I discovered thanks to dependency walker).

so anyone who wants to do PHP XSLT under windows, not only do you need to uncomment php_xslt.dll in the php.ini file, you need to find sablot.dll and libexpat.dll and stick em in your system32 diectory.
gherson at DatainFormation com
22-Aug-2002 03:56
Compiling xslt into cgi version of PHP4.2.2 on linux 2.4.7:
Lots of work was needed.  I had to download  Mozilla's js-1.5rc4-2.i386.rpm and js-devel-1.5rc4-2.i386.rpm and the Sablotron library tarball, all from Applying patch was nec (found by searching google with "SXPF_DISPOSE_VALUES", which make blamed for failing, claiming it had a duplicate value). Export CPLUS_INCLUDE_PATH="/usr/include/js/" was nec to get past a Sablotron make or configure error "required file jsapi.h not found".  Then ./configure --enable-javascript; make; make install worked w/o errors.  Then, for PHP 4.2.2 compilation:
$ ./configure  --with-pgsql=/usr/local/pgsql --enable-force-cgi-redirect --enable-xslt  --with-xslt-sablot --with-sablot-js
followed by $ make and # make install.  No errors. /usr/local/bin/php is the new cgi executable.  $ php -v confirmed the version, and function phpinfo() confirmed xslt enabled.  (Along the way I had tried the rpm version of Sablotron and compiling the CVS version of PHP when i got stuck, to no avail.)
dennisNOSPAM at infoleak dot com
23-May-2002 04:23
Building Sablotron on Solaris with.
gcc 3.0.3 and native linker
libtool (sunfreeware)
apache 1.3.24
php-4.2.1
sablotron-0.90
expat-1.95.2

When configuring Apache you might experience this error..

libsablot.so: undefined reference to `operator new[](unsigned)'
libsablot.so: undefined reference to `__cxa_call_unexpected'
libsablot.so: undefined reference to `vtable for __cxxabiv1::__si_class_type_info'
libsablot.so: undefined reference to `operator delete(void*)'
libsablot.so: undefined reference to `__gxx_personality_v0'
libsablot.so: undefined reference to `vtable for __cxxabiv1::__class_type_info'
libsablot.so: undefined reference to `operator delete[](void*)'
libsablot.so: undefined reference to `vtable for __cxxabiv1::__vmi_class_type_info'
libsablot.so: undefined reference to `operator new(unsigned)'

To cure it make sure that during the configure stage you feed configure LDFLAGS variable like so.

LDFLAGS=' -lstdc++' ./configure

Otherwise Apache's compiler sanity check will balk.
jon dot sprague at itgco dot com
06-Feb-2002 08:59
For those of you who are having problems installing php with Sablotron (I was one), here's what I did.

What I'm running:
-Apache 1.3.19
-PHP 4.1.1
-Linux

This is what I did:
1. Go to the web site previosly mentioned by [email protected],

2. Click the FAQ: "How do I install Sablotron with PHP?�"

The only thing that needs to be done differently for PHP 4.1 and it's sub versions (ex. 4.1.1) is the options on the configure line.
Use --enable-xslt --with-xslt-sablot instead.
erik_i at NOSPAMtelia dot com
21-Jan-2002 10:53
The extension dll in Windows is no longer php_sablot.dll, it's php_xslt.dll
ken1138 at altavista dot com
11-Jan-2002 10:15
The XSLT functions may experience conflicts with Apache in some configurations, causing random segfaults in httpd.  Apache has included a 'lite' version of expat in their recent distributions, which can cause conflicts with expat.  Apache1.3.22 solves the problem by configuring itself to use the expat you have installed, instead of the built-in. If you compiled Apache before you installed expat, make sure you upgrade and/or recompile your Apache server with the same version of expat that PHP and Sablotron are using.
Jaron dot Schaeffer at jayweb dot de
09-Jan-2002 09:25
I extended the example of Daniel Unterberger even more. I had the problem to evaluate PHP code within my xml data files (e.g. to output database results) and after that apply a xsl stylesheet to the generated data.

When I tried Daniel's solution I found it quite useful but noticed that you can't "print out" from your PHP Code. You're bound to annoying return()-Statements, wich makes it impossible to loop outputs or concatenate strings and then return them. If you try to do so, you will notice that a statement like
...
<php:eval>
  for($i=0; $i<10; $i++)
   echo "This is number ".$i;
</php:eval>
...

will result in PHP to do the output right in the moment when the eval()-Statement is run.

Things do, at least, work fine if you keep it simple:

...
<php:eval>
  return("Hello World!");
</php:eval>
...

I tried to fix that and came to a solution. The following code is just a snippet from my XSLT-class. The uppercase letters are constants defined in a header file. (e.g. define('PHP_EVAL_START_TAG', '<php:eval>');

...
 function xmlString() {

   $fd = fopen($this->xmlFileLocation, 'r');
   $xmlString = fread($fd, filesize($this->xmlFileLocation));
   fclose($fd);

   if($this->contentType == DYNAMIC_CONTENT) {

     while(!(strpos($xmlString, PHP_EVAL_START_TAG) === false)) {

   $startPos = strpos($xmlString, PHP_EVAL_START_TAG);
   $endPos  = strpos($xmlString, PHP_EVAL_END_TAG);

   ob_start();
   eval(substr($xmlString, $startPos + strlen(PHP_EVAL_START_TAG), $endPos - $startPos - strlen(PHP_EVAL_START_TAG)));
   $evaluatedString = ob_get_contents();
   ob_end_clean();

   $xmlString =
       substr($xmlString, 0, $startPos).$evaluatedString.substr($xmlString, $endPos + 11);
     }
   }
  
   return($xmlString);
  }
...

[email protected]
sandro_zic at web dot de
28-Aug-2001 01:57
[Editor's note: moved this note here where it belongs - [email protected]]

This shows how you can use the XSLT functions to add dynamic content to the result tree, i.e. how to hand over parameters to the XSL stylesheet and write to Sablotron's document buffer.

First we assign the value of the parameter to an array in PHP:
-----------------------------------------
$xslt_params["test"] = "Run-time parameter.";
-----------------------------------------

The parameter is envoced in XSL by
-----------------------------------------
<h1>Value of run-time parameter:</h1>
<b><xsl:value-of select="$test" /></b>
<hr/>
-----------------------------------------

Don't forget to define the parameter at the beginning of your stylesheet:
-----------------------------------------
<xsl:param name="test"/>
-----------------------------------------


How can we add dynamic content from a database to the XSLT output? In Sablotron, this is done using the document buffer function.

Retrieve a table's content, store it in a XML structure assigned to an array in PHP:
-----------------------------------------
$xslt_args["buffer1"] =
"
<TestBuffer>
   <Message>
       <Content>
       This is message 1 of buffer 1.
       </Content>
   </Message>
   <Message>
       <Content>
       This is message 2 of buffer 1.
       </Content>
   </Message>
</TestBuffer>
";
-----------------------------------------

This is how you add the buffer to the result tree in your XSL document:
-----------------------------------------
<h1>Dynamic content from document buffer 1:</h1>
<xsl:for-each select="document('arg:/buffer1')/TestBuffer/Message">
   <b><xsl:value-of select="Content" /></b><br/>
</xsl:for-each>
<hr/>   
-----------------------------------------


To get the whole thing running, following functions have to be executed:
-----------------------------------------
$processor = xslt_create();
xslt_run ($processor, "file://".$DOCUMENT_ROOT.$xsl_file, "file://".$DOCUMENT_ROOT.$xml_file, "arg:/_result", $xslt_params, $xslt_args);
$result = xslt_fetch_result ($processor);
echo $result;
-----------------------------------------


The complete XSL file looks like this:
-----------------------------------------
<?xml version="1.0" encoding="iso-8859-1"?>
<xsl:stylesheet xmlns:xsl="" version="1.0">
<xsl:output method="html" version="1.0" standalone="yes" indent="yes" />

<!-- define parameter -->
<xsl:param name="test"/>

<xsl:template match="/">           

<!-- run-time parameter -->
<h1>Value of run-time parameter:</h1>
<b><xsl:value-of select="$test" /></b>
<hr/>

<!-- dynamic content -->
<h1>Dynamic content from document buffer 1:</h1>
<xsl:for-each select="document('arg:/buffer1')/TestBuffer/Message">
   <b><xsl:value-of select="Content" /></b><br/>
</xsl:for-each>
<hr/>   

</xsl:template>

</xsl:stylesheet>
-----------------------------------------
d dot u at mail dot com
13-Jun-2001 07:19
... addition to last message

sorry shanx (miss-spelled).
having a full example you must call it like in the shanx-example. Hint dont use echo inside of <php:eval> but return, because it is only string concatenation.

<code>
<?php
##  require "xslt.inc.php";

$xslt = new xsltTransform("life.xsl", "life.xml");
print (
$xslt->applyTransformation());

?>
</code>
d dot u at mail dot com
13-Jun-2001 06:43
I extended the example of shanks (very helpful for me tnx), so you can call php inside your xslt file, I had the problem to pass url-parameters and did not understand how to solve it, so I use php.

<code>
<?php

/**
 *
 * A class to transform XML through XSLT using PHP4 Sablotron extension
 *
 */

 #######################################################################
 ## file extended by Daniel Unterberger ([email protected])
 ## changes: some  php:eval's added

class xsltTransform
{

   var
$xsl_file;
   var
$xml_file;
   var
$fileName;

  
/**
     * Constructor to the xsl_transform ticket
     *
     * @param $xsl_file The XSLT file containing the transformation info
     * @param $xml_file The XML file containing the actual data
     * @see readFile()
     */
  
function xsltTransform($xsl_file = '', $xml_file = '')
   {
      
$this->xsl_string = $this->readFile($xsl_file,'php:eval');
      
$this->xml_string = $this->readFile($xml_file);
   }

  
/**
     * Function to read through the file
     *
     * @param $fileName Which file to read?
     *
     */
  
function readFile($fileName,$php_eval="")
   {
      
// get contents of a file into a string
      
$fd = fopen( $fileName, "r" );
      
$content = fread( $fd, filesize( $fileName ) );
      
fclose( $fd );

      
##################################################
       ## extension by Daniel Unterberger ([email protected])

      
while ( $php_eval and ( $pos_start=strpos($content,'<php:eval>') ))
       {
        
$pos_end=strpos($content,'</php:eval>');
        
$content=substr($content,0,$pos_start).
                   eval(
substr($content,$pos_start+10,$pos_end-$pos_start-10) ).
                  
substr($content,$pos_end+11);
       }

       if (
$GLOBALS["debug"]=="ON") print "<xmp>$content</xmp>";
          
## see xslt-file for debuggin if you call page.php?debug=ON (remove on life-server)

       ###################################################
       ## end extension

      
return $content;


   }

  
/**
     * Function to apply the actual transformation
     *
     */
  
function applyTransformation()
   {
      
$this->result = '';
      
$this->msg = xslt_process($this->xsl_string, $this->xml_string, $this->result);
       if(!
$this->msg) print ("Transformation failed.");
       return
$this->result;
   }


// End of class, do not remove
}



?>
</code>

in the xslt you can call it now with

...
<tag><php:eval> return $GLOBALS["filter"]; /* all php allowed */ </php:eval></tag>
...

-------------------------------
hope this gives new inspiration
(d.u)
maximo at migliari dot com
27-Apr-2001 04:31
COMPILING AND INSTALLING SABLOTRON AND EXPAT FOR PHP ON A FREEBSD iServer

0) Prepare your virtual server environment.  Telnet to your iserver and type:
   mkdir -p ~/usr/local/apache/1.3/bin
   ln /usr/bin/make ~/usr/bin/make
   ln /usr/local/apache/1.3/bin/apxs ~/usr/local/apache/1.3/bin/apxs
   ln /usr/local/apache/1.3/bin/httpd ~/usr/local/apache/1.3/bin/httpd

1) download the following files:
   expat-1.95.tar.gz -
   Sablot-0.52.tar.gz -
   php4-latest.tar.gz -

2) copy these files to ~/usr/local

3) expand all these files uing tar -xvzf

4) go into expat directory and type:
   ./configure --prefix=/usr/home/your_iserver_login_name/usr/local
   make
   make install
  
   the files will be installed under ~/usr/local/lib and ~/usr/local/include

5) set the following environment variables:
   setenv LD_LIBRARY_PATH /usr/home/your_iserver_login_name/usr/local/lib
   setenv LD_RUN_PATH /usr/home/your_iserver_login_name/usr/local/
   setenv CPLUS_INCLUDE_PATH /usr/home/your_iserver_login_name/usr/local/include
   setenv LIBRARY_PATH /usr/home/your_iserver_login_name/usr/local/lib

6) go into the Sablotron directory and type:
   ./configure --prefix=/usr/home/your_iserver_login_name/usr/local
   make
   make install

7) go into the php directory and type:
   ./configure --with-apxs=/usr/local/apache/1.3/bin/apxs \
   --disable-debug \
   --enable-trans-sid \
   --enable-versioning \
   --enable-ftp \
   --with-mysql=/usr/home/your_iserver_login_name/usr/local/mysql \
   --with-xml \
   --enable-magic-quotes \
   --enable-track-vars \
   --enable-sablot-errors-descriptive \
   --with-sablot=/usr/home/your_iserver_login_name/usr/local \
   --with-expat=/usr/home/your_iserver_login_name/usr/local

   then

   make
   and
   make install

the final command - make install - should give an error about not being able to install pear.
This is normal, as pear tries to copy itself outside of your virtual server space.  Since pear
is not an essential part of PHP - you can ignore this. (maybe there is a command for ./configure
in php that allows us to specify the directory in which pear will be installed?

8) final steps:
   go to ~/usr/local/etc/httpd/conf
   edit httpd.conf
   comment out the LoadModule directive for the previous php .so module.
   not that you should see the new module you just compile already inserted in the httpd.conf as
   the last line of all LoadModule directives. (it should be called libphp4.so

   now just go back to the command prompt after you have edited httpd.conf and type:
   restart_apache

   now go to your httpd document root (usually htdocs), and create a php file with the following
   code in it:

   <?php
     phpinfo
();
  
?>

   load the file in your browser, and you should see that everything has been installed properly :)
07-Apr-2001 04:14
Interesting PHP/Sablotron article:


<xsl_xsltprocessor_transform_to_xmlxslt_backend_info>
 Last updated: Tue, 21 Dec 2004
show source | credits | sitemap | contact | advertising | mirror sites 
Copyright © 2001-2005 The PHP Group
All rights reserved.
This unofficial mirror is operated at: /
Last updated: Mon Mar 14 08:13:06 2005 Local time zone must be set--see zic manual page