Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/xslt/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用XSLT合并两个XML文件_Xml_Xslt_Xpath - Fatal编程技术网

使用XSLT合并两个XML文件

使用XSLT合并两个XML文件,xml,xslt,xpath,Xml,Xslt,Xpath,我有两个xml文件,需要使用样式表将它们合并在一起 <AssessmentInput> <ApplicationData>...</AppicationData> <MetricList>...</MetricList> </AssessmentInput> ... ... 一个是ApplicationData,另一个是MetricList。 这就是我所做的,但与我应该做的完全不同 <?xml versi

我有两个xml文件,需要使用样式表将它们合并在一起

<AssessmentInput>
  <ApplicationData>...</AppicationData>
  <MetricList>...</MetricList>
</AssessmentInput>

...
...
一个是ApplicationData,另一个是MetricList。 这就是我所做的,但与我应该做的完全不同

<?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>


请帮帮我。我没有任何XSLT方面的经验。

您应该按照以下方式替换您的行:-

<xsl:param name="ApplicationData" select="/"/>
  <xsl:param name="MetricList"/>

下面的第一行:

   <xsl:variable name="Application_Data" select="document('Application_Data.xml')/ApplicationData"/>
 <xsl:variable name="'Metric_List" select="document('Application_Data.xml')/MetricList"/>


我认为这可能会帮助您..

提供以下输入文件:

ApplicationData.xml

<?xml version="1.0" ?>
<ApplicationData>
    Whatever data you have in here.
</ApplicationData>
<?xml version="1.0" ?>
<MetricList>
    Whatever list you have in here.
</MetricList>
<?xml version="1.0" ?>
<AssessmentInput />
<?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>

不管你这里有什么数据。
MetricList.xml

<?xml version="1.0" ?>
<ApplicationData>
    Whatever data you have in here.
</ApplicationData>
<?xml version="1.0" ?>
<MetricList>
    Whatever list you have in here.
</MetricList>
<?xml version="1.0" ?>
<AssessmentInput />
<?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>

不管你这里有什么清单。
AssessmentInput.xml

<?xml version="1.0" ?>
<ApplicationData>
    Whatever data you have in here.
</ApplicationData>
<?xml version="1.0" ?>
<MetricList>
    Whatever list you have in here.
</MetricList>
<?xml version="1.0" ?>
<AssessmentInput />
<?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>

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

<?xml version="1.0" ?>
<ApplicationData>
    Whatever data you have in here.
</ApplicationData>
<?xml version="1.0" ?>
<MetricList>
    Whatever list you have in here.
</MetricList>
<?xml version="1.0" ?>
<AssessmentInput />
<?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>

产生正确的输出

<?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>

不管你这里有什么数据。
不管你这里有什么清单。

您已经描述了输出的结构,但是输入XML文件的结构是什么?