这是我的XML代码:
<SECTOR_LIST>
<LIGHT_SECTOR>
<SECTOR1>22</SECTOR1>
<SECTOR2>92</SECTOR2>
</LIGHT_SECTOR>
<LIGHT_SECTOR>
<SECTOR1>22</SECTOR1>
<SECTOR2>92</SECTOR2>
</LIGHT_SECTOR>
<LIGHT_SECTOR>
<SECTOR1>92</SECTOR1>
<SECTOR2>137</SECTOR2>
</LIGHT_SECTOR>
<LIGHT_SECTOR>
<SECTOR1>92</SECTOR1>
<SECTOR2>137</SECTOR2>
</LIGHT_SECTOR>
</SECTOR_LIST>
我创建了这个XSLT 1.0:
<xsl:for-each select="SECTOR_LIST">
<xsl:for-each select="LIGHT_SECTOR">
<xsl:text>VIS </xsl:text>
<xsl:value-of select="SECTOR1"/>
<xsl:text>-</xsl:text>
<xsl:value-of select="SECTOR2"/>
<br/>
</xsl:for-each>
</xsl:for-each>
在输出中我有这个: VIS 22-92 VIS 22-92 VIS 92-137 VIS 92-137
我只会: VIS 22-92 VIS 92-137
答案 0 :(得分:1)
请尝试以下代码:
<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:key name="sector" match="//LIGHT_SECTOR" use="."/>
<xsl:variable name="Sectors" select="//LIGHT_SECTOR"/>
<xsl:template match="SECTOR_LIST">
<xsl:for-each select="$Sectors[count(. | key('sector', .)[1]) = 1]">
<xsl:text>VIS </xsl:text>
<xsl:value-of select="SECTOR1"/>
<xsl:text>-</xsl:text>
<xsl:value-of select="SECTOR2"/>
<br/>
</xsl:for-each>
</xsl:template>
</xsl:stylesheet>