Lots of
working codes using PHP are available in the internet for transforming
the XML files using XSL.
$xsltrans
= new DomDocument();
$xsltrans->load("XSL_file.xsl");
$xmlinput = new DomDocument();
$xmlinput->load("XML_file.xml");
$transobj = new XsltProcessor();
$transobj->registerPhpFunctions();
$xsltrans = $transobj->importStylesheet($xsltrans);
$result = $transobj->transformToDoc($xmlinput);
print $result->saveXML();
_______________________________________________
The above
sample code will transform the "XML_file.xml" using the stylesheet
"XSL_file.xsl". From the code you can see that two DOM objects
are created. One is to load the XML file and the other is to load the
XSL file.
The 'new
DomDocument()' is used to create the DOM object. This object has the
'load' method, which is used to load the XML and the XSL file into them.
Once this is done a XSLT processor instance is created with the command
'new XsltProcessor()'.
The importStylesheet
method and the transformToDoc method of this processor instance are
used to import the stylesheet and then do the transformation. Then the
result is printed out.