XSLT删除重复的节点和属性

时间:2014-07-01 16:05:34

标签: xml xpath xslt-1.0

需要使用XSLT1.0删除xml中的重复条目,如何实现?

 Example : For below input xml , i need only unique image element

    <image source="marginal_links_orange.png"/>
     <image source="marginal_programme_home.png"/>
     <image source="marginal_programme_guide.png"/>
     <image source="marginal_links_orange.png"/>
     <image source="marginal_programme_home.png"/>

   Expected Output :

    <image source="marginal_links_orange.png"/>
    <image source="marginal_programme_home.png"/>
    <image source="marginal_programme_guide.png"/>

1 个答案:

答案 0 :(得分:0)

我认为这将解决您的问题

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"   xmlns:fo="http://www.w3.org/1999/XSL/Format">
<xsl:output method="html" indent="yes"/>
    <xsl:template match="/">
        <xsl:apply-templates select="//image[@source]"/>        
    </xsl:template>
    <xsl:template match="image[@source]">           
        <xsl:if test="not(preceding-sibling::image[@source = current()/@source])">
            <xsl:copy-of select="."/>
            <xsl:text>&#13;&#xa;</xsl:text>
        </xsl:if>
    </xsl:template>
</xsl:stylesheet>
相关问题