Solved

How to use "and" in a when statement

Posted on 2011-02-22
8
291 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
Comment Utility
<xsl:when test="key('oldData', $code) and $missing ='x2' ">
0
 
LVL 60

Expert Comment

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

Author Comment

by:badtz7229
Comment Utility
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
Comment Utility
nevermind, i got it. i was missing doubel quotes outside
0
Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
LVL 60

Expert Comment

by:Geert Bormans
Comment Utility
passing the parameter is right
0
 
LVL 60

Expert Comment

by:Geert Bormans
Comment Utility
OK, I see
0
 

Author Comment

by:badtz7229
Comment Utility
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
Comment Utility
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

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

Preface In the first article: A Better Website Login System (http://www.experts-exchange.com/A_2902.html) I introduced the EE Collaborative Login System and its intended purpose. In this article I will discuss some of the design consideratio…
The Confluence of Individual Knowledge and the Collective Intelligence At this writing (summer 2013) the term API (http://dictionary.reference.com/browse/API?s=t) has made its way into the popular lexicon of the English language.  A few years ago, …
Viewers will learn about basic arrays, how to declare them, and how to use them. Introduction and definition: Declare an array and cover the syntax of declaring them: Initialize every index in the created array: Example/Features of a basic arr…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)

744 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

18 Experts available now in Live!

Get 1:1 Help Now