2
votes

I'm trying to combine multiple, smaller XML files into one large XML.

I have done some searching and am trying to use PHP / XML / XSL but I can't seem to get it right.

I'm using:

<?php

// Load the XML source
$xml = new DOMDocument;
$xml->load('collection.xml');

$xsl = new DOMDocument;
$xsl->load('vp.xsl');

// Configure the transformer
$proc = new XSLTProcessor;
$proc->importStyleSheet($xsl); // attach the xsl rules

echo $proc->transformToXML($xml);

?>

And here is the XSL file I'm using:

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output omit-xml-declaration="yes" indent="yes"/>

<xsl:param name="pdoc1Url" select="'http://www.domainname.com/pages/google-feed?page=1.xml'"/>
<xsl:param name="pdoc2Url" select="'http://www.domainname.com/pages/google-feed?page=2.xml'"/> 
<xsl:param name="pdoc3Url" select="'http://www.domainname.com/pages/google-feed?page=3.xml'"/>
<xsl:template match="/">

<documents>
<xsl:copy-of select="document($pdoc1Url)"/>
<xsl:copy-of select="document($pdoc2Url)"/>
<xsl:copy-of select="document($pdoc3Url)"/>
</documents>
</xsl:template>
</xsl:stylesheet>

However when I run the script nothing is combining? I know I'm doing something wrong but can't seem to find out exactly what that is. I think I'm using the PHP XSLT Processor incorrectly.

What is the best way to combine XML documents from multiple URLs into 1 xml? They all have the same formatting. Ideally I'd like to be able to view the combined XML from a URL.

The data I'm trying to combine is like these two URLs for example: http://www.domainname.com/pages/google-feed?page=1.xml http://www.domainname.com/pages/google-feed?page=2.xml

1
possible duplicate of XSLT: A simple way to merge xml filesGordon

1 Answers

0
votes

I was able to perform your transformation using Saxon 6.5.4. The transformation took more than 14 seconds on a fast 12GB RAM computer. 108209 lines were produced (and thus I am not placing the output here ... :) ).

There is an error in http://www.vitaminpartners.com/pages/google-feed?page=1.xml but Saxon recovered from this error. Quite probably the XSLT processor you are using doesn't recover from this error, or the computer you are using lacks enough memory.

Here are the messages from Saxon:

SAXON 6.5.4 from Michael Kay
Java version 1.6.0_31
Preparation time: 90 milliseconds
Processing file:/(Untitled)
Building tree for file:/(Untitled) using class com.icl.saxon.tinytree.TinyBuilder
Tree built in 6 milliseconds
Building tree for http://www.vitaminpartners.com/pages/google-feed?page=1.xml using class com.icl.saxon.tinytree.TinyBuilder
Error on line 28088 column 21 of http://www.vitaminpartners.com/pages/google-feed?page=1.xml:
  Error reported by XML parser: unexpected character after entity reference (found "<") (expected ";")
Recoverable error
org.xml.sax.SAXParseException: unexpected character after entity reference (found "<") (expected ";")
Building tree for http://www.vitaminpartners.com/pages/google-feed?page=2.xml using class com.icl.saxon.tinytree.TinyBuilder
Tree built in 6936 milliseconds
Building tree for http://www.vitaminpartners.com/pages/google-feed?page=3.xml using class com.icl.saxon.tinytree.TinyBuilder
Tree built in 4350 milliseconds
Execution time: 14845 milliseconds
Press any key to continue . . .