对元素进行分组并删除重复节点 - XSLT 1.0
我查看了 慕尼黑分组 - 组内节点,不在整个文档内,但它对我来说不太有效。仅靠慕尼黑方法也不适合我。
我还查看了 XSLT 1.0:分组和删除重复,但不能完全遵循它。
我有以下 XML:
<?xml version="1.0" encoding="UTF-8"?>
<MT_MATERIALDATA>
<items item="475053">
<Recordset>
<CodeBusinessUnit>99</CodeBusinessUnit>
<PriceValue>250</PriceValue>
</Recordset>
<Recordset>
<CodeBusinessUnit>1</CodeBusinessUnit>
<PriceValue>250</PriceValue>
</Recordset>
</items>
<items item="475054">
<Recordset>
<CodeBusinessUnit>1</CodeBusinessUnit>
<PriceValue>255.34</PriceValue>
</Recordset>
<Recordset>
<CodeBusinessUnit>10</CodeBusinessUnit>
<PriceValue>299</PriceValue>
</Recordset>
</items>
</MT_MATERIALDATA>
结果应如下所示:
<?xml version="1.0" encoding="UTF-8"?>
<MT_MATERIALDATA>
<Mi item="475053">
<PriceList>
<Prices>
<Price Value="250"/>
<PriceConfig>
<Stores>99,1</Stores>
</PriceConfig>
</Prices>
</PriceList>
</Mi>
<Mi item="475054">
<PriceList>
<Prices>
<Price Value="255.34"/>
<PriceConfig>
<Stores>1</Stores>
</PriceConfig>
</Prices>
<Prices>
<Price Value="299"/>
<PriceConfig>
<Stores>10</Stores>
</PriceConfig>
</Prices>
</PriceList>
</Mi>
</MT_MATERIALDATA>
因此,对于匹配
元素 在
中,所有相应的
都需要在
中列出。 如果没有,则需要创建一个额外的
节点。
我已经尝试了几个小时,但商店编号总是重复,或者即使 PriceValue 相同,它们也不会聚合。
I have looked at Muenchian Grouping - group within a node, not within the entire document but it is not quite working for me. The Muenchian method alone does not do it either for me.
I have also looked at XSLT 1.0: grouping and removing duplicate but cannot follow it completely.
I have the following XML:
<?xml version="1.0" encoding="UTF-8"?>
<MT_MATERIALDATA>
<items item="475053">
<Recordset>
<CodeBusinessUnit>99</CodeBusinessUnit>
<PriceValue>250</PriceValue>
</Recordset>
<Recordset>
<CodeBusinessUnit>1</CodeBusinessUnit>
<PriceValue>250</PriceValue>
</Recordset>
</items>
<items item="475054">
<Recordset>
<CodeBusinessUnit>1</CodeBusinessUnit>
<PriceValue>255.34</PriceValue>
</Recordset>
<Recordset>
<CodeBusinessUnit>10</CodeBusinessUnit>
<PriceValue>299</PriceValue>
</Recordset>
</items>
</MT_MATERIALDATA>
The outcome should look like this:
<?xml version="1.0" encoding="UTF-8"?>
<MT_MATERIALDATA>
<Mi item="475053">
<PriceList>
<Prices>
<Price Value="250"/>
<PriceConfig>
<Stores>99,1</Stores>
</PriceConfig>
</Prices>
</PriceList>
</Mi>
<Mi item="475054">
<PriceList>
<Prices>
<Price Value="255.34"/>
<PriceConfig>
<Stores>1</Stores>
</PriceConfig>
</Prices>
<Prices>
<Price Value="299"/>
<PriceConfig>
<Stores>10</Stores>
</PriceConfig>
</Prices>
</PriceList>
</Mi>
</MT_MATERIALDATA>
So for matching <PriceValue>
elements
in <Recordset>
, all respective <CodeBusinessUnits>
need to be listed in <Stores>
.
If not, an extra <Prices>
node needs to be created.
I have been trying for hours but either the Store-numbers are always duplicate or they are not aggregated even if the PriceValue is the same.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
此转换:
当应用于提供的 XML 文档时:
产生所需的正确结果:
This transformation:
when applied on the provided XML document:
produces the wanted, correct result:
我认为以下解决了问题,至少对于分组而言:
I think the following solves the problem, at least for the grouping:
我还将发布一个样式表,因为每个人都会这样做:
注意:按商品和价格对商店进行分组。拉式风格比推式风格多一点(那是因为没有重复的@item。)
输出:
我认为我们涵盖了所有变体:键值、推拉、序列分隔符条件。
I'm also going to post an stylesheet, because everybody do it:
Note: Grouping stores by item and price. A little more pull than push style (That's because there is no duplicate @item.)
Output:
I think we cover all the variations: key value, push-pull, sequence separator condition.