这是我的XML:
<LIGHT_DESCRIPTION_LIST>
<LIGHT_DESCRIPTION>
<LIGHT_CHARACTERISTICS>Fl</LIGHT_CHARACTERISTICS>
<LIGHT_CATEGORY>17</LIGHT_CATEGORY>
</LIGHT_DESCRIPTION>
<LIGHT_DESCRIPTION>
<LIGHT_CHARACTERISTICS>Fl</LIGHT_CHARACTERISTICS>
<LIGHT_CATEGORY>UNKNOWN</LIGHT_CATEGORY>
</LIGHT_DESCRIPTION>
<LIGHT_DESCRIPTION>
<LIGHT_CHARACTERISTICS>Fl</LIGHT_CHARACTERISTICS>
<LIGHT_CATEGORY>UNKNOWN</LIGHT_CATEGORY>
</LIGHT_DESCRIPTION>
<LIGHT_DESCRIPTION>
<LIGHT_CHARACTERISTICS>Fl</LIGHT_CHARACTERISTICS>
<LIGHT_CATEGORY>17</LIGHT_CATEGORY>
</LIGHT_DESCRIPTION>
<LIGHT_DESCRIPTION>
<LIGHT_CHARACTERISTICS>Fl</LIGHT_CHARACTERISTICS>
<LIGHT_CATEGORY>UNKNOWN</LIGHT_CATEGORY>
</LIGHT_DESCRIPTION>
<LIGHT_DESCRIPTION>
<LIGHT_CHARACTERISTICS>Fl</LIGHT_CHARACTERISTICS>
<LIGHT_CATEGORY>17</LIGHT_CATEGORY>
</LIGHT_DESCRIPTION>
<LIGHT_DESCRIPTION>
<LIGHT_CHARACTERISTICS>Fl</LIGHT_CHARACTERISTICS>
<LIGHT_CATEGORY>17</LIGHT_CATEGORY>
</LIGHT_DESCRIPTION>
</LIGHT_DESCRIPTION_LIST>
这是我的XSLT:
<xsl:for-each select="LIGHT_DESCRIPTION_LIST">
<xsl:for-each select="LIGHT_DESCRIPTION">
<xsl:if test="LIGHT_CATEGORY = '17'">
<xsl:text>IRA</xsl:text>
</xsl:if>
</xsl:for-each>
</xsl:for-each>
在输出中我有:
IRA IRA IRA IRA
我会:IRA(如果存在轻型类别= 17只写一次IRA而没有重复)
答案 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="LD" match="LIGHT_DESCRIPTION" use="."/>
<xsl:variable name="Light_Desc" select="//LIGHT_DESCRIPTION"/>
<xsl:template match="LIGHT_DESCRIPTION_LIST">
<xsl:for-each select="$Light_Desc[count(. | key('LD', .)[1]) = 1]">
<xsl:if test="LIGHT_CATEGORY = '17'">
<br/>
<span style="font-family:Univers Condensed; font-size:9pt; ">
<xsl:text>IRA</xsl:text>
</span>
</xsl:if>
</xsl:for-each>
</xsl:template>
</xsl:stylesheet>
在测试节点内容之前,您必须使用密钥并消除重复项。
答案 1 :(得分:0)
<xsl:key name="LD" match="//LIGHT_DESCRIPTION" use="."/>
<xsl:for-each select="LIGHT_DESCRIPTION_LIST">
<xsl:for-each select="LIGHT_DESCRIPTION">
<xsl:variable name="Light_Desc" select="."/>
<xsl:for-each select="$Light_Desc[count(. | key('LD', .)[1]) = 1]">
<xsl:if test="LIGHT_CATEGORY = '17'">
<xsl:text>IRA</xsl:text>
</xsl:if>
</xsl:for-each>
</xsl:for-each>
</xsl:for-each>
在输出中,这给出了:
IRA IRA