xsl-list
[Top] [All Lists]

Re: [xsl] filter using contains with multiple values

2016-03-04 11:21:56
wow getting more and more complex!
Yes I had still stylesheet version 1.0 there - ups, but even using exactly your 
stylesheet declarations I still do not succeed!
So I guess the problem must be elsewhere. To give you the full picture:

The code we are talking about is a XSL stylesheet is used by a servlet passing 
in the filter stuff in using transformer.setParameter and filter_values are 
passed to the servlet
using javascript. So to get to the bottom of the problem I inserted the 
filter_values directly into the setParameter and now see the following:

                        transformer.setParameter("filter", "keywords");
                        transformer.setParameter("filter_values", "Log");   

works fine as expected! But:

                       transformer.setParameter("filter_values", “'Log'");   

(note the single quotes on the second argument of the filter_values!) Doesn’t 
work! So it looks like the quotes are passed to the xls:parameter and on 
doesn’t get a match
on Logging (but would on ‘Logging’)!

So passing the parameters using:

                       transformer.setParameter("filter_values", “‘Log’, 
‘Info'”);

does also not work - as one would now naturally expect!

So one could think of passing them using:

                       transformer.setParameter("filter_values", “Log, Info”);

(which does not work either) but here I guess the whole second argument is 
interpreted as one single string (object) and I knew in advance that this is 
not meant to be working!

So at this point I guess I’m faced with the topic of 1) which transformer 
implementation one is using (I believe it’s Saxon - but am I sure?) and 2) how 
this implementation is handling
the second argument of the setParameter (which is of type Object).
Is there a easy way out e.g. how would one have to quote the argument if it is 
a complex string like the one I’m aiming for?

These are the details an I get from the tomcat servlet engine:

Saxon version: 9.1.0.8
Version and details of JAXP

• DocumentBuilderFactory implementation: 
org.apache.xerces.jaxp.DocumentBuilderFactoryImpl loaded from: Java Runtime
• XPathFactory implementation: org.apache.xpath.jaxp.XPathFactoryImpl loaded 
from: Java Runtime
• TransformerFactory implementation: net.sf.saxon.TransformerFactoryImpl loaded 
from: Java Runtime
• SAXParserFactory implementation: org.apache.xerces.jaxp.SAXParserFactoryImpl 
loaded from: Java Runtime

which always confused me (why do I get this mixture of org.apache. and 
net.sf.saxon?) 
 
   

Are you sure you are using an XSLT 2.0 processor with the
 <xsl:stylesheet version="2.0"
? The xsl:value-of results sounds as if you have the wrong version attribute 
on your xsl:stylesheet or xsl:transform (or somewhere in your code you set 
xsl:version to 1.0).

For me

<?xml version="1.0" encoding="UTF-8" ?>
<xsl:transform xmlns:xsl="http://www.w3.org/1999/XSL/Transform"; version="2.0"
 xmlns:xs="http://www.w3.org/2001/XMLSchema"; exclude-result-prefixes="xs">

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

<xsl:template match="/">
   <xsl:copy-of select="//*[name() = $filter and . = $filter_values]"/>
</xsl:template>


</xsl:transform>

when run against

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

with Saxon 9 (see online at http://xsltransform.net/gWvjQg1) returns the 
three elements

<keyword>Log</keyword><keyword>Log</keyword><keyword>Info</keyword>


The contains check with "some" would be

<xsl:transform xmlns:xsl="http://www.w3.org/1999/XSL/Transform"; version="2.0"
 xmlns:xs="http://www.w3.org/2001/XMLSchema"; exclude-result-prefixes="xs">

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

<xsl:template match="/">
   <xsl:copy-of select="//*[name() = $filter and (some $value in 
$filter_values satisfies contains(., $value))]"/>
</xsl:template>


</xsl:transform>

with the sample

<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>The newest Info</keyword>
   <location>B</location>
 </entry>
</list>


giving

<keyword>Log</keyword><keyword>Log</keyword><keyword>The newest Info</keyword>

(Online at http://xsltransform.net/gWvjQg1/1)

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