我有一个程序从exslt中的函数接收节点集。它包含重复的节点( contains出现了两次):
<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)"/>行中的一些东西,但不知怎么我找不到这样做的方法。任何帮助都将不胜感激。
发布于 2015-06-25 14:31:24
您的代码应该在http://xsltransform.net/gWmuiJX中使用Saxon6.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>。
https://stackoverflow.com/questions/31052923
复制相似问题