On 2 Mar 2016, at 18:43, Raimund Kammering
raimund(_dot_)kammering(_at_)desy(_dot_)de
<xsl-list-service(_at_)lists(_dot_)mulberrytech(_dot_)com> wrote:
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)”>
*[name()=$filter] returns a set/sequence of element nodes; the contains()
function returns a boolean.
The result of comparing a node-set to a boolean depends on whether you are
running 1.0 (or 2.0 with backwards compatibility enabled) or 2.0.
In either case, I don't think it does what you want. I think you want
test="*[name()=$filter][contains(., $filter_value)]"
But perhaps you don't even want contains(). In your example, you are matching
the whole value, rather than a substring. That suggests that an "=" test is
wanted, not a "contains" test. So:
test="*[name()=$filter][. = $filter_value]"
Michael Kay
Saxonica
…
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
--~--