How to compare the XML element with the XSL variable

advertisements

I am using xslt to transform an xml document to html for use in an email. I need to compare xml elements with another xml element value so that I know what format to give the value. Basically I have an xml structure as such:

<main>
    <comparer>1</comparer>
    <items>
        <item>
            <name>blarg</name>
            <values>
                <value>1</value>
                <value>2</value>
            </values>
    </items>
</main>

The item information is being used to build a table:

<table>
    <tr>
        <td>blarg</td>
        <td>1</td>
        <td>2</td>
    </tr>
</table>

What I need to be able to do is use xsl to compare the item values with the 'comparer' node value and if they are equal then bold the cell in the table otherwise the cell value i snot bolded. I need to accomplish this without the use of javascript so it has to be done in xsl. Right now, I am looking at using a xsl:variable then attempting to use the xsl:when to do the compare. Unfortunately, I am having little luck. This is what I have just started playing with for each row in the table:

<xsl:variable name="compare" select="//main/comparer" />

...    

<xsl:for-each select="value">
    <td>
        <xsl:choose>
            <xsl:when test=". = $compare">
                <b>
                    <xsl:value-of select="."/>
                </b>
            </xsl:when>
            <xsl:otherwise>
                <xsl:value-of select="."/>.
            </xsl:otherwise>
        </xsl:choose>
    </td>
</xsl:for-each>

*Note: I left out most of the xsl for brevity. I'm just trying to focus on my issue.


I figured it out after some trial and error. Alejandro's answer appears that it would work, but I do not have the luxury of restructuring the xsl to make use of templating. Here is what I used to solve my issue:

<xsl:variable name="compare" select="//main/comparer" />

...    

<xsl:for-each select="value">
    <td>
        <xsl:choose>
            <xsl:when test="contains(., $expireDate)">
                <b>
                    <xsl:value-of select="."/>
                </b>
            </xsl:when>
            <xsl:otherwise>
                <xsl:value-of select="."/>.
            </xsl:otherwise>
        </xsl:choose>
    </td>
</xsl:for-each>