When I need to compare some XML text element against several strings, I could compare it with each of the strings but I prefer to use the contains() function.
For example, there are 3 lists of possible qualifiers for LIN-02/04/06/…/30:
- SKU: CB, SK, IN, BP, OT, IT
- Vendor Part Number: VI, VN, VP, VC, VA, MN, MG
- UPC: UP, UA, UI, UK
And XML like this:
<LIN>
<LIN01>000010</LIN01>
<LIN02>VN</LIN02>
<LIN03>ABC-123456</LIN03>
<LIN04>OT</LIN04>
<LIN05>998877</LIN05>
</LIN>
If I used the “direct” way to find item’s SKU number, I would have to create something like this:
<xsl:choose>
<xsl:when test="(LIN02 = 'CB' or LIN02 = 'SK' or LIN02 = 'IN' or LIN02 = 'BP' or LIN02 = 'OT' or LIN02 = 'IT')">
<xsl:value-of select="LIN03" />
</xsl:when>
<xsl:when test="(LIN04 = 'CB' or LIN04 = 'SK' or LIN04 = 'IN' or LIN04 = 'BP' or LIN04 = 'OT' or LIN04 = 'IT')">
<xsl:value-of select="LIN05" />
</xsl:when>
...
<xsl:when test="(LIN30 = 'CB' or LIN30 = 'SK' or LIN30 = 'IN' or LIN30 = 'BP' or LIN30 = 'OT' or LIN30 = 'IT')">
<xsl:value-of select="LIN31" />
</xsl:when>
</xsl:choose>
But there is an elegant, clear and short way to do the same. I prefer something like this:
<xsl:variable name="skuQuals" select="'~CB~SK~IN~BP~OT~IT~'" />
<xsl:value-of select="./*[contains(name(), 'LIN') and (number(substring-after(name(), 'LIN')) mod 2 = 0) and contains($skuQuals, concat('~', text(), '~'))]/following-sibling::*"/>
Gennady Kim