xsl-list
[Top] [All Lists]

[xsl] filter using contains with multiple values

2016-03-02 12:42:58
Hi,

I created a filter statement using two variables to a) specify the node of 
interest and b) the value to be matched:

XSL is like this:
...
<xsl:if test="*[name()=$filter]=contains(., $filter_value)”>
…

feed with the following XML:

<list>
  <entry>
    <keyword>Log</keyword>
    <location>A</location>
  </entry>
  <entry>
    <keyword>Log</keyword>
    <location>B</location>
  </entry>
  <entry>
    <keyword>Problem</keyword>
    <location>A</location>
  </entry>
  <entry>
    <keyword>Info</keyword>
    <location>B</location>
  </entry>
</list>

so that setting ‘filter’ to ‘keyword’ and ‘filter_value’ to ‘Log’ will only 
match the first two ‘entry’ nodes. Fine so far, but now
I would like to allow to pass in a flexile number of values for the 
‘filter_value’, like ‘Log’ or ‘Info’ to match the first two plus the
last entry. I guess the solution would be to do this in kind of a loop, but how 
can this be done with ‘filter_value’ being a
simple XSL variable or is exactly this the weakness of the approach?

I’running Saxon version: 9.1.0.8 so that I’m able to use XSLT and XPath 2.0.

Thanks,
Raimund 
--~----------------------------------------------------------------
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
EasyUnsubscribe: http://lists.mulberrytech.com/unsub/xsl-list/1167547
or by email: xsl-list-unsub(_at_)lists(_dot_)mulberrytech(_dot_)com
--~--

<Prev in Thread] Current Thread [Next in Thread>