Ste*_*eph 5 xml xslt xpath distinct
我需要删除以下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>
Run Code Online (Sandbox Code Playgroud)
有人可以帮忙吗?
使用标准分组解决方案可以轻松实现此任务.不要使用单个select语句来执行众所周知会导致性能问题的语句.
注意引用identity.xsl只是在样式表中包含众所周知的身份转换模板.
[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>
Run Code Online (Sandbox Code Playgroud)
[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>
Run Code Online (Sandbox Code Playgroud)
您需要使用 Muenchian 分组方法将它们分组在一起。或者 xslt 2.0 中更具体的分组函数。这是两个相关的堆栈溢出问题: