我正在尝试使用xsl转换将数据从file1复制到file2。我可以复制数据,但不能复制到我想要的位置。请帮助我将数据复制到正确的位置。这是我的代码:
file1.xml:
<Org>
<Department name="Environmental" />
</Org>
file2.xml:
<Org>
<Division>Engineering</Division>
<Address>123 Elm Street</Address>
</Org>
result.xml:
<Org>
<Division>Engineering</Division>
<Address>123 Elm Street</Address>
</Org>
<Department name="Environmental" />
所需的输出:
<Org>
<Department name="Environmental">
<Division>Engineering</Division>
<Address>123 Elm Street</Address>
</Department>
</Org>
这是我的xsl文件中的代码:
<xsl:template match="//*[local-name()='Org'][*[local-name()='Department']]">
<xsl:copy>
<xsl:apply-templates select="@*" />
<xsl:copy>
<xsl:copy-of select="document($lookup)/Agency/Division" />
<xsl:copy-of select="document($lookup)//Agency/Address" />
</xsl:copy>
<xsl:apply-templates select="node()" />
</xsl:copy>
有人可以帮助我解决此问题吗?
感谢您的帮助。
答案 0 :(得分:0)
将XSLT模板更改为以下内容。变量Bundle.main.url(forResource: "theBinary", withExtension: nil)
应包含文件名和路径lookup
。
file2.xml
输出为:
<!-- Copies the 'Org' node of file1.xml and applies the templates on the child elements -->
<xsl:template match="/*[local-name()='Org']">
<xsl:copy>
<xsl:apply-templates select="*" />
</xsl:copy>
</xsl:template>
<!-- Copies the 'Department' node of file1.xml and then includes the values from file2.xml (in $lookup variable) -->
<xsl:template match="*[local-name()='Department' and parent::*[local-name()='Org']]">
<xsl:copy>
<xsl:copy-of select="@*" /> <!-- Copy the @name attribute (and possible others) -->
<xsl:copy-of select="document($lookup)/Org/Division" />
<xsl:copy-of select="document($lookup)/Org/Address" />
<xsl:apply-templates select="node()" />
</xsl:copy>
</xsl:template>