You can use the xsl: select statement, something like switching in common programming languages:
Example:
<xsl:variable name="variable_name">
<xsl:for-each select="product/attributes">
<xsl:choose>
<xsl:when test="@attributename='A'">
1
</xsl:when>
<xsl:when test=" @attributename='B'">
1
</xsl:when>
<xsl:otherwise>1</xsl:otherwise>
</xsl:choose>
</xsl:for-each>
</xsl:variable>
variable_name product/attributes.
... http://www.w3schools.comwww.w3schools.com/xsl/el_choose.asp
EDIT: ( ) OP:
<xsl:variable name="variable_name">
<xsl:for-each select="product/attributes">
<xsl:if test="contains(text(), 'A') or contains(text(), 'B')">
1
</xsl:if>
</xsl:for-each>
</xsl:variable>
, xml, xslt.