【发布时间】:2012-05-08 03:59:01
【问题描述】:
这个问题有3个场景:
第一种可能性: 输入:
<root>
<node id="N1">
<fruit id="1" action="aaa">
<orange id="x" action="create">
<attribute>
<color>Orange</color>
<year>2012</year>
</attribute>
</orange>
<orange id="x" action="change">
<attribute>
<color>Red</color>
</attribute>
</orange>
<orange id="x" action="change">
<attribute>
<color>Blue</color>
<condition>good</condition>
</attribute>
</orange>
</fruit>
</node>
</root>
预期输出:
<root>
<node id="N1">
<fruit id="1" action="aaa">
<orange id="x" action="create">
<attribute>
<color>Blue</color>
<year>2012</year>
<condition>good</condition>
</attribute>
</orange>
</fruit>
</node>
</root>
第二种可能性: 输入:
<root>
<node id="N1">
<car id="1">
<bmw id="i" action="change">
<attribute>
<color>Blue</color>
<owner>a</owner>
</attribute>
</bmw>
<bmw id="i" action="change">
<attribute>
<color>Yellow</color>
<status>avaailable</status>
</attribute>
</bmw>
</car>
</node>
</root>
预期输出:
<root>
<node id="N1">
<car id="1">
<bmw id="i" action="change">
<attribute>
<color>Yellow</color>
<owner>a</owner>
<status>available</status>
</attribute>
</bmw>
</car>
</node>
</root>
第三种场景:
<root>
<node id="N1">
<car id="1">
<bmw id="j" action="delete">
<attribute>
<color>Blue</color>
<year>2000</year>
</attribute>
</bmw>
<bmw id="j" action="delete">
<attribute>
<color>Pink</color>
<status>available</status>
</attribute>
</bmw>
</car>
</node>
</root>
预期输出:
<root>
<node id="N1">
<car id="1">
<bmw id="j" action="delete">
<attribute>
<color>Pink</color>
<year>2000</year>
<status>available</status>
</attribute>
</bmw>
</car>
</node>
</root>
第二种和第三种情况的解释:
- 两个或多个具有“action=change”的节点将合并为一个具有“action=change”的节点
- 两个或多个具有“action=delete”的节点将合并为一个具有“action=delete”的节点
- 在合并时,我们更新我们只保留最后一个节点的值,保留初始节点并添加任何新的附加节点。
我希望解释清楚。
请告诉我有关此问题的 XSLT 解决方案。 谢谢。
亲切的问候, 约翰
【问题讨论】:
-
不清楚“创建”、“更改”和“删除”的所有“有效”序列是什么。如果没有先前的“创建”,序列如何以“删除”开头? “删除”是删除对象,还是只删除包含的属性?请编辑问题并解释。我不得不猜测重复“改变”动作的语义,在我看来,你还没有给我们一个完全有代表性的例子。在示例中,只有最后一个“更改”中包含的属性应与初始属性合并——猜想中间“更改”属性也必须合并。
-
@DimitreNovaatchev 我已经添加了更多解释,希望现在可以清除。这是创建、更改和删除订单的唯一可能方案。非常感谢。
-
@DimitreNovaatchev 嗨,你有没有可能解决这个问题?谢谢。
-
当我理解了问题——只有这样我才能回答。您发布的问题仍然没有完全定义,花时间解决这些问题是没有意义的。
-
@John,与您并行提出的问题相比,这个问题与构建这些属性的超集有些不同:stackoverflow.com/questions/10419095/…。您对我发布到该解决方案的解决方案是否满意,或者您需要同时实现这两种风格?