0

我有一个程序从 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)"/>可能是这样的,但不知何故我找不到这样做的方法。任何帮助,将不胜感激。

4

1 回答 1

1

您的代码应该在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>

于 2015-06-25T14:31:24.977 回答