Solved

How to use "and" in a when statement

Posted on 2011-02-22
8
292 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
 

Author Comment

by:badtz7229
ID: 34954080
nevermind, i got it. i was missing doubel quotes outside
0
3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

 
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

DevOps Toolchain Recommendations

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

Question has a verified solution.

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

Preface This is the third article about the EE Collaborative Login Project. A Better Website Login System (http://www.experts-exchange.com/A_2902.html) introduces the Login System and shows how to implement a login page. The EE Collaborative Logi…
I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
Viewers will learn about the different types of variables in Java and how to declare them. Decide the type of variable desired: Put the keyword corresponding to the type of variable in front of the variable name: Use the equal sign to assign a v…
The viewer will learn how to dynamically set the form action using jQuery.

932 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

10 Experts available now in Live!

Get 1:1 Help Now