我需要删除以下xml中的重复项:
<ListOfRowIDWithListOfBooks xmlns:bpws="http://schemas.xmlsoap.org/ws/2003/03/business-process/">
<RowIDWithListOfBooks>
<Row_ID>ADOA-XssK</Row_ID>
<ListOfBookInfo>
<book>
<BookType>Brand</BookType>
<BookName>jon</BookName>
</book>
<book>
<BookType>Brand</BookType>
<BookName>jon</BookName>
</book>
</ListOfBookInfo>
</RowIDWithListOfBooks>
</ListOfRowIDWithListOfBooks>有人能帮上忙吗?
发布于 2011-07-22 05:40:53
使用标准分组解决方案可以轻松完成此任务。不要使用单个select语句来执行众所周知的会导致性能问题的操作。
注意,对identity.xsl的引用只是将众所周知的identity transformation模板包含到样式表中。
XSLT 1.0
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:key name="k-books" match="book" use="concat(BookType,'|',BookName)"/>
<xsl:include href="identity.xsl"/>
<xsl:template match="ListOfBookInfo">
<ListOfBookInfo>
<xsl:copy>
<xsl:apply-templates select="book
[generate-id()
=generate-id(key('k-books',concat(BookType,'|',BookName))[1])]"/>
</xsl:copy>
</ListOfBookInfo>
</xsl:template>
</xsl:stylesheet>XSLT 2.0
<xsl:stylesheet version="2.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:include href="identity.xsl"/>
<xsl:template match="ListOfBookInfo">
<ListOfBookInfo>
<xsl:for-each-group select="book"
group-by="concat(BookType,'|',BookName)">
<xsl:apply-templates select="."/>
</xsl:for-each-group>
</ListOfBookInfo>
</xsl:template>
</xsl:stylesheet>发布于 2011-07-21 13:09:18
试试这个XSLT:
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" indent="yes"/>
<xsl:template match="/">
<xsl:apply-templates select="//ListOfBookInfo/book[not(BookType = preceding-sibling::book/BookType
and BookName = preceding-sibling::book/BookName)]"/>
</xsl:template>
<xsl:template match="book">
<xsl:copy-of select="."/>
</xsl:template>
</xsl:stylesheet>它将选择具有唯一BookType和BookName的book%s。在你的样本结果中应该是:
<book xmlns:bpws="http://schemas.xmlsoap.org/ws/2003/03/business-process/">
<BookType>Brand</BookType>
<BookName>jon</BookName>
</book>发布于 2011-07-21 04:59:31
您需要使用Muenchian分组方法将它们分组在一起。或者XSLT2.0中更具体的分组函数。下面是两个相关的堆栈溢出问题:
https://stackoverflow.com/questions/6768387
复制相似问题