简体   繁体   中英

xslt 2.0 check if at least one attribute value equals values specified in variable

I have a variable that contains two values, eg one two

I have elements that have an attribute that has one of the values, none of these values or one of these values and other values, eg

<elem att="one"/>
<elem att="two"/>
<elem att="one somethingelse"/>
<elem att="two somethingelse somemore"/>

When I do this:

<xsl:if test="@att = $variable"></xsl:if> it is true if the attribute contains one of the values contained in the variable.

But it should also be true if the attribute value contains one of the values and then maybe some more, eg the last two elem elements.

How can I do that? Do I need to iterate over each attribute value separately?

So to make it clear: With my code, the test is only true for the first two elem elements but not for the last two. I nedd to check if at least one of the attribute values matches one of the values in the variable.

假设您的变量是一个字符串序列,我将标记属性值并进行比较,即<xsl:if test="$variable = tokenize(@att, '\\s+')">...</xsl:if>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM