如何使用 xsl 合并多个 xml 文件? [英] How to merge multiple xml files using xsl?

查看:69
本文介绍了如何使用 xsl 合并多个 xml 文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要在 1.0 中使用 uisng xsl 合并以下 3 个 xml 文件

I need to merge below 3 xml files uisng xsl in 1.0

<xmlResponse>
    <Person>
        <FirstName>FirstName_1</FirstName>
        <LastName>LastName_1</LastName>
    </Person>
    <Person>
        <FirstName>FirstName_2</FirstName>
        <LastName>LastName_2</LastName>
    </Person>
</xmlResponse>

在 XML 文件中:02.xml

<xmlResponse>
    <Person>
        <FirstName>FirstName_2</FirstName>
        <LastName>LastName_2</LastName>
    </Person>
    <Person>
        <FirstName>FirstName_3</FirstName>
        <LastName>LastName_3</LastName>
    </Person>
    <Person>
        <FirstName>FirstName_4</FirstName>
        <LastName>LastName_4</LastName>
    </Person>
</xmlResponse>

在 XML 文件中:03.xml

<xmlResponse>
    <Person>
        <FirstName>FirstName_5</FirstName>
        <LastName>LastName_5</LastName>
    </Person>
</xmlResponse>

我需要像下面这样的输出(01.xml + 02.xml + 03.XML)

<xmlResponse>
    <Person>
        <FirstName>FirstName_1</FirstName>
        <LastName>LastName_1</LastName>
    </Person>
    <Person>
        <FirstName>FirstName_2</FirstName>
        <LastName>LastName_2</LastName>
    </Person>
    <Person>
        <FirstName>FirstName_2</FirstName>
        <LastName>LastName_2</LastName>
    </Person>
    <Person>
        <FirstName>FirstName_3</FirstName>
        <LastName>LastName_3</LastName>
    </Person>
    <Person>
        <FirstName>FirstName_4</FirstName>
        <LastName>LastName_4</LastName>
    </Person>
    <Person>
        <FirstName>FirstName_5</FirstName>
        <LastName>LastName_5</LastName>
    </Person>
</xmlResponse> 

希望得到您的回应,tks...

hoping your response, tks...

推荐答案

使用document函数:

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

    <xsl:template match="/xmlResponse">
        <xsl:copy>
            <xsl:apply-templates select="Person"/>
            <xsl:apply-templates select="document('2.xml')/*/Person"/>
            <xsl:apply-templates select="document('3.xml')/*/Person"/>
        </xsl:copy>
    </xsl:template>

    <xsl:template match="@* | node()">
        <xsl:copy>
            <xsl:apply-templates select="@* | node()"/>
        </xsl:copy>
    </xsl:template>
</xsl:stylesheet>

这篇关于如何使用 xsl 合并多个 xml 文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆