2013-10-15 127 views
1

我一直在研究如何删除重复的节点,但不知道如何继续。按节点组或删除节点用xslt重复?

我有这样的初步名单

<?xml version="1.0" encoding="utf-8"?> 
<SEC count="7"> 
    <value>outy</value> 
    <name>object</name> 
    <Row> 
<client>0000000530708</client> 
     <date>20100401</date> 
    </Row> 
    <Row> 
     <client>0000000530708</client> 
     <date>20100401</date> 
    </Row> 
    <Row> 
     <client>0000000999999</client> 
     <date>20100401</date> 
    </Row> 
    <Row> 
     <client>0000000999999</client> 
     <date>20100401</date> 
    </Row> 
    <Row> 
     <client>0000000999999</client> 
     <date>20100401</date> 
    </Row> 
</SEC> 

,我希望得到这个

<?xml version="1.0" encoding="utf-8"?> 
<SEC count="7"> 
    <value>outy</value> 
    <name>object</name> 
    <Row> 
     <client>0000000530708</client> 
     <date>20100401</date> 
    </Row> 
    <Row> 
     <client>0000000999999</client> 
     <date>20100401</date> 
    </Row> 
</SEC> 

我该怎么办呢? 有人可以帮我吗?我使用XSL 1.0。

谢谢。

回答

3

您可以对此使用Muenchian方法的变体。与身份模板开始复制一切作为,就是除非有更具体的模板覆盖:

<xsl:template match="@*|node()"> 
    <xsl:copy><xsl:apply-templates select="@*|node()"/></xsl:copy> 
</xsl:template> 

定义关键赋予的独特条件:

<xsl:key name="uniqueRow" match="Row" use="concat(client, '|', date)"/> 

和一个多模板添加到忽略任何那就是不是第一个用那个特定的键值:

<xsl:template match="Row[generate-id() != 
    generate-id(key('uniqueRow', concat(client, '|', date))[1])]"/>