问题描述:

the question is, is there an other (better) way to implement the thing i did.

What I was trying is, to make a XSLT to write a file onto the server where the XSLT is running.

Note: It has to be XSLT-1.0 cause it is called by a PHP scrip.

The PHP script is running on a local server and is called from a java program

The XSLT generates a message send back to the java program, so i can't use <xsl:output method="xml"/>

Input in my XSLT is a XML, and within it, there is an other XML, which is base64 encoded.

My approach to this Problem is, that I am using a PHP-call-back

XLST

<!--base64 decode the file so it can be written onto the server-->

<xsl:variable name="base64decode">

<xsl:if test="not(contains($login ,'Invalid')))">

<xsl:value-of select="php:function('base64_decode', string($product))"/>

</xsl:if>

</xsl:variable>

<!--php call-back to write the file onto the server-->

<xsl:variable name="fileputcontent">

<xsl:if test="$base64decode != ''">

<xsl:value-of select="php:function('postProduct::wirteFileOnServer', string($base64decode))"/>

</xsl:if>

</xsl:variable>

PHP

class postProduct {

public static function writeFileOnServer($file, $path){

file_put_contents($path, $file);

$ret = new DOMDocument('1.1', 'UTF-8');

if(not(is_file($path))){

$res = '<error>';

$res.= '<msg>An Error occurred</msg>';

$res.= '</error>';

}

$res = '<data>'.$res.'</data>';

$res = $ret->loadXML($res, LIBXML_NOERROR | LIBXML_NOWARNING);

if ($res !== TRUE) {

$ret->appendChild($err);

}

return $ret;

}

}

相关阅读:
Top