Filter on multiple params in XSL

I'm trying to pass multiple params into an XSL stylesheet in order to filter the contents of the output based on the values of certain XML elements.  The default state of the stylesheet should not filter on these params.  The gist of what I've got so far:

<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="2.0"
        xmlns:xsl="http://www.w3.org/1999/XSL/Transform" >
  <xsl:param name="filterBy">FLAGGED</xsl:param>
  <xsl:param name="filterValue">1</xsl:param>
  <xsl:param name="filterBy2">PREFERRED</xsl:param>
  <xsl:param name="filterValue2"></xsl:param>
   
     <xsl:template match="/">
       <xsl:for-each select="//APPLICANT[*[(name() = $filterBy and . = $filterValue)]]">
         
        ...(table built from <xsl:value-of select="FLAGGED">, etc. )...

       </xsl:for-each>
     </xsl:template>
</xsl:stylesheet>

This only displays rows where filterBy = filterValue, which is good.  What I need is for this to default to NOT filtering AND to be able to simultaneously filter by other parameters, too.  I'd rather not put the filtering in the XML transform function if I don't have to.  
LVL 2
etd_onlineguysAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Geert BormansInformation ArchitectCommented:
Hi etd_onlineguys,

you can make the parameters empty by default, which is good practice
  <xsl:param name="filterBy"/>
  <xsl:param name="filterValue"/>
  <xsl:param name="filterBy2"/>
  <xsl:param name="filterValue2"/>

and make your test like this
    <xsl:for-each select="//APPLICANT[*[( (name() = $filterBy or string-length($filterBy) = 0) and ...)]]">

which is true if you don't pass a parameter

cheers

Geert
0
etd_onlineguysAuthor Commented:
Hi Gertone,
Thanks for the response.  The string-length() trick is a good one and I've got this working with one filter parameter.  I'm still unsure of how to get the additional filter parameters to work.   I tried using multiple predicates

<xsl:for-each select="//APPLICANT[*
        [(name() = $filterBy or string-length($filterBy) = 0) and . = $filtervalue]
        [(name() = $filterBy2 or string-length($filterBy2) = 0) and . = $filterValue2]
    ]">

but ended up with no results even though some rows met both filter criteria.  What am I missing?

David
0
Geert BormansInformation ArchitectCommented:
two predicates chained is an implicit AND operation
I see four conditions that should all four be true
two of the conditions are . = $filtervalue and . = $filterValue2
this condition can only be met if $filtervalue = $filterValue2
That is likely not true... so you will get no results

do you want an OR between the two predicates?
then you need a union
<xsl:for-each select="//APPLICANT[
        * [(name() = $filterBy or string-length($filterBy) = 0) and . = $filtervalue]
       | *[(name() = $filterBy2 or string-length($filterBy2) = 0) and . = $filterValue2]
    ]">

cheers

Geert
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
etd_onlineguysAuthor Commented:
Gertone,
That was exactly what I needed!  Thanks!
David
0
Geert BormansInformation ArchitectCommented:
welcome David
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
XML

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.