xslt 1.0 - 通过多个条件查找唯一值 [英] xslt 1.0 - find unique values by several criteria
本文介绍了xslt 1.0 - 通过多个条件查找唯一值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有以下 XML:
<library>
<elements>
<element name="books">
<property name="author">A</property>
<property name="select">true</property>
</element>
<element name="books">
<property name="author">B</property>
<property name="select">false</property>
</element>
<element name="books">
<property name="author">C</property>
<property name="select">true</property>
</element>
<element name="books">
<property name="author">A</property>
<property name="select">true</property>
</element>
</elements>
</library>
我需要获取所有 name="books" 元素的输出,这些元素被选中 (selected = true) 并且按作者姓名是唯一的.必须使用 xslt 1.0.
I need to get output of all elements with name="books", which are selected (selected = true) and unique by author name. Must use xslt 1.0.
预期结果:作者:A作者:C
Expected result: author: A author: C
必须只输出作者 A 和 C 的数据.
Must output data only for authors A and C.
提前致谢!
推荐答案
not(.=preceding::*)
在for循环中检索给定xpath的唯一值
to retrieve the unique values of the given xpath in for loop
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:output method="text"/>
<xsl:template match="/">
<ul>
<xsl:for-each select="//elements/element[@name = 'books' and property[@name = 'select' and .='true'] ]/property[@name = 'author' and not(.=preceding::*)]">
<li>
<xsl:value-of select="concat('author :',.)"/>
</li>
</xsl:for-each>
</ul>
</xsl:template>
</xsl:stylesheet>
输出 XML :
作者:作者:C
这篇关于xslt 1.0 - 通过多个条件查找唯一值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文