exslt 节点集中的不同值

Distinct values in a exslt nodeset

我有一个程序可以从 exslt 中的函数接收节点集。它包含重复节点(Tom Waits 出现两次):

<xsl:template name="giveMeHeroes">
    <person>
        <lastName>Waits</lastName>
        <firstName>Tom</firstName>
    </person>
    <person>
        <lastName>Everett</lastName>
        <firstName>Mark</firstName>
    </person>
    <person>
        <lastName>Hickey</lastName>
        <firstName>Rich</firstName>
    </person>
    <person>
        <lastName>Waits</lastName>
        <firstName>Tom</firstName>
    </person>
</xsl:template>

<xsl:template match="/">

    <xsl:variable name="someHeroes">
        <xsl:call-template name="giveMeHeroes"></xsl:call-template>
    </xsl:variable>


    <xsl:apply-templates select="ext:node-set($someHeroes)/person"/>

</xsl:template>


<xsl:template match="person">
    <xsl:value-of select="concat('Long live',firstName,' ',lastName,'!!!')"/>
    <br/>
</xsl:template>

此示例产生(在浏览器中解析):

Long live Tom Waits!!!
Long live Mark Everett!!!
Long live Rich Hickey!!!
Long live Tom Waits!!! 

我知道我应该能够使用 set:distinct(nodeset) 过滤结果,也许是 <xsl:apply-templates select="set:distinct(ext:node-set($someHeroes)/person)"/> 的内容,但不知何故我找不到这样做的方法。任何帮助将不胜感激。

你的代码应该适用于 http://xsltransform.net/gWmuiJX 中的 Saxon 6.5.5,并且适用于我

<?xml version="1.0" encoding="UTF-8" ?>
<xsl:transform xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0"
  xmlns:exsl="http://exslt.org/common"
  xmlns:set="http://exslt.org/sets"
  exclude-result-prefixes="exsl set">

    <xsl:output method="html" doctype-public="XSLT-compat" omit-xml-declaration="yes" encoding="UTF-8" indent="yes" />

<xsl:template name="giveMeHeroes">
    <person>
        <lastName>Waits</lastName>
        <firstName>Tom</firstName>
    </person>
    <person>
        <lastName>Everett</lastName>
        <firstName>Mark</firstName>
    </person>
    <person>
        <lastName>Hickey</lastName>
        <firstName>Rich</firstName>
    </person>
    <person>
        <lastName>Waits</lastName>
        <firstName>Tom</firstName>
    </person>
</xsl:template>

<xsl:template match="/">

    <xsl:variable name="someHeroes">
        <xsl:call-template name="giveMeHeroes"></xsl:call-template>
    </xsl:variable>


    <xsl:apply-templates select="set:distinct(exsl:node-set($someHeroes)/person)"/>

</xsl:template>


<xsl:template match="person">
    <xsl:value-of select="concat('Long live',firstName,' ',lastName,'!!!')"/>
    <br/>
</xsl:template>
</xsl:transform>

并输出 Long liveTom Waits!!!<br>Long liveMark Everett!!!<br>Long liveRich Hickey!!!<br>.