gpt4 book ai didi

xml - 使用 XSLT 合并两个 XML 文件

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

我有 2 个 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 没有任何经验。

最佳答案

给定以下输入文件:

ApplicationData.xml

<?xml version="1.0" ?>
<ApplicationData>
Whatever data you have in here.
</ApplicationData>

MetricList.xml

<?xml version="1.0" ?>
<MetricList>
Whatever list you have in here.
</MetricList>

AssessmentInput.xml

<?xml version="1.0" ?>
<AssessmentInput />

以下转换 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>

产生正确的输出

<?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 - 使用 XSLT 合并两个 XML 文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19021205/

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