与xsl合并元素 [英] merging elements with xsl

查看:44
本文介绍了与xsl合并元素的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有多个xml元素,它们实际上是指相同的对象",它们可能具有相同的数据,或者它们可能具有不同的数据.任何一个都可能具有其他元素所没有的元素.我希望我的xsl输出所有这些xml对象"的元素总和.我们不会担心重叠.如何使用XSL这样合并?

I have multiple xml elements which actually refer to the same "object", they may have the same data, or they may have different data. Any may have elements which the others do not. I want my xsl to output the sum of the elements of all of these xml "objects". We won't worry about overlap. How can you merge like this using XSL?

示例:

<root>
<object>
<property1>value</property1>
</object>
<object>
<property1>value</property1>
<property2>value</property2>
</object>
...
<object>
<propertyN>value</propertyN>
</object>
</root>

结果:

<root>
<object>
<property1>value</property1>
<property2>value</property2>
...
<propertyN>value</propertyN>
</object>
</root>

推荐答案

此转换已应用于您的示例.xml

This transform applied to your sample .xml

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0"      xmlns:ext="www.foo.com">
<xsl:output method="xml" indent="yes"/>

<xsl:template match="/">
<root>
  <object>
    <xsl:for-each select="/root/object//*">
      <xsl:copy-of select="."/>
    </xsl:for-each>
  </object>
</root>
</xsl:template>
</xsl:stylesheet>

产生此输出:

<?xml version="1.0" encoding="UTF-8"?>
<root>
<object>
  <property1>value</property1>
  <property1>value</property1>
  <property2>value</property2>
  <propertyN>value</propertyN>
</object>
</root>

尽管您稍后可能会想做得更好,但这应该可以帮助您.

Although you will probably want to do something better later, this should get you going.

这篇关于与xsl合并元素的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆