-2

我需要一些帮助来使用 XSLT 合并 2 个 xml 文件。下面我放置了一些示例文件。请按照以下

第一个 XML 文件 (1.xml)

<?xml version="1.0" encoding="UTF-8"?>
<rowset  xmlns="urn:schemas-microsoft-com:xml-analysis:rowset"  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<Row>
    <Column0>1</Column0>
    <Column1>aaa</Column1>
    <Column2>a1</Column2>
</Row>
<Row>
    <Column0>2</Column0>
    <Column1>bbb</Column1>
    <Column2>b1</Column2>
</Row>
<Row>
    <Column0>3</Column0>
    <Column1>ccc</Column1>
    <Column2>c1</Column2>
</Row>

</rowset>

第二个 XML 文件 (2.xml)

<?xml version="1.0" encoding="UTF-8"?>
<rowset  xmlns="urn:schemas-microsoft-com:xml-analysis:rowset"  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">

<Row>
    <Column0>3</Column0>
    <Column1>ddd</Column1>
    <Column2>d1</Column2>
</Row>
<Row>
    <Column0>4</Column0>
    <Column1>eee</Column1>
    <Column2>e1</Column2>
</Row>
<Row>
    <Column0>1</Column0>
    <Column1>aaa</Column1>
    <Column2>a1</Column2>
</Row>

</rowset>

预期产出

<?xml version="1.0" encoding="UTF-8"?>
<rowset  xmlns="urn:schemas-microsoft-com:xml-analysis:rowset"  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<Row>
    <Column0>1</Column0>
    <Column1>aaa</Column1>
    <Column2>a1</Column2>
</Row>
<Row>
    <Column0>2</Column0>
    <Column1>bbb</Column1>
    <Column2>b1</Column2>
</Row>
<Row>
    <Column0>3</Column0>
    <Column1>ccc</Column1>
    <Column2>c1</Column2>
</Row>

<Row>
    <Column0>3</Column0>
    <Column1>ddd</Column1>
    <Column2>d1</Column2>
</Row>
<Row>
    <Column0>4</Column0>
    <Column1>eee</Column1>
    <Column2>e1</Column2>
</Row>
<Row>
    <Column0>1</Column0>
    <Column1>aaa</Column1>
    <Column2>a1</Column2>
</Row>

</rowset>

谁能帮我...


谢谢,JP

4

1 回答 1

0

试试这个:

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
  <xsl:output indent="yes" method="xml"/>
  <xsl:param name="file1" select="document('Untitled1.xml')"/>
  <xsl:param name="file2" select="document('Untitled2.xml')"/>
  <xsl:key name="Column" match="*[starts-with(name(), 'Column')]" use="self::*"/>
  <xsl:template match="/">
    <rowset  xmlns="urn:schemas-microsoft-com:xml-analysis:rowset"  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
    <xsl:copy-of select="$file1//*:Row"/>
    <xsl:copy-of select="$file2//*:Row"/>
      </rowset>
  </xsl:template>
</xsl:stylesheet>
于 2013-04-29T12:36:29.297 回答