リストをトークン化できます。次のような関数が機能する可能性があります (デモンストレーション目的で動作中の XSLT に埋め込まれています)。
<?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>
正規表現を使用することもできます。
normalize-space()
whatとdoについては、XPath のドキュメントを参照してtokenize()
ください。偽の名前空間「NS:MY」を適切なものに置き換えたいと思うかもしれません。