We're using XSLT2. Wondering if this is possible.
We have a tag filter, where a customer can choose to see all the themes which match ALL of their selections.
Here's an idea of the XML structure:
<themes>
<theme>
<name>Apple</name>
<tags>
<tag id="1">
<tag id="2">
</tags>
</theme>
<theme>
<name>Banana</name>
<tags>
<tag id="2">
<tag id="3">
</tags>
</theme>
<theme>
<name>Kiwifruit</name>
<tags>
<tag id="2">
<tag id="3">
</tags>
</theme>
</themes>
The customer chooses tags 2 and 3. The result we want is to only show is Banana and Kiwifruit, as they have all the tags the user selected.
We can't use the AND operator as the list of tags is long and unknown. We currently have this list passed into the XSLT and then tokenised:
<xsl:param name="tag_ids"/>
<xsl:variable name="tag_id_list" select="tokenize($tag_ids,',')"/>
This statement selects any theme that has any of the tag_id_list:
<xsl:for-each select="themes/theme/tags/tag[@id=$tag_id_list]">
But we're trying to find a XPath statement that makes sure the has ALL the s in $tag_id_list
Any ideas?! Thanks in advance.
You want this if the tags have to be in the right order:
themes/theme/tags[deep-equal($tag_id_list, tag/@id)]
or this if they can be in any order:
themes/theme/tags[
(every $tag in $tag_id_list satisfies $tag = tag/@id)
and
(every $tag in tag/@id satisfies $tag = $tag_id_list)]
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With