gpt4 book ai didi

xml - 如何使用 xsl 合并多个 xml 文件?

转载 作者:数据小太阳 更新时间:2023-10-29 01:47:05 24 4
gpt4 key购买 nike

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

在 XML 文件中:01.xml

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

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

最佳答案

使用文档函数:

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

关于xml - 如何使用 xsl 合并多个 xml 文件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9210134/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com