我有两个xml结构中需要合并的两个变量。我试图在stackoverflow上基于不同的awnsers编写XSLT样式表,但是我没有成功。XSLT合并两个XML结构
第一个的结构是这样的:
<root>
<content>
<text-block>
<descriptionHead>
Some description text for the text block head.
</descriptionHead>
<description>
Some description text block text.
</description>
</text-block>
<shortDescription>
<textHead>
Example text for the short description head.
</textHead>
<textBody>
Example text for the short description text body.
</textBody>
</shortDescription>
<longDescription>
<textHead>
Example text for the long description head.
</textHead>
<textBody>
Example text for the short description text body.
</textBody>
</longDescription>
</content>
</root>
,第二个看起来像这样:
<root>
<content>
<text-block>
<descriptionHead>
Some text 1.
</descriptionHead>
<description>
Some text 2.
</description>
</text-block>
<shortDescription>
<textHead></textHead>
<textBody></textBody>
</shortDescription>
<longDescription>
<textHead>
Some text 3.
</textHead>
<textBody></textBody>
</longDescription>
</content>
</root>
正如你在第二个看到有一些遗漏的信息。 在shortDescription中,缺少textHead和textBody的文本,在longDescription中缺少textBody的文本。可能缺少文本,文本或全部文本。 现在我想从第一个xml结构中取出缺失的信息并将它们复制到第二个结构中,并用div标记标记更改。
输出应该看起来像:
<root>
<content>
<text-block>
<descriptionHead>
Some text 1.
</descriptionHead>
<description>
Some text 2.
</description>
</text-block>
<shortDescription>
<textHead>
<div class="merged">
Example text for the short description head.
</div>
</textHead>
<textBody>
<div class="merged">
Example text for the short description text body.
</div>
</textBody>
</shortDescription>
<longDescription>
<textHead>
Some text 3.
</textHead>
<textBody>
<div class="merged">
Example text for the short description text body.
</div>
</textBody>
</longDescription>
</content>
</root>
我可以使用XSLT 2.0该任务。用XSLT做这样的事情有可能吗?
xslt是否过度杀伤?一个简单的应用程序可以完成非常简单.. –