PHP 5.5.16 is released

XSLT (PHP 4) 関数

目次

add a note add a note

User Contributed Notes 28 notes

up
0
hentaidream at gmx dot de
3 years ago
How to make a XSLT Side with function

<code>
<xsl:output method="xhtml"/>
  <xsl:template match="/">
    <html>
      <head><title>Ausgabe</title></head>
      <body>
        <xsl:apply-templates select="aktien/aktie"></xsl:apply-templates>
      </body>
    </html>
 
  </xsl:template>
 
  <xsl:template match="aktie">
     <xsl:if test="@isin">
       <xsl:value-of select="name" />
       <xsl:value-of select="fn:format-number(fn:sum(kurse/kurs/ausgabepreis) div fn:count(kurse/kurs), '##.00')" />    
     </xsl:if> 
  </xsl:template>

</xsl:stylesheet>
</code>
up
0
Jeroen
6 years ago
In addition to the contibution of "tom at kornack dot com" about converting an Apple plist (iPhoto or iTunes library or other) into a more general XML format, I have tried to simplify his xsl file a little further:

<?xml version="1.0"?>
<xsl:transform xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:output method="xml" indent="no"/>                
<!-- XSL file based on example on php.net by tom@kornack.com -->

<xsl:template match="dict">                           
  <xsl:for-each select="key">
    <xsl:variable name="n1" select="translate(.,' ','_')"/>
    <xsl:variable name="pName"><xsl:choose>           
      <xsl:when test="string(number($n1))='NaN'">     
        <xsl:value-of select="$n1"/>                  
      </xsl:when>                                     
      <xsl:otherwise>                                 
        <xsl:value-of select="concat('_',$n1,'_')"/>  
      </xsl:otherwise>                                
    </xsl:choose></xsl:variable>                      
    <xsl:element name="{$pName}">                     
      <xsl:apply-templates select="following-sibling::*[1]"/>
    </xsl:element>
  </xsl:for-each>
</xsl:template>

<xsl:template match="array">                          
  <xsl:for-each select="*"><xsl:element name="item">  
    <xsl:attribute name="nr"><xsl:number/></xsl:attribute>
    <xsl:apply-templates select="."/>                 
  </xsl:element></xsl:for-each>                       
</xsl:template>

<xsl:template match="string|integer|real|date|data">  
  <xsl:value-of select="."/>                          
</xsl:template>

<xsl:template match="true|false">                     
  <xsl:value-of select="name()"/>                     
</xsl:template>

<xsl:template match="text()|@*">                      
</xsl:template>

</xsl:transform>
up
0
nicolas_rainardNOSPAM at yahoo dot fr
7 years ago
The XSLTProcessor, when transforming a document, always resolves entities.
To avoid this (if you want to keep HTML entitities by ex.), you have two solutions:

- if you have full control over the input document, you can encapsulate every text element which contains entities in a CDATA section.

- the previous solution is the smarter and the less computing intensive, but it is not always possible. In other cases, what you can do is to replace every occurence of '&' (entity mark) by something which will be considered as normal text by the parser (let's say '[AMP]' by ex) in the input document before the transformation. After the transformation, you can get these entitites back in the output document by reversing the previous operation.

<?php

$xml
= $input_dom->saveXML();
$xml = str_replace('&', '[AMP]', $xml);
$input_dom->loadXML($xml);

$xml = $xsl->transformToXML($input_dom);
$xml = str_replace('[AMP]', '&', $xml);
$output_dom->loadXML($xml);

?>

Warning : this second method "escapes" ALL entities, even those you wouldn't want to be escaped. This is a raw explanation, fine-tune it to your own situation.
up
0
armencho at gmail dot com
7 years ago
I believe the xslt_process and its URI resolving behaviour, including the xslt_set_base function are violating the XSLT specification which states:

<blockquote>

3.2 Base URI

Every node also has an associated URI called its base URI, which is used for resolving attribute values that represent relative URIs into absolute URIs. If an element or processing instruction occurs in an external entity, the base URI of that element or processing instruction is the URI of the external entity; otherwise, the base URI is the base URI of the document. The base URI of the document node is the URI of the document entity. The base URI for a text node, a comment node, an attribute node or a namespace node is the base URI of the parent of the node.

</blockquote>

This implies that if stylesheet file A contains a <xsl:import href="../B.xsl" /> and stylesheet file B contains a <xsl:import href="../C.xsl" />, given that all physical paths are valid, no matter which base you set up for the XSLT extension (with xslt_set_base) the processor WILL FAIL. Simply because it uses a single base path for all its processing regardless of the context (importing file) which includes/imports. This is a violation of the above part of the specification quoted above.

And it makes it very difficult to program XSLT with PHP.
up
0
Roman
8 years ago
bat at flurf, you said that Sablotron implements XSLT 1.1, but according to its makers, "Sablotron is ...implementing XSLT 1.0, DOM Level2 and XPath 1.0" [http://www.gingerall.org/sablotron.html]
up
0
bat at flurf dot net
8 years ago
maurits says that libxslt should be preferred over Sablotron, but I disagree.  libxslt only implements a fraction of the capabilities of Sablotron; in particular, this doesn't work in libxslt:

    <xsl:variable name="x">
      <a>One</a>
      <a>Two</a>
      <a>Three</a>
    </xsl:variable>

    <xsl:for-each select="$x/a">
      <xsl:value-of select="."/>
    </xsl:for-each>

In Sablotron, which implements XSLT 1.1, this works fine.  In libxslt's version, XSLT 1.0, a variable is a "result tree fragment", not a nodeset, and you are arbitrarily not allowed to do as much with it.

Further, Sablotron allows callbacks via the document() function (see information on xslt_set_scheme_handler()) and appears to give /slightly/ more informative error messages -- they identify the line number in the XSLT file at least.

In general, I can't recommend libxslt, which appears very underpowered.  Sablotron is considerably more impressive.
up
0
gabriel a-t bumpt do-t net
8 years ago
If you need to transform an XML document that specifies the URL of its own prefered stylesheet (using the processing instruction <?xml-stylesheet href="xyz.xsl"?>, you can start by parsing the XML data to retrieve that URL, and then call the xslt_process function using the specified stylesheet :

<?php

/* A small class for stylesheet URL extraction from an XML */

class XMLStylesheet
{
    var
$hParser;
    var
$xml;
    var
$stylesheet;

    function
XMLStylesheet($filename)
    {
       
$this->hParser = xml_parser_create();
       
xml_set_object($this->hParser, $this);
       
xml_set_processing_instruction_handler($this->hParser, 'fnProcessingInstruction');
       
$this->xml = file_get_contents($filename);
       
xml_parse($this->hParser, $this->xml, true);
       
xml_parser_free($this->hParser);
    }

    function
getStylesheet()
    {
        return
$this->stylesheet;
    }
   
    function
fnProcessingInstruction($hParser, $target, $data)
    {
        if(
$target == 'xml-stylesheet')
        {
           
ereg('href="([^"]+)"', $data, $regs);
           
$this->stylesheet = $regs[1];
        }
    }
}

/* Now, instanciate an object of this class, given the filename of our XML data */
$xml = new XMLStylesheet('my_data.xml');

/* And finally, retrieve the URL of the stylesheet specified in the XML data. */
$xsl_url = $xml->getStylesheet());

/* Now you can xslt_process as usual. */

?>
up
0
maurits at example dot com
8 years ago
I tried to get Sablotron runnning on a Windows XP - Apache 2 -PHP5 System which is my developement system. I have Sablotron running on a life Linux server. After spending lots of  effort I gave up on Sablotron on Windows.

Then I found out that there is Libxslt, and it is allready working!

I am missing a hint on this page, that Sablotron is not really recommended any more and that people should start to migrate their code to Libxslt.
up
0
Jon Dawson
9 years ago
Getting XSLT running under Red Hat/Plesk 7.5

The PHP installation on my VPS came with '--enable-xslt=shared' '--with-xslt-sablot' '--with-sablot-js=/usr' in the config line. However could not get any transformations to run. Finally got there following these steps:

1. ran 'yum install php-xslt'
2. This installed 'xslt.so' to usr/lib/php4 and other dependencies.
3. Add 'dl('xslt.so');' to the top of your php files you want to perform a translation in. e.g.

dl('xslt.so');
// Allocate a new XSLT processor
$xh = xslt_create();
// Process the document, returning the result into the $result variable
$result = xslt_process($xh, 'test.xml', 'test.xsl');
// Output to browser
echo $result;
up
0
Pete Silvester
9 years ago
When installing on debian using apt/binaries, after installing php4-xslt and sablotron, you may have to add this line to /etc/php4/apache/php.ini :

extension=xslt.so
up
0
arossato at istitutocolli dot org
9 years ago
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...
up
0
tom at kornack dot com
9 years ago
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 http://www.xmldatabases.org/WK/blog/1086?t=item . 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  ="http://www.w3.org/1999/XSL/Transform" 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>
up
0
will at NOSPAM dot wdp dot ndo dot co dot uk
10 years ago
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.
up
0
crtn at users dot sourceforge dot net
11 years ago
Another way to get around the EXPAT-SABLOTRON problems (seg faults) is supposedly to recompile apache with:
--disable-rule=EXPAT
up
0
d dot brotherstone at pobox dot com
11 years ago
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.
up
0
DrTebi at NOSPAM dot yahoo dot NOSPAM dot com
11 years ago
I would like to add that there is no problem to install PHP with Sablotron on a Gentoo Linux system (http://www.gentoo.org).

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 ;-)
up
0
ohlesbeauxjours at yahoo dot fr
11 years ago
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
up
0
aargh at 44rgh dot net
11 years ago
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.
up
0
jw at shapers dot nl
11 years ago
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.
up
0
gbarattoKILLSPAMMERS at superb dot net
11 years ago
Regarding the `__gxx_personality_v0' problem described by dennisNOSPAM@infoleak.com, you have to use LDFLAGS=-lstdc++  as well before configuring php (and not apache) when compiling php as a shared object.

Thank you Dennis
up
0
matthias-at-mlienau.de
11 years ago
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)
up
0
dennisNOSPAM at infoleak dot com
12 years ago
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.
up
0
ken1138 at altavista dot com
12 years ago
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.
up
0
Jaron dot Schaeffer at jayweb dot de
12 years ago
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);
  }
...

Jaron.Schaeffer@jayweb.de
up
0
sandro_zic at web dot de
12 years ago
[Editor's note: moved this note here where it belongs - jmcastagnetto@php.net]

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="http://www.w3.org/1999/XSL/Transform" 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>
-----------------------------------------
up
0
d dot u at mail dot com
13 years ago
... 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>
up
0
d dot u at mail dot com
13 years ago
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 (d.u@mail.com)
## 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 (d.u@mail.com)

       
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)
up
0
maximo at migliari dot com
13 years ago
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 - http://expat.sourceforge.com
    Sablot-0.52.tar.gz - http://www.gingerall.com
    php4-latest.tar.gz - http://snaps.php.net

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 :)
To Top