Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

XSLT - Adding a class to something with a class?

Tags:

xslt

When using XSLT how do I apply a class to an element which already has a class? The way I'm doing it it replaces the class that is already present? How would I add the class in addition to the existing class? My code is as follows:

<xsl:if test="data[@alias = 'off'] = 1">
    <xsl:attribute name="class">off</xsl:attribute>
</xsl:if>
<xsl:if test="$currentPage/ancestor-or-self::node/@id = current()/@id">
    <xsl:attribute name="class">active</xsl:attribute>
</xsl:if>

Thanks.

like image 933
Probocop Avatar asked May 26 '10 09:05

Probocop


1 Answers

The other way around:

<xsl:attribute name="class">
  <xsl:if test="data[@alias = 'off'] = 1">off </xsl:if>
  <xsl:if test="$currentPage/ancestor-or-self::node/@id = current()/@id">active </xsl:if>
</xsl:attribute>

Note the extra space I put after every attribute value. The XSLT processor will trim the trailing space from the attribute value on its own, so no need to do complicated space handling.

like image 180
Tomalak Avatar answered Oct 27 '22 01:10

Tomalak