?
Solved

XSLT Variable Scope

Posted on 2007-07-24
7
Medium Priority
?
1,083 Views
Last Modified: 2013-11-18
Have the following problem, its more of a syntax/grammar issue than a problem. but the idea is that you have a case statement that gives you the node then you do the for each that outputs it. Gives the error: A reference to variable or parameter 'venSearch' cannot be resolved. The variable or parameter may not be defined, or it may not be in scope.

<xsl:if test="...condition1...">
  <xsl:variable name="...name..." select="...node1..."/>
</xsl:if>
<xsl:if test="...condition2...">
  <xsl:variable name="...name..." select="...node2..."/>
</xsl:if>  

<xsl:for-each select="$...name..."/>
...
...
(aka 200 lines of code specific to this condition that I dont want to repeat however many times for each condition)
...
...
</xsl:for-each>
0
Comment
Question by:BeenSwank
  • 2
  • 2
  • 2
  • +1
7 Comments
 
LVL 13

Assisted Solution

by:R7AF
R7AF earned 248 total points
ID: 19555115
Try this:

<xsl:variable name="test">
  <xsl:if>... </xsl:if>
</xsl:variable>
0
 
LVL 14

Expert Comment

by:bugs021997
ID: 19555125
Can you paste the code for the calling page......
0
 
LVL 14

Expert Comment

by:bugs021997
ID: 19555157
It can be referenced as @R7AF suggested...

<xsl:if test="price > 10">
        <xsl:value-of select="title"/>
        <xsl:value-of select="artist"/>
</xsl:if>
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
LVL 13

Expert Comment

by:R7AF
ID: 19555483
You put the variable inside the if-statement. Then the if-statement is the scope, and the variable can only be used inside the if-statement. In your example it's useless.
0
 
LVL 12

Accepted Solution

by:
jkmyoung earned 252 total points
ID: 19557898
So do you want one variable which contains a list of nodes? If so, try as presented before, make the variable actually contain multiple nodes:
<xsl:variable name="master">
  <xsl:if test="...condition1...">
    <name><xsl:value-of select="...node1..."/></name>
  </xsl:if>
  <xsl:if test="...condition2...">
    <name><xsl:value-of select="...node2..."/></name>
  </xsl:if>
...
</xsl:variable>

Now when you call the for-each on this variable, you may need to use a node-set function, eg <xsl:for-each select="msxsl:node-set($master)\name" xmlns:msxsl="urn:schemas-microsoft-com:xslt" e>
0
 

Author Comment

by:BeenSwank
ID: 19563662
Works well jkmyoung, but didnt need to elaborate on output Final script:

<xsl:variable name="venSearch">
      <xsl:if test="$k_location='Warwickshire'">
         <xsl:value-of select="document(concat($docOp, $k_category, '_', $k_type, $docCl))//venue[county='Warwickshire']"/>
      </xsl:if>
  <xsl:if test="$k_location='West Midlands'">
         <xsl:value-of select="document(concat($docOp, $k_category, '_', $k_type, $docCl))//venue[county='West Midlands']"/>
      </xsl:if>
</xsl:variable>

<xsl:value-of select="$venSearch"/>
0
 
LVL 12

Expert Comment

by:jkmyoung
ID: 19564491
If only one of the conditions will ever be true, you could use a choose, when clause instead; it'll slightly boost peformance, by stopping at the first clause that is true. Of course, if you're not worried about that you can ignore this post altogether.

<xsl:variable name="venSearch">
  <xsl:choose>
      <xsl:when test="$k_location='Warwickshire'">
         <xsl:value-of select="document(concat($docOp, $k_category, '_', $k_type, $docCl))//venue[county='Warwickshire']"/>
      </xsl:when>
  <xsl:when test="$k_location='West Midlands'">
         <xsl:value-of select="document(concat($docOp, $k_category, '_', $k_type, $docCl))//venue[county='West Midlands']"/>
      </xsl:when>
  </xsl:choose>
</xsl:variable>
0

Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

Question has a verified solution.

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

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…
Create a Windows 10 custom Image with custom task bar and custom start menu using XML for deployment.
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 how to dynamically set the form action using jQuery.
Suggested Courses

840 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