Celebrate National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

How to use "and" in a when statement

Posted on 2011-02-22
8
Medium Priority
?
298 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 3
8 Comments
 
LVL 60

Accepted Solution

by:
Geert Bormans earned 2000 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
More Than Just A Video Library

Train for your certification. Learn the latest DevOps tools. Grow your skillset to do better work.

At Linux Academy, we release new training modules every week so you'll always be up to date on the latest tech.

 

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

TCP/IP Network Protocol Cheat Sheet

TCP/IP is a set of network protocols which is best known for connecting the machines that make up the Internet. The truth is that TCP/IP is one of the oldest network protocols and its survival is mainly based on its simplicity and universality.

Question has a verified solution.

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

Styling your websites can become very complex. Here I'll show how SASS can help you better organize, maintain and reuse your CSS code.
Create a Windows 10 custom Image with custom task bar and custom start menu using XML for deployment.
The viewer will receive an overview of the basics of CSS showing inline styles. In the head tags set up your style tags: (CODE) Reference the nav tag and set your properties.: (CODE) Set the reference for the UL element and styles for it to ensu…
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.

730 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