我需要有关XSL的帮助,请在下面找到我的xml
<TEST xmlns:xsi="http://www.w3.org/2001/XMLSchemainstance" xmlns:i="http://www.w3.org/2001/XMLSchemainstance">
<TEST>
<TEST1>
<TEST2>
<A>
<Rule>e1fa7f63820a406bb97f1c1b11af8d09</Rule>
<MountPoint>0</MountPoint>
</A>
<A>
<Rule>917271928cea4a75bdfa903b49ed23e5</Rule>
<MountPoint>0</MountPoint>
</A>
<A>
<Rule>6b6336722d574e8285b73192ea057b45</Rule>
<MountPoint>0</MountPoint>
</A>
</TEST2>
</TEST1>
<CHECK>
<CHECK1>
<Rule>
<Name>test1</Name>
<ID>6b6336722d574e8285b73192ea057b45</ID>
<Type>DicomHeaderAttribute</Type>
<Category>SeriesDate</Category>
<Operator>Equals</Operator>
<Value>as</Value>
</Rule>
<Rule>
<Name>sdsd</Name>
<ID>e1fa7f63820a406bb97f1c1b11af8d09</ID>
<Type>DicomHeaderAttribute</Type>
<Category>SeriesInformation</Category>
<Operator>Equals</Operator>
<Value>sdsdsd</Value>
</Rule>
<Rule>
<Name>fdfdf</Name>
<ID>917271928cea4a75bdfa903b49ed23e5</ID>
<Type>DicomHeaderAttribute</Type>
<Category>ReferringPhysician</Category>
<Operator>Equals</Operator>
<Value>assd</Value>
</Rule>
</CHECK1>
</CHECK>
</TEST>
</TEST>
在上面的xml中,我需要删除与类别值'SeriesInformation'
匹配的规则,以及与'SeriesInformation'
规则的ID匹配的相应的"A"节点
预期的XML:
<TEST xmlns:xsi="http://www.w3.org/2001/XMLSchemainstance" xmlns:i="http://www.w3.org/2001/XMLSchemainstance">
<TEST>
<TEST1>
<TEST2>
<A>
<Rule>917271928cea4a75bdfa903b49ed23e5</Rule>
<MountPoint>0</MountPoint>
</A>
<A>
<Rule>6b6336722d574e8285b73192ea057b45</Rule>
<MountPoint>0</MountPoint>
</A>
</TEST2>
</TEST1>
<CHECK>
<CHECK1>
<Rule>
<Name>test1</Name>
<ID>6b6336722d574e8285b73192ea057b45</ID>
<Type>DicomHeaderAttribute</Type>
<Category>SeriesDate</Category>
<Operator>Equals</Operator>
<Value>as</Value>
</Rule>
<Rule>
<Name>fdfdf</Name>
<ID>917271928cea4a75bdfa903b49ed23e5</ID>
<Type>DicomHeaderAttribute</Type>
<Category>ReferringPhysician</Category>
<Operator>Equals</Operator>
<Value>assd</Value>
</Rule>
</CHECK1>
</CHECK>
</TEST>
</TEST>
请在XSL方面提供帮助。
嗨,这是xsl-iam使用
<?xml version="1.0"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:output method="xml" indent="yes"/>
<xsl:strip-space elements="*"/>
<xsl:template match="node()|@*">
<xsl:copy>
<xsl:apply-templates select="node()|@*"/>
</xsl:copy>
</xsl:template>
<xsl:template match="Rule[Category = 'SeriesInformation']">
</xsl:template>
</xsl:stylesheet>
之后我无法转发,我可以删除与类别匹配的规则作为序列信息,但之后如何删除依赖ID的A节点无法执行
要删除A
元素,您可以定义一个键来通过ID
查找Rule
元素
<xsl:key name="rule" match="Rule[ID]" use="ID" />
然后,忽略A
元素的模板匹配如下:
<xsl:template match="A[key('rule', Rule)/Category='SeriesInformation']" />
试试这个XSLT:
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:output method="xml" indent="yes" />
<xsl:key name="rule" match="Rule[ID]" use="ID" />
<xsl:template match="Rule[Category='SeriesInformation']" />
<xsl:template match="A[key('rule', Rule)/Category='SeriesInformation']" />
<xsl:template match="@*|node()">
<xsl:copy>
<xsl:apply-templates select="@*|node()"/>
</xsl:copy>
</xsl:template>
</xsl:stylesheet>