xmlxsltxslt-1.0exslt

How to compare string with array in XSLT1.0 in apply templates


Suppose, if I have "Test1|Test2|Test3" as a string and I want compare it with following:

<items>
<item>Test1</item>
<item>Test2</item>
<item>Test3</item>
</items>

Is it possible to check in apply template is it true of false?

Thanks


Solution

  • I would suggest you take precaution and use:

    <xsl:apply-templates select="item[contains(concat('|', $yourString, '|'), concat('|', ., '|'))]"/>
    

    Otherwise you may get false positives - for example, if your string is:

    Test1|Test25|Test301
    

    a simple contains() test will also pass all of these:

    <item>Test2</item>
    <item>Test3</item>
    <item>Test30</item>