Closed Thread Icon

Topic awaiting preservation: Translator: Perl -> PHP Pages that link to <a href="https://ozoneasylum.com/backlink?for=12792" title="Pages that link to Topic awaiting preservation: Translator: Perl -&amp;gt; PHP" rel="nofollow" >Topic awaiting preservation: Translator: Perl -&gt; PHP\

 
Author Thread
u-neek
Bipolar (III) Inmate

From: Berlin, Germany
Insane since: Jan 2001

posted posted 06-18-2003 15:38

Hi,
i found a great Perl program, that reads and writes XML Files. I tried to convert everything into PHP, but one function gives me headache. Here is the source (part of it):

code:
use strict;
use CGI;
use File::Copy;
use XML::LibXSLT;
use XML::LibXML;
.
.
.
my $filepath = "/full/path/to/cgi-bin/data";
my $xml = $q->param("data");
my $view = $q->param("view");
my $xmlFile = $year . $month;
.
.
.
sub modeEdit {

my $parser = XML::LibXML->new();
my $xslt = XML::LibXSLT->new();

my $file = "$filepath/$xml.xml";

my $source = $parser->parse_file($file);
my $style_doc = $parser->parse_file('$cgiPath/myxslfile.xsl');

my $stylesheet = $xslt->parse_stylesheet($style_doc);

my $results = $stylesheet->transform($source, view => "'$view'", month => "'$xmlFile'");

print "Content-type: text/html; charset=\"UTF-8\"\n\n";
print $stylesheet->output_string($results);
}



Could someone explain me every step in the function and give a hint to the equivalent PHP function?
Thanks

[Emp edit: Stopped HSBoD]

[This message has been edited by Emperor (edited 06-18-2003).]

[This message has been edited by u-neek (edited 06-18-2003).]

Emperor
Maniac (V) Mad Scientist with Finglongers

From: Cell 53, East Wing
Insane since: Jul 2001

posted posted 06-18-2003 16:13

u-neek: I'm sure there are ways and means to convert between the 2 but this:

quote:
my $parser = XML::LibXML->new();
my $xslt = XML::LibXSLT->new();



means that it is running from Perl modules and you won't be to simply convert things like that and it would be better to work from scratch. It depends on your setup but have a look at the Expat parser for PHP (and if you want XSLT Sablotron).

___________________
Emps

FAQs: Emperor

u-neek
Bipolar (III) Inmate

From: Berlin, Germany
Insane since: Jan 2001

posted posted 06-18-2003 17:13

I've installed both, XSLT & XML for PHP following a tutorial at http://www.phpbeginner.com/ and phpinfo() tells me, that it works correct.

bitdamaged
Maniac (V) Mad Scientist

From: 100101010011 <-- right about here
Insane since: Mar 2000

posted posted 06-18-2003 18:05

I haven't worked with XSLT in php but I have done XML parsing. And it's relatively easy. The PHP XML functions tend to work very simliarly to the Perl Library functions.

Take a look at the PHP XML parsing page for some examples.

I'd recommend figuring out what it means to parse an XML document and then go from there to transforming it.

The thing is there are a couple of way to parse an XML doc depending on how you want to use it. What does this script do?



.:[ Never resist a perfect moment ]:.

u-neek
Bipolar (III) Inmate

From: Berlin, Germany
Insane since: Jan 2001

posted posted 06-18-2003 18:29

WHOOOOOHOOO!

xslt_process is my friend. My PHP source:

code:
function modeEdit() {

global $filepath, $xml, $thisPath, $xmlFile, $view;

$file = $filepath ."/". $xml .".xml";
$XslFile = $thisPath ."/myxslfile.xsl";

$xslt = xslt_create();

$source = implode("", file($file));
$style_doc = implode("", file($XslFile));

$args = array('/_xml' => $source, '/_xsl' => $style_doc);
$params = array('view' => $view, 'month' => $xmlFile);

$result = xslt_process($xslt, 'arg:/_xml', 'arg:/_xsl', NULL, $args, $params);
IF (!$result) echo xslt_error($xslt);
echo $result;

xslt_free($xslt);

}



It is not ready yet! But it works as i want it

bitdamaged, this script only combines a xslt and a xml document.
These three tutorials will give some further informations on combining xml, xslt and php.

Whew

[This message has been edited by u-neek (edited 06-18-2003).]

« BackwardsOnwards »

Show Forum Drop Down Menu