[XSL-LIST Mailing List Archive Home] [By Thread] [By Date]

XML/XSL transformation page


Subject: XML/XSL transformation page
From: Eric van der Vlist <vdv@xxxxxxxxxxxx>
Date: Mon, 11 Oct 1999 14:49:24 +0200

Hi,

This message to share a simple php3 (http://www.php.net/) & phplib
oohforms (http://phplib.netuse.de) script allowing to type in xml & xsl
simple examples and displays the result of the transformation after
calling your favorite tool (XT http://www.jclark.com/xml/xt.html on my
box).

It's not rocket science, but I find it useful when I want to test simple
XML/XSL templates (for instance to answer questions on the XSL mailing
list :=), or to make sure I have understood a "detail" of the W3C
recommendations).

Please note that it shouldn't be used without modification on a public
sites as one can, through XSL statements, read and write on the server
file system.

I hope you'll enjoy it.

Eric

-------------------------------------------------------------
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
<HTML>
<HEAD>
<!- Copyright (c) 1999 Eric van der Vlist / Dyomedea

Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
``Software''), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:

The above copyright notice and this permission notice shall be included
in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED ``AS IS'', WITHOUT WARRANTY OF ANY KIND,
EXPRESS
OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
IN NO EVENT SHALL ERIC VAN DER VLIST AND/OR DYOMEDEA BE LIABLE FOR ANY
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
->

<title> XML/XSL transformation</title>
</HEAD>
<BODY>
<script language="php">

$classpath	="CLASSPATH=/opt/XP/xp.jar:/opt/XT/xt.jar:/opt/XT/sax.jar";
$xt		= "/opt/jdk1.2/bin/java  com.jclark.xsl.sax.Driver";

require("oohforms.inc");   

function transform(){
	global $xml, $xsl, $classpath, $xt;

	$filename="/tmp/".uniqid("xmlxsl");

	$fxml = fopen($filename.".xml", "w");
	fwrite($fxml, StripSlashes($xml));
	fclose($fxml);

	$fxsl = fopen($filename.".xsl", "w");
	fwrite($fxsl, StripSlashes($xsl));
	fclose($fxsl);

	putenv("$classpath");
	$fp = popen( "$xt $filename.xml $filename.xsl 2>&1", "r" );
	echo "<br>XSL Transformation (result) :<pre>";
	while ($buffer = fgets($fp, 4096)) {
		echo htmlentities($buffer);
	}
	echo "</pre>";
	pclose ($fp);

	unlink($filename.".xml");
	unlink($filename.".xsl");

}

	$f = new form;	

	$f->add_element(array("type"=>"textarea",
		"name"=>"xml",
		"rows"=>8,
		"cols"=>80,
		"value"=>"<?xml version='1.0' encoding='ISO-8859-1'?>
	"));

	$f->add_element(array("type"=>"textarea",
		"name"=>"xsl",
		"rows"=>8,
		"cols"=>80,
		"value"=>"<xsl:stylesheet
xmlns:xsl=\"http://www.w3.org/XSL/Transform/1.0\">


</xsl:stylesheet>"));

	$f->add_element(array("type"=>"submit",
		"name"=>"transform",
		"value"=>"transform"));

	if ($transform)      {           // Is there data to process?
		if ($err = $f->validate()) {   // Is the data valid?
			echo $err;                   // No; Display error
		}else {
			transform();
		}
		$f->load_defaults();  // Load form with submitted data
	}

	$f->start("jvcheck");                  // Start displaying form
	$element = $f->elements['xml']['ob'];
	$element->value = StripSlashes($element->value);
	$f->elements['xml']['ob'] = $element;
	$f->show_element("xml");
	echo "<br>";
	$element = $f->elements['xsl']['ob'];
	$element->value = StripSlashes($element->value);
	$f->elements['xsl']['ob'] = $element;
	$f->show_element("xsl");
	echo "<br>";
	$f->show_element("transform", "transform");
	$f->finish();

</script>
</BODY>
</HTML>

-- 
------------------------------------------------------------------------
Eric van der Vlist                                              Dyomedea

http://www.dyomedea.com                          http://www.ducotede.com
------------------------------------------------------------------------


 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list



Current Thread
Keywords