I have multiple xml files in a website directory folder called "jobs" and ive been trying to get any xml file that within that jobs folder to combine into one xml file called Output.xml
The PHP code i have partly works however it my issue is it doesn't combine all the xml files in that jobs directory into the output.xml unless i specify the filename. Now im a bit stuck as i dont know why it only shows one in that output.xml.
Here some example code:
XML1
<JobRecords>
<JobRecord>
<Brand>Corporate1</Brand>
<WorkTypes>
<WorkTypeRecord>
<Title>Permanent1</Title>
</WorkTypeRecord>
</WorkTypes>
</JobRecord>
</JobRecords>
XML2
<JobRecords>
<JobRecord>
<Brand>Corporate2</Brand>
<WorkTypes>
<WorkTypeRecord>
<Title>Permanent2</Title>
</WorkTypeRecord>
</WorkTypes>
</JobRecord>
</JobRecords>
XSLT (save as .xsl file in same directory as all XML files)
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/>
<xsl:strip-space elements="*"/>
<xsl:template match="/">
<files>
<xsl:copy-of select="/jobs"/>
<!-- add more as needed -->
</files>
</xsl:template>
</xsl:stylesheet>
PHP (load first XML and XSL scripts, then transform/output)
// LOAD XML SOURCE
$xml = new DOMDocument('1.0', 'UTF-8');
$xml->load('xml1.xml');
// LOAD XSL SOURCE
$xsl = new DOMDocument('1.0', 'UTF-8');
$xsl->load('XSLT_Script.xsl');
// TRANSFORM XML
$proc = new XSLTProcessor;
$proc->importStyleSheet($xsl);
$newXML = $proc->transformToXML($xml);
// SAVE NEW XML
file_put_contents('output.xml', $newXML);