Rob
Rob

Reputation: 193

XSLT Transformation Using msxsl="urn:schemas-microsoft-com:xslt"

I have an XSLT stylesheet with the following header

  <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    xmlns:lxslt="http://xml.apache.org/xslt"
    xmlns:redirect="org.apache.xalan.xslt.extensions.Redirect"
    extension-element-prefixes="redirect"
   xmlns:msxsl="urn:schemas-microsoft-com:xslt" xmlns:my-ext="ext1">

I have also have custom functions:

<msxsl:script language="JavaScript" implements-prefix="my-ext">

    var lineCounter = 0;
    var totalPages = 0;
    var currentPage = 1;
    var currentObject = '';
    var colSpan = 0;

    function getLineCounter()
    {
        return lineCounter;
    }

    function updateLineCounter(aValue)
    {
        lineCounter += aValue;
         return '';
    }

My custom functions are used throughout my xsl. When I transform my XML using this XSL from a command line, using msxsl.exe it works perfectly and produces perfect HTML.

OK, here's my issue: I'm trying to use PHP to perform the transformation on the server and send back results. I have used this procedure many times before without issue; howver, this is the first time I've tried it with MSXSL extensions and functions.

Sample errors look like:

Warning: XSLTProcessor::transformToXml() [xsltprocessor.transformtoxml]: xmlXPathCompOpEval: **function resetAll not found** in D:\Development\AppServ\www\RJFWEB\jqueryFileTree\PHPMain.php on line 49

Warning: XSLTProcessor::transformToXml() [xsltprocessor.transformtoxml]: **Unregistered function** in D:\Development\AppServ\www\RJFWEB\jqueryFileTree\PHPMain.php on line 49

We can see that functions are not found/understood - although this is the same code I run at command line using msXSL.exe.

SO, ultimately I'm trying to find out if there's something I need to fix/add in my PHP.ini to understand how to use the MS extensions OR do I need to change the XSL stylesheets?

Man... I hope this question makes sense! Any help appreciated. Thanks.

Rob

My phpInfo displays

**XSL**
XSL                                      enabled
libxslt Version                              1.1.23
libxslt compiled against libxml Version      2.6.32
EXSLT                                    enabled
libexslt Version                             0.8.13

Upvotes: 0

Views: 3921

Answers (1)

Martin Honnen
Martin Honnen

Reputation: 167726

The msxsl:script is a proprietary extension allowing you to write extension functions with JScript or VBScript, I don't think libxslt supports that. With PHP 5 and libxslt you can however write extension functions in PHP, see http://php.net/manual/en/xsltprocessor.registerphpfunctions.php. So that seems to be the way to go, if you can't use pure XSLT to implement your requirements, then you need to port the functions written in J(ava)Script to PHP and make use of http://php.net/manual/en/xsltprocessor.registerphpfunctions.php to use those functions in XSLT.

As an alternative, in case you run PHP on Windows where you have MSXML available, you might want to try to use it from PHP, it should be possible with the help of http://www.php.net/manual/en/class.com.php e.g. new COM("MSXML2.DomDocument.3.0") for instance should give you an MSXML DOM document with a transformNode method to run your stylesheet using msxsl:script.

Upvotes: 1

Related Questions