Solved

How to use "and" in a when statement

Posted on 2011-02-22
8
293 Views
Last Modified: 2013-11-08
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

0
Comment
Question by:badtz7229
  • 5
  • 3
8 Comments
 
LVL 60

Accepted Solution

by:
Geert Bormans earned 500 total points
ID: 34953256
<xsl:when test="key('oldData', $code) and $missing ='x2' ">
0
 
LVL 60

Expert Comment

by:Geert Bormans
ID: 34953316
could be that you are not passing anything to $missing?
0
 

Author Comment

by:badtz7229
ID: 34953975
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

0
DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

 

Author Comment

by:badtz7229
ID: 34954080
nevermind, i got it. i was missing doubel quotes outside
0
 
LVL 60

Expert Comment

by:Geert Bormans
ID: 34954116
passing the parameter is right
0
 
LVL 60

Expert Comment

by:Geert Bormans
ID: 34954119
OK, I see
0
 

Author Comment

by:badtz7229
ID: 34954120
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

0
 
LVL 60

Expert Comment

by:Geert Bormans
ID: 35219071
no you can't

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

should be

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

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I found this questions asking how to do this in many different forums, so I will describe here how to implement a solution using PHP and AJAX. The logical flow for the problem should be: Write an event handler for the first drop down box to get …
Many times as a report developer I've been asked to display normalized data such as three rows with values Jack, Joe, and Bob as a single comma-separated string such as 'Jack, Joe, Bob', and vice versa.  Here's how to do it. 
Viewers will learn about if statements in Java and their use The if statement: The condition required to create an if statement: Variations of if statements: An example using if statements:
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.

815 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now