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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With