我有兩個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是否過度殺傷?一個簡單的應用程序可以完成非常簡單.. –