tesmc
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
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>
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
could be that you are not passing anything to $missing?
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
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>
ASKER
nevermind, i got it. i was missing doubel quotes outside
passing the parameter is right
OK, I see
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
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>
no you can't
<xsl:value-of select="key('oldData', $code)/$missing"/>
should be
<xsl:value-of select="key('oldData', $code)/*[name() = $missing]"/>
<xsl:value-of select="key('oldData', $code)/$missing"/>
should be
<xsl:value-of select="key('oldData', $code)/*[name() = $missing]"/>