Jump to content

XSLT - problem with EXSLT document tag


NigelRen

Recommended Posts

I've been using the exslt document tag in an XSLT template for a while.  Something like

 

<?xml version="1.0" encoding="UTF-8"?>

<xsl:stylesheet version="1.0"

  xmlns:xsl="http://www.w3.org/1999/XSL/Transform"

  xmlns:exsl="http://exslt.org/common"

  xmlns:date="http://exslt.org/dates-and-times"

  extension-element-prefixes="exsl date">

<xsl:output method="text" />

<xsl:template match="/Schema/Table">

<exsl:document href="a.b" method="text">

A

</exsl:document>

</xsl:template>

 

</xsl:stylesheet>

Suddenly it's stopped working with

 

[Fri Feb 10 20:49:25 2012] [error] [client 192.168.122.1] PHP Warning:  XSLTProcessor::transformToXml(): File write for a.b refused in /var/www/gen/genX/GenModelClass.php on line 72, referer: http://192.168.122.35/gen/genMenu.php

[Fri Feb 10 20:49:25 2012] [error] [client 192.168.122.1] PHP Warning:  XSLTProcessor::transformToXml(): runtime error: file /var/www/gen/genX/GenModelClass.xsl line 9 element document in /var/www/gen/genX/GenModelClass.php on line 72, referer: http://192.168.122.35/gen/genMenu.php

 

So I assumed that it was write permissions to the directory it was using, but using fopen will create the file.  Even if I specify the file as file:///tmp/a.b doesn't work. ( I'm using Ubuntu as the server ).

 

Is there a working example out there which I could try and see if there is something wrong with my setup - or does someone know what's happening?

 

Link to comment
Share on other sites

I'm trying to generate sources from a database schema, but I removed all of the extra stuff in case there was something else causing problems.

 

I've managed to get the same thing working on a CentOS virtual machine I just set up - so it may be some permissions settings on the Ubuntu config.  I've tried to ensure all directories I've tried to write to are rwx for all users.  If there isn't anything obvious I may just end up scrapping or rebuilding the Ubuntu machine and try again.

 

 

Link to comment
Share on other sites

With the code...

 

$result = $xp->transformToXml($def);
if ( $result == false )	{
$err =  libxml_get_last_error();
echo "Error...". print_r(libxml_get_errors(),TRUE)  ."<br />";
}
else	{
echo $result;
}
echo "<b>Complete</b>";

 

All I get is...

 

Error...Array ( )

Complete

 

The one thing - is that I always seemed to get false even when it did work.  But I wasn't worried about that.

Link to comment
Share on other sites

:D :D :D

Finally found the problem... they've changed the defaults in the way XSLT is allowed to create files etc.  listed as a 'bug' ( have a read of https://bugs.php.net/bug.php?id=54446 ).

 

I've changed the code to be

 

$xp = new XsltProcessor();

//if you want to write from within the XSLT
if (version_compare(PHP_VERSION,'5.4',"<")) {
$oldval = ini_set("xsl.security_prefs",0);
} else {
$oldval = $xp->setSecurityPreferences(0);
}

$xsl = new DOMDocument();
$xsl->load("./GenModelClass.xsl");

$xp->importStylesheet($xsl);

 

And it now works.

 

Thanks for you help :)

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.