RE: [xsl] Merging xml files

Subject: RE: [xsl] Merging xml files
From: ADAM PATRICK <adampatrick@xxxxxxxxxxxxxx>
Date: Tue, 9 Aug 2005 14:56:02 +0100 (BST)
thanks to mike for the tip the correct xsl if anyone
is interested...

<?xml version="1.0" encoding="ISO-8859-1"?>
<xsl:stylesheet
xmlns:xsl="http://www.w3.org/1999/XSL/Transform";
	version="1.0">
	
<xsl:output indent="yes"/>
<xsl:template match="ctt">
	<ctt>
		<xsl:variable name="docs"
select="document(./doc/@filename)"/>
		<xsl:for-each select="$docs">
			<xsl:copy-of select="./ctt/ctt_doc"/>
		</xsl:for-each>
	</ctt>
</xsl:template>
</xsl:stylesheet>

--- Michael Kay <mike@xxxxxxxxxxxx> wrote:

> select="./ctt_doc" should be select="./ctt/ctt_doc".
> The document() function
> selects the root node of the document, which is the
> parent of the outermost
> element.
> 
> Michael Kay
> http://www.saxonica.com/ 
> 
> > -----Original Message-----
> > From: ADAM PATRICK
> [mailto:adampatrick@xxxxxxxxxxxxxx] 
> > Sent: 08 August 2005 18:14
> > To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
> > Subject: [xsl] Merging xml files
> > 
> > Using Instant Saxon 6.5.3
> > 
> > I have seen previous posts but a bit comfounded at
> > getting it to work for me... want to merge
> identical
> > xml files using xslt
> > 
> > the following is what I have so far...any help on
> what
> > my stylesheet should be would be gratefully
> received,
> > thaks.
> > 
> > ctt.xml
> > 
> > <?xml version="1.0" encoding="ISO-8859-1"?>
> > <ctt>
> > <doc filename="test1.xml"/>
> > <doc filename="test2.xml"/>
> > <doc filename="test3.xml"/>
> > </ctt>
> > 
> > test1.xml - all xml files have the same format
> > 
> > <?xml version="1.0" encoding="ISO-8859-1"?>
> > <ctt>
> > <ctt_doc ctt_doc_ref="1">
> > <parent_doc_ref>testthis</parent_doc_ref>
> > </ctt_doc>
> > </ctt>
> > 
> > bad xslt stylesheet...(i.e. not working)
> > 
> > <?xml version="1.0" encoding="ISO-8859-1"?>
> > <xsl:stylesheet
> > xmlns:xsl="http://www.w3.org/1999/XSL/Transform";
> >  version="1.0">
> >  
> > <xsl:output indent="yes"/>
> > <xsl:template match="ctt">
> >  <ctt>
> >   <xsl:variable name="docs"
> > select="document(ctt/doc/@filename)"/>
> >   <xsl:for-each select="$docs">
> >    <xsl:copy-of select="./ctt_doc"/>
> >    <xsl:copy-of
> select="ctt/ctt_doc/parent_doc_ref"/>
> >   </xsl:for-each>
> >  </ctt>
> > </xsl:template>
> > </xsl:stylesheet>
> > 
> > current output upon:
> >  saxon -o newtest.xml ctt.xml merge.xsl
> > 
> > <?xml version="1.0" encoding="utf-8"?>
> > <ctt/>
> > 
> > would like...
> > 
> > <?xml version="1.0" encoding="ISO-8859-1"?>
> > <ctt>
> > <ctt_doc ctt_doc_ref="1">
> > <parent_doc_ref>testthis</parent_doc_ref>
> > </ctt_doc>
> > <ctt_doc ctt_doc_ref="2">
> > <parent_doc_ref>testthis</parent_doc_ref>
> > </ctt_doc>
> > <ctt_doc ctt_doc_ref="3">
> > <parent_doc_ref>testthis</parent_doc_ref>
> > </ctt_doc>
> > </ctt>

Current Thread