【问题标题】:XSLT to remove duplicate node and attributeXSLT 删除重复的节点和属性
【发布时间】:2014-07-01 16:05:33
【问题描述】:

需要使用 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"/>

【问题讨论】:

标签: xml xpath xslt-1.0


【解决方案1】:

我想这会解决你的问题

<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>

【讨论】:

    猜你喜欢
    • 2011-10-07
    • 1970-01-01
    • 1970-01-01
    • 2016-10-11
    • 2017-07-11
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多