0

I have the following XML snippet:

<figure customer="ABC DEF">
    <image customer="ABC"/>
    <image customer="XYZ"/>
</figure>

I'd like to check if the figure element's customer attribute contains the customer attributes of the image elements.

<xsl:if test="contains(@customer, image/@customer)">
    ...
</xsl:if>

I get an error saying:

a sequence of more than one item is not allowed as the second argument of contains

It's important to note that I cannot tell the values of the customer attributes in advance, thus using xsl:choose is not an option here.

Is it possible to solve this without using xsl:for-each?

1 Answer 1

2

In XSLT 2.0 you can use:

test="image/@customer/contains(../../@customer, .) = true()"

and you will get a true() result if any of them are true. Actually, that leads me to suggest:

test="some $cust in image/@customer satisfies contains(@customer, $cust)"

but that won't address the situation where the customer string is a subset of another customer string.

Therefore, perhaps this is best:

test="tokenize(@customer,'\s+') = image/@customer"

... as that will do a string-by-string comparison and give you true() if any of the tokenized values of the figure attribute is equal to one of the image attributes.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.