Reformatting/Sanitizing XML output into a simpler node tree - XSL/XSLT transformation with PHP
So I am employing an XSLT and a few lines of PHP to fish through the convoluted XML file to rebuild a nice cleaner and more precise XML node tree.
The PHP
<?php
$xml = new DomDocument;
$xml->load('http://myxmlsource.idonny.net.org/viewoutputfile?format=idxml');
$xsl = new DomDocument;
$xsl->load('http://idonny.net/sites/mypath/themes/cbixml/case_rss.xslt');
$proc = new xsltprocessor;
$proc->importStyleSheet($xsl);
$result = $proc->transformToXML($xml);
print $result; // print output of the mash
?>
Here is the XSLT file that is being applied to the colvoluted XML
<?xml version="1.0" encoding="ISO-8859-1"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output
method="xml"
encoding="ISO-8859-1"
omit-xml-declaration="no"
standalone="no"
cdata-section-elements="description"
indent="yes"
media-type="text/xml" />
<xsl:template match="/drupal_page/div/div/div/ul">
<cbixml>
<xsl:for-each select="li">
<cbinode>
<title><xsl:value-of select="node/title"/></title>
<industry_sector><xsl:value-of select="node/industry_sector/ul/li/a"/></industry_sector>
<link>http://idonny.com/node/<xsl:value-of select="node/id"/></link>
<id><xsl:value-of select="node/id"/></id>
<image_path><xsl:value-of select="node/image/img/@src"/></image_path>
<description><xsl:value-of select="node/description"/></description>
</cbinode>
</xsl:for-each><!-- /item -->
</cbixml>
</xsl:template>
</xsl:stylesheet>
Naturally, you can have the XSLT file pull and place anything you want fromt eh source XML file to result in a new strcuture/format
Enjoy!


