Page 1 of 1

XSLT IF Multiple Conditions

Posted: Mon May 11, 2015 5:32 pm
by lukeharris95
Hi,

I have created a CV as my XML document. I have than made a XSL which produces either a accept/reject letter based on if certain words appear in the XML.

That criteria is as follows: If the word 'Web Developer' appear in <experienceSummary> AND 'Information' OR 'Computer' OR 'Web' appear in <educationSummary> then load up a accept letter. If this criteria is not met load up a reject letter.

I have got it working for the word 'Web Developer' but I'm not sure how to connect the other words to this expression.

Code: Select all

<xsl:variable name="search">
<xsl:value-of select="//experienceSummary"/>
</xsl:variable>

<xsl:variable name="expSearch">
<xsl:value-of select="//educationSummary"/>
</xsl:variable>

<xsl:if test="contains($search, 'Web Developer')">

<!-- <xsl:if test="contains($search, 'Web Developer' and ($expSearch='Computer' or $expSearch='Information' or $expSearch='Web' ))"> -->

<!-- <xsl:if test="contains($search, 'Web Developer' and (contains($expSearch, 'Computer' or 'Information' or 'Web' )))"> -->

<p>Buckinghamshire New University regard that your experience as a Web Developer to be relevant to this post.</p>

<p>Your award [item title from CV XML], also fulfils elements of the job description.</p>

<p>We are therefore pleased to invite to an interview on: Monday 18th May 2015.</p>

</xsl:if>

<xsl:if test="not(contains($search, 'Web Developer'))">

<p>Buckinghamshire New University received many applications for this post. Due to the strength of the field we regret that you have not been selected for an interview on this occasion.</p>

<p>We will, however, keep your CV on file for consideration when similar opportunities arise.</p>

</xsl:if>
I have searched almost everywhere for a solution with no luck!! Surely it can't be that hard to have a IF test with multiple conditions. Thanks in advance for any help given, will be much appreciated!

Re: XSLT IF Multiple Conditions

Posted: Tue May 12, 2015 12:31 pm
by adrian
Hi,

If you use boolean operators (or/and) between strings, you'll get a boolean result (true/false), which isn't useful since you need a string for the contains() function. So you need to apply contains() on each individual string.

Code: Select all

<xsl:if test="contains($search, 'Web Developer') and (contains($expSearch, 'Computer') or contains($expSearch, 'Information') or contains($expSearch, 'Web' ))">
Regards,
Adrian

Re: XSLT IF Multiple Conditions

Posted: Tue May 12, 2015 12:37 pm
by lukeharris95
Thanks Adrian! :)