0
votes

This is my 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>

This is my 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>

In output I had: IRA IRA IRA IRA
I would : IRA ( if exist a light category = 17 write only one time IRA without Repetition)

2
This is almost the same as your previous question (stackoverflow.com/questions/21180816/…). Try to read about XSL Keys.Joel M. Lamsen

2 Answers

1
votes

Anyway, please try the code below:

<?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>

You must use keys and eliminate duplicates before testing the node content.

0
votes
<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>

In output this give:

IRA IRA