【发布时间】:2018-06-09 12:40:47
【问题描述】:
我正在努力使用 XSLT 完成这项工作:
我需要从 XML 中删除重复节点,但它与通常的不同,因为这些节点可能位于不同的父节点中,我不能只删除第一个出现的节点,但有一个优先级规则。
这是我的输入
<?xml version="1.0" encoding="UTF-8"?>
<xml>
<Collection>
<AddedType>
<Type>
<Name>BBBBBBB</Name>
<Status>On</Status>
<Version>2</Version>
<Iteration>3</Iteration>
</Type>
<Type>
<Name>AAAAAAA</Name>
<Status>Off</Status>
<Version>3</Version>
<Iteration>0</Iteration>
</Type>
<Type>
<Name>CCCCCCC</Name>
<Status>On</Status>
<Version>0</Version>
<Iteration>1</Iteration>
</Type>
<Type>
<Name>BBBBBBB</Name>
<Status>Off</Status>
<Version>4</Version>
<Iteration>0</Iteration>
</Type>
</AddedType>
<ChangedType>
<Type>
<Name>BBBBBBB</Name>
<Status>On</Status>
<Version>7</Version>
<Iteration>2</Iteration>
</Type>
</ChangedType>
<UnchangedType>
<Type>
<Name>AAAAAAA</Name>
<Status>On</Status>
<Version>2</Version>
<Iteration>0</Iteration>
</Type>
</UnChangedType>
<DeletedType>
<Type>
<Name>XXXXXX</Name>
<Status>On</Status>
<Version>5</Version>
<Iteration>1</Iteration>
</Type>
</DeletedType>
</Collection>
</xml>
所需的输出
<?xml version="1.0" encoding="UTF-8"?>
<xml>
<Collection>
<AddedType>
<Type>
<Name>CCCCCCC</Name>
<Status>On</Status>
<Version>0</Version>
<Iteration>1</Iteration>
</Type>
</AddedType>
<ChangedType>
<Type>
<Name>BBBBBBB</Name>
<Status>On</Status>
<Version>7</Version>
<Iteration>2</Iteration>
</Type>
</ChangedType>
<UnchangedType>
<Type>
<Name>AAAAAAA</Name>
<Status>On</Status>
<Version>2</Version>
<Iteration>0</Iteration>
</Type>
</UnChangedType>
<DeletedType>
<Type>
<Name>XXXXXX</Name>
<Status>On</Status>
<Version>5</Version>
<Iteration>1</Iteration>
</Type>
</DeletedType>
</Collection>
</xml>
Type节点可以在AddedType ChangedType UnChangedType DeletedType
Status只能是On或Off与On > Off
版本是数字、整数
迭代是数字,整数
正如您在上面的示例中看到的,我需要在 OUTPUT 中只出现 1 个具有相同 Name 值的每个 Type 节点,它应该是根据以下规则具有更高优先级:
选择保留哪一个的完整键是(状态).(版本).(迭代)示例:Off.5.1
任何帮助将不胜感激
【问题讨论】:
-
您是否仅限于使用 xslt 或者您可以使用任何 oop 语言?
-
不幸的是,我仅限于使用 XLST,否则我已经使用 xmltables 完成了此操作并稍后重建了 xml
-
您是否使用 .net 框架的 XSLTCompiledTransform 来执行 xslt?
-
我目前正在从命令行调用 Saxon
-
您可以使用 saxon 框架添加扩展对象。然后您可以在 .net 代码中生成节点结构
标签: xslt