Hi, I'm new to XSLT and I got some problems with it. I want to merge 2 XML files. I want to copy everything from a main file and a specific element with its childs from a second file into the main root Element. Example: Main File:
<?xml version="1.0" encoding="utf-8"?><CAEXFile SchemaVersion="2.15" ...> <InstanceHierarchy Name="Example"> ...A lot of elements... </InstanceHierarchy></CAEXFile>
2nd File:
<CAEXFile ...> <SystemUnitClassLib Name="Function"> ...A lot of elements... </SystemUnitClassLib></CAEXFile>
Final File:
<?xml version="1.0" encoding="utf-8"?><CAEXFile SchemaVersion="2.15" ...> <InstanceHierarchy Name="Example"> ...A lot of elements... </InstanceHierarchy> <SystemUnitClassLib Name="Function"> ...A lot of elements... </SystemUnitClassLib></CAEXFile>
My try looks like this:
<?xml version="1.0" encoding="UTF-8"?> <xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"><xsl:template match="CAEXFile"><xsl:copy> <xsl:apply-templates select="@* | node()" /></xsl:copy></xsl:template> <xsl:template match="node() | @*"><xsl:copy-of select="." /></xsl:template> </xsl:stylesheet>
It copies the file correct, but how do I get the information out of the 2nd file? I tried something like this:
<xsl:apply-templates match="document('my2ndFile.xml')/SystemUnitClassLib/node()" />
but without success. I found some Topics which had the same issue, but it couldn't help me. I'd be very thankful for any help.