My PHP Parser
Code: Select all
<?php
//REQUIRED INPUTS:
// - xml: path to xml document
// - xsl: path to xsl style sheet
// - pCount: number of parameters to be passed to xslt (send zero '0' if none)
//OPTIONAL INPUTS (must have as many as specified in pCount, increment '1' in
//names below up a number for each iteration):
// - p1n: name of first parameter
// - p1v: value of first parameter
//SET Paths
$xmlPath = $_GET['xml'];
$xslPath = $_GET['xsl'];
// Load the XML source
$xml = new DOMDocument;
$xml->load($xmlPath);
$xsl = new DOMDocument;
$xsl->load($xslPath);
// Configure the transformer
$proc = new XSLTProcessor;
$proc->importStyleSheet($xsl); // attach the xsl rules
//Set Parameter(s), if present
$xslParamCount = $_GET['pCount']; //Check number of xsl parameters specified in GET
for ($i=1; $i<=$xslParamCount; $i++){
$xslParamName = $_GET['p'.$i.'n'];
$xslParamValue = $_GET['p'.$i.'v'];
$proc->setParameter( '', $xslParamName, $xslParamValue); //Set parameters for XSLTProcessor
}
// TRANSFORM
echo $proc->transformToXML($xml);
// SET Mime Type
$mime = "application/xhtml+xml";
$charset = "iso-8859-1";
header("Content-Type: $mime;charset=$charset");
?>