I'm currently trying to load external XML files and parse them in HTML using an XSL stylesheet. I use the XData Toolkit plugin to achieve this, and it works fine. However, this plugin requires me to create a new request for each XML file and use short code to load the content. Since I have many XML files, this method may not be very suitable for me.
Is there a way to load XML content and dynamically disclose it using XSLT on the page by passing a parameter (i.e. XML file name)?
Can I do this with the PHP script XSLTProcessor? Can I call a PHP script from a page in WordPress? If so, where can I save the PHP script? Maybe something like this?
<?php // Load the XML source $xml = new DOMDocument; $xml->load('file.xml'); $xsl = new DOMDocument; $xsl->load('stylesheet.xsl'); // Configure the transformer $proc = new XSLTProcessor; $proc->importStyleSheet($xsl); // attach the xsl rules echo $proc->transformToXML($xml); ?>
I am not very familiar with WordPress and PHP, so any suggestions are welcome. More info: Using the Pagelines theme and WordPress 3.4.1
source share