Multiple XML/XSLT files in PHP, transform one with XSLT and add others but process it first with PHP

Posted by ipalaus on Stack Overflow See other posts from Stack Overflow or by ipalaus
Published on 2011-01-10T17:23:41Z Indexed on 2011/01/11 2:53 UTC
Read the original article Hit count: 197

Filed under:
|
|

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!

© Stack Overflow or respective owner

Related posts about php

Related posts about Xml