Multiple XML/XSLT files in PHP, transform one with XSLT and add others but process it first with PHP
- by ipalaus
I am processing XML files transformations with XSLT in PHP correctly. Actually I use this code:
$xml = new DOMDocument;
$xml->LoadXML($xml_contents);
$xsl = new DOMDocument;
$xsl->load($xsl_file);
$proc = new XSLTProcesoor;
$proc->importStyleSheet($xsl);
echo $proc->transformToXml($xml);
$xml_contents is the XML processed with PHP, this is done by including the XML file first and then assigning $xml_contents = ob_get_contents(); ob_end_clean();. This forces to process the PHP code on the XML, and it works perfectly.
My problem is that I use more than one XML file and this XML files has PHP code on it that need to be processed AND have a XSLT file associated to process the data. Actually I'm including this files in XSLT with the next code:
<!-- First I add the XML file -->
<xsl:param name="menu" select="document('menu.xml')" />
<!-- Next I add the transformations for menu.xml file -->
<xsl:include href="menu.xsl" />
<!-- Finally, I process it on the actual ("parent") XML -->
<xsl:apply-templates select="$menu/menu" />
My questiion is how I can handle this. I need to add mutiple XML(+XSLT) files to my first XML file that will containt PHP so it needs to be processed.
Thank you in advance!