2014-07-01 196 views
0

需要使用XSLT1.0删除xml中的重复条目,这怎么实现?XSLT删除重复节点和属性

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

http://www.jenitennison.com/xslt/grouping/muenchian.html –

回答

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>