I am having a terrible time with XSL synax. I can't seem to figure out how to set a global variable before you enter the loop and then run the loop and then test the variable.

For example, I am trying to have the name of the a certain element displayed once in loop. I wrote some psuedo-code in there to help with the logic-



Code:
    <!-- set variable here -->
    
    <xsl:template match="PLAY"> 
        <xsl:variable name="unique-list" />
        <xsl:for-each select="ACT/SCENE/SPEECH">
                <xsl:if test="contains(SPEAKER,'KING HENRY V')">
                    
                    <xsl:variable name="check-list"/>
                    <xsl:value-of select="../../TITLE" />
                    <xsl:if test="if ($unique-list != $check-list)>
                        <h3><xsl:value-of select="../../TITLE" /></h3>
                       <xsl: $check-list = value-of select="../../TITLE"/>
                    </xsl:if>

                </xsl:if>
            </xsl:for-each>
    </xsl:template>