xsl-list
[Top] [All Lists]

Re: [xsl] filter using contains with multiple values

2016-03-03 12:25:21
Great this was exactly what I was looking for, BUT it does not work for me! 
There seam to be two problems:

1. Saxon complains about ‘some’ after the ‘and’:

  XPST0003: XPath syntax error at char 21 on line 279 in {*[name()=$filter and 
some $}:
    Unexpected token "some" in path expression

but here I get out using this much better syntax suggested by Michael Kay:

test="*[name()=$filter][. = $filter_value]”

2. so if I sum up these both tips, I end up with:

test="*[name()=$filter][some $value in $filter_value satisfies .=$value]”

which works correctly for filter_value holding only one string like:

<xsl:param name="filter_values" as="xs:string*" select=“Log”/>

but does not match any of them if filter_value holds e.g. two values:

<xsl:param name="filter_values" as="xs:string*" select="'Log', 'Info'”/>

So I guess I’m missing some concept on how to work with a ‘atomic’ type as 
xs:string is to have the ‘some in satisfies’
properly iterate over it!?

Raimund

On 02 Mar 2016, at 19:54, Martin Honnen martin(_dot_)honnen(_at_)gmx(_dot_)de 
<xsl-list-service(_at_)lists(_dot_)mulberrytech(_dot_)com> wrote:

Raimund Kammering raimund(_dot_)kammering(_at_)desy(_dot_)de wrote:

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.

You can use

 <xsl:if test="*[name()=$filter and some $value in $filter_values satisfies 
contains(., $value)]”>

where you define <xsl:param name="filter_values" as="xs:string*" 
select="'Log', 'Info'"/>.


--~----------------------------------------------------------------
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>