XML parsing with XSLT in Wordpress

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

+4
source share
1 answer

Wordpress has a built-in XML processor that can be easier to use if you are the ultimate goal of displaying content.

If it’s easier for you to include the PHP script you wrote to convert the channels or import the library, you can put the script in the theme folder (for example, / wp-content / themes / pagelines /) and call this with include_once :

include_once(get_template_directory().'/FILENAME.php');

0
source

Source: https://habr.com/ru/post/1441773/


All Articles