Link to home
Start Free TrialLog in
Avatar of tesmc
tesmcFlag for United States of America

asked on

How to use "and" in a when statement

I have a template that receives 2 parameters. This template runs a key function to compare a value .
I want the condition to read when key is found AND 2nd parameter value equals the string "x2" then return the value found in the key.

right now i have the following:
but i want to include the and-statement, but I keep getting error that missing variable is not declared.

please advise on syntax

   
<xsl:template name="getVal">
    <xsl:param name="code"/>
    <xsl:param name="missing"/>
   
    <xsl:choose>

      <xsl:when test="key('oldData', $code)" > <!--and $missing ='x2'>-->

        <xsl:value-of select="key('oldData', $code)/x2"/>
      </xsl:when>

    </xsl:choose>
  </xsl:template>

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of Gertone (Geert Bormans)
Gertone (Geert Bormans)
Flag of Belgium image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
could be that you are not passing anything to $missing?
Avatar of tesmc

ASKER

i see i was missing the double quotes in my and-statement.
Gertone: you are right. my $missing is null.
i am passing a string into this variable during my function call.
see below

so i'm not sure if my syntax for passing a variable is incorrect. i tried with single and double quotes but i still get null
<xsl:call-template name="getVal">
                <xsl:with-param name="code" select="$pk"/>
                <xsl:with-param name="missing" select='x2'/>
              </xsl:call-template>

Open in new window

Avatar of tesmc

ASKER

nevermind, i got it. i was missing doubel quotes outside
passing the parameter is right
Avatar of tesmc

ASKER

i'm wondering though - since my "missing" parameter is actually an element name can i do something like  below?
where i pass missing variable into my value=of select?
 i keep getting error when i do this, perhaps my syntax is off
<xsl:choose>
      <xsl:when test="key('oldData', $code)" > 
        <xsl:value-of select="key('oldData', $code)/$missing"/>
      </xsl:when>
    </xsl:choose>

Open in new window

no you can't

  <xsl:value-of select="key('oldData', $code)/$missing"/>

should be

  <xsl:value-of select="key('oldData', $code)/*[name() = $missing]"/>