【发布时间】:2017-05-16 07:18:37
【问题描述】:
我有一个关于根据子节点删除父节点的问题。
XML 文件具有以下结构:
<PlmXmlData xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:plm="http://www.plmxml.org/Schemas/PLMXMLSchema" xmlns:fn="http://www.w3.org/2005/xpath-functions" xmlns:an="">
<ItemList>
<Item>
<ID>1</ID>
<Group>Group1</Group>
<Projekt>Projekt1</Projekt>
<DatasetList>
<Dataset>
<Name>Name1</Name>
<Type>TXT</Type>
<Template>None</Template>
<RelativeFilePath>FilePath1</RelativeFilePath>
<PropertyList>
<Property>
<Title>item_name</Title>
<Value>ITEM_Name</Value>
</Property>
<Property>
<Title>item_name</Title>
<Value>ITEM_Name</Value>
</Property>
</PropertyList>
</Dataset>
<Dataset>
<Name>Name1</Name>
<Type>PDF</Type>
<Template>Template1</Template>
<RelativeFilePath>FilePath1/Name1.pdf</RelativeFilePath>
<PropertyList>
<Property>
<Title>item_name</Title>
<Value>CAR1</Value>
</Property>
<Property>
<Title>item_name</Title>
<Value>CAR1</Value>
</Property>
<Property>
<Title>item_name2</Title>
<Value>CAR2</Value>
</Property>
<Property>
<Title>item_name2</Title>
<Value>CAR2</Value>
</Property>
</PropertyList>
</Dataset>
</DatasetList>
</Item>
</ItemList>
</PlmXmlData>
如您所见,此示例 TXT 和 PDF 中有不同的 <Type> 节点。
在这个节点中有节点<Property> 和子节点<Title> 和<Value>。
对于每个<Type> 中的每个重复条目,我想删除整个<Property> 节点及其子节点<Title> 和<Value>。
想要的输出应该是这样的:
<PlmXmlData xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:plm="http://www.plmxml.org/Schemas/PLMXMLSchema" xmlns:fn="http://www.w3.org/2005/xpath-functions" xmlns:an="">
<ItemList>
<Item>
<ID>1</ID>
<Group>Group1</Group>
<Projekt>Projekt1</Projekt>
<DatasetList>
<Dataset>
<Name>Name1</Name>
<Type>TXT</Type>
<Template>None</Template>
<RelativeFilePath>FilePath1</RelativeFilePath>
<PropertyList>
<Property>
<Title>item_name</Title>
<Value>ITEM_Name</Value>
</Property>
</PropertyList>
</Dataset>
<Dataset>
<Name>Name1</Name>
<Type>PDF</Type>
<Template>Template1</Template>
<RelativeFilePath>FilePath1/Name1.pdf</RelativeFilePath>
<PropertyList>
<Property>
<Title>item_name</Title>
<Value>CAR1</Value>
</Property>
<Property>
<Title>item_name2</Title>
<Value>CAR2</Value>
</Property>
</PropertyList>
</Dataset>
</DatasetList>
</Item>
</ItemList>
我已经搜索了论坛,但找不到合适的解决方案。提前感谢您的帮助!
【问题讨论】:
-
请选择 XSLT 1.0 或 XSLT 2.0 - 不能同时选择。要删除重复项,请搜索 grouping - 这可能是这里最常被问到的 XSLT 问题。
标签: xml xslt xslt-1.0 xslt-2.0