[英]copying content of one xml file into another xml file using xslt
我有一个xml文件,其中标记的属性是其他xml文件的src。
<a>
<b>
<c src="other1.xml" name="other1"></c>
<c src="other2.xml" name="other2"></c>
<c src="other3.xml" name="other3"></c>
</b>
</a>
我想将此xml文件的内容更改为以下格式
<a>
<b>
<other1> content of other1.xml </other1>
<other2> content of other2.xml </other2>
<other3> content of other3.xml </other3>
</b>
</a>
我尝试使用xsl:variable并在其中存储src的值,但出现错误。
有人请提出解决方案....甚至提示将不胜感激
应该这样做:
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" indent="yes"/>
<xsl:template match="@* | node()">
<xsl:copy>
<xsl:apply-templates select="@* | node()"/>
</xsl:copy>
</xsl:template>
<xsl:template match="c">
<xsl:element name="{@name}">
<xsl:apply-templates select="document(@src)" />
</xsl:element>
</xsl:template>
</xsl:stylesheet>
使用以下文件作为other1.xml,other2.xml和other3.xml:
<I xmlns="hello">
<am some="" xml="" />
</I>
<I xmlns="hello">
<amAlso xml="" />
</I>
<I>
<am xml="as well" />
</I>
并将示例XML作为输入运行,结果是:
<a>
<b>
<other1>
<I xmlns="hello">
<am some="" xml="" />
</I>
</other1>
<other2>
<I xmlns="hello">
<amAlso xml="" />
</I>
</other2>
<other3>
<I>
<am xml="as well" />
</I>
</other3>
</b>
</a>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.