Q:

How do I extract a particular value in a comma delimited list in XLST and compare the value to another?

I am new to XSLT and have a similar requirement to Line Break in XSLT for a comma separated value however I need to do the following

Check if the value is a single string e.g. Apples or whethe it is a comma delimited list e.g. Apples, Pears, etc
If it is a comma delimited list then check if the list has a particular value or values
If the value exists then do something 
If it is a single string e.g. Apple then do something

How can I achieve this is XSLT 2.0?

A:

You can tokenize the list. A function like this might do the job (embedded in a working XSLT for demonstration purposes):
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:my="NS:MY">
  <xsl:function name="my:test">
    <xsl:param name="string"/>
    <xsl:variable name="tokens" select="tokenize(normalize-space($string),'\s*,\s*')"/>
    <xsl:choose>
      <xsl:when test="normalize-space($string)='Apples'">
        Do something where we have a single "Apples" 
      </xsl:when>
      <xsl:when test="normalize-space($string)='Pears'"> 
        Do something where we have a single "Pears" 
      </xsl:when>
      <xsl:when test="$tokens='Apples' and $tokens='Pears'"> 
        There are Apples and Pears 
      </xsl:when>
      <xsl:when test="$tokens='Apples'"> 
        There are Apples in the list 
      </xsl:when>
      <xsl:when test="$tokens='Pears'"> 
        There are Pears in the list 
      </xsl:when>
      <xsl:otherwise> 
        Didn't find what we're looking for 
      </xsl:otherwise>
    </xsl:choose>
  </xsl:function>

  <xsl:template match="/">
    <out>
      <xsl:value-of select="my:test('Apples')"/>
      <xsl:value-of select="my:test('Pears,Oranges')"/>
      <xsl:value-of select="my:test(' Apples ,Pears,Oranges')"/>
      <xsl:value-of select="my:test('Oranges , Bananas, Strawberries')"/>
    </out>
  </xsl:template>
</xsl:stylesheet>

You could also use regular expressions.
See the XPath documentation for what normalize-space() and tokenize() do. You might want to replace the bogus namespace "NS:MY" with something sensible.

