XML 中的重复节点
我想应用 XSL 样式表来删除 xml 中的重复节点。 我测试了一些解决方案,但我做不到:( 我的程序在 Visual C# Studio 中。
我有以下 XML:
<store>
<laptop>
<ID>1</ID>
<price>X2</price>
</laptop>
<laptop>
<ID>2</ID>
<price>X1</price>
</laptop>
<laptop>
<ID>8</ID>
<price>X2</price>
</laptop>
<laptop>
<ID>2</ID>
<price>X3</price>
</laptop>
</store>
所需的输出是:
<store>
<laptop>
<ID>1</ID>
<price>X2</price>
</laptop>
<laptop>
<ID>8</ID>
<price>X2</price>
</laptop>
<laptop>
<ID>2</ID>
<price>X3</price>
</laptop>
</store>
I want to apply a XSL style sheet that delete duplicate nodes in my xml.
I test some solution but i can't do it :( my program is in Visual C# Studio.
I have the following XML:
<store>
<laptop>
<ID>1</ID>
<price>X2</price>
</laptop>
<laptop>
<ID>2</ID>
<price>X1</price>
</laptop>
<laptop>
<ID>8</ID>
<price>X2</price>
</laptop>
<laptop>
<ID>2</ID>
<price>X3</price>
</laptop>
</store>
The desired output is:
<store>
<laptop>
<ID>1</ID>
<price>X2</price>
</laptop>
<laptop>
<ID>8</ID>
<price>X2</price>
</laptop>
<laptop>
<ID>2</ID>
<price>X3</price>
</laptop>
</store>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
下面的解决方案满足您的要求,并按以下方式工作:
下面没有具有相同值的 ID 标签(这就是 ID 2 出现在
输出结束)
欢迎所有的孩子
发表评论,这是我近两年来第一次尝试 XSL。
我尝试了 xsl:copy 但它未能包含子级的标签名称,但值显示了,无法弄清楚为什么!?
摘自其内容:
工作代码:
The solution below does what you are asking for and works the following way:
not have a ID tag below with the same value (thats why ID 2 comes at
the end of the output)
and all of it's children
Comments are welcome, this is my first try at XSL in the last two years.
I tried a xsl:copy but it failed to include the children's tag names, but the values showed up, couldn't figure out why!?
Taken somewhat out of it's contents:
Working code: