2014-07-01 190 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>