使用XSLT合并两个XML文件

use*_*881 6 xml xslt xpath

I have 2 xml files which I need to merge together using a style sheet

<AssessmentInput>
  <ApplicationData>...</AppicationData>
  <MetricList>...</MetricList>
</AssessmentInput>
Run Code Online (Sandbox Code Playgroud)

One is ApplicationData and the other one is MetricList. here is what I have done but it is nothing close to what it should be

<?xml version="1.0" encoding="ascii"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:exslt="http://exslt.org/common" exclude-result-prefixes="xsl exslt">
    <xsl:output omit-xml-declaration="yes" method="xml" encoding="UTF-8"/>
    <xsl:param name="ApplicationData" select="/"/>
    <xsl:param name="MetricList"/>
    <xsl:template match="/">
        <xsl:apply-templates select="$ApplicationData/ApplicationData"/>
    </xsl:template>
    <xsl:template match="ApplicationData">
        <xsl:copy>
            <xsl:apply-templates select="@*"/>
            <xsl:apply-templates select="*"/>
        </xsl:copy>
    </xsl:template>
    <xsl:template match="@* | node()">
        <xsl:copy>
            <xsl:apply-templates select="@* | node()"/>
        </xsl:copy>
    </xsl:template>
</xsl:stylesheet>
Run Code Online (Sandbox Code Playgroud)

Please help me. I don't have any experience with XSLT.

hie*_*ppe 8

给定以下输入文件:

ApplicationData.xml

<?xml version="1.0" ?>
<ApplicationData>
    Whatever data you have in here.
</ApplicationData>
Run Code Online (Sandbox Code Playgroud)

MetricList.xml

<?xml version="1.0" ?>
<MetricList>
    Whatever list you have in here.
</MetricList>
Run Code Online (Sandbox Code Playgroud)

AssessmentInput.xml

<?xml version="1.0" ?>
<AssessmentInput />
Run Code Online (Sandbox Code Playgroud)

以下转换merge.xsl应用于AssessmentInput.xml

<?xml version="1.0" ?>
<xsl:transform
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    version="1.0">
    <xsl:template match="/AssessmentInput">
        <xsl:copy>
            <xsl:copy-of select="document('ApplicationData.xml')" />
            <xsl:copy-of select="document('MetricList.xml')" />
        </xsl:copy>
    </xsl:template>
</xsl:transform>
Run Code Online (Sandbox Code Playgroud)

产生正确的输出

<?xml version="1.0" encoding="UTF-8"?>
<AssessmentInput>
    <ApplicationData>
        Whatever data you have in here.
    </ApplicationData>
    <MetricList>
        Whatever list you have in here.
    </MetricList>
</AssessmentInput>
Run Code Online (Sandbox Code Playgroud)