Assign CSS class to element in an XSL

xslt

My XML file is as follows:

<worksheet>
<row>
<rowTitle>RT1</rowTitle>
<rowType>yesorno</rowType>
<subLine>subLine1Content</subLine>
<subLine>subLine2Content</subLine>
</row>
<row>
<rowTitle>RT2</rowTitle>
<rowType>operation</rowType>
<subLine>subLine1Content</subLine>
<subLine>subLine2Content</subLine>
<subLine>subLine3Content</subLine>
</row>
.
.
</worksheet>

in my xsl, while displaying contents of a particular row, i'd like to add a class to the html element that'll specify the type of the row it is. I tried using xsl:choose and assigning value to a xsl:variable, but that doesn't work.
I'm trying to display the row as

<ol>
<li class="rowTypeBoolean">
RT1
<ul><li>subLineContent1</li>
<li>subLineContent2</li></ul>
</li>
<li class="rowTypeOptions">
RT2
<ul><li>subLineContent1</li>
<li>subLineContent2</li>
<li>subLineContent3</li></ul>
</li>
.    
.
</ol>

XSL file snippet

<xsl:template match="row">
        <li class="rowClass ${className}">
            <xsl:choose>
                <xsl:when test="type = 'YESORNO'">
                    <xsl:variable name="className" select="rowTypeBoolean"/>
                </xsl:when>
                <xsl:when test="type = 'OPTIONS'">
                    <xsl:variable name="className" select="rowTypeOptions"/>
                </xsl:when>
                <xsl:when test="type = 'OPERATION'">
                     <xsl:variable name="className" select="rowTypeOperation"/>
                </xsl:when>
                <xsl:otherwise>
                    <xsl:variable name="className" select="rowTypeOther"/>
                </xsl:otherwise>
            </xsl:choose>
            <span class="rowTitleClass">
                <xsl:value-of select="rowtitle"/>
            </span>
            <br/>
            <ul class="subLineListClass">
                <xsl:apply-templates select="subLine"/>
            </ul>
        </li>
</xsl:template>

Best Answer

You need to add it as an attribute to the element:

    <li>
        <xsl:choose>
            <xsl:when test="type = 'YESORNO'">
                <xsl:attribute name="className">rowTypeBoolean</xsl:attribute>
            </xsl:when>
            <xsl:when test="type = 'OPTIONS'">
                <xsl:attribute name="className">rowTypeOptions</xsl:attribute>
            </xsl:when>
            <xsl:when test="type = 'OPERATION'">
                <xsl:attribute name="className">rowTypeOperation"</xsl:attribute>
            </xsl:when>
            <xsl:otherwise>
                <xsl:attribute name="className">rowTypeOther"</xsl:attribute>
            </xsl:otherwise>
        </xsl:choose>
    </li>
Related Topic