Solved

XSL Session variable check syntax

Posted on 2007-11-27
11
1,558 Views
Last Modified: 2013-11-18
I have an xsl file that is being used on a web page to display a table that contains menu links. The menu tems are like -
Help    Subscribe   Return

On certain logins which are stored in a session variable - Session["LoginCheck"] I don't want to show the "return" menu item.
Is there certain syntax to do this or go about this?
0
Comment
Question by:jandhb
  • 5
  • 4
11 Comments
 
LVL 60

Expert Comment

by:Geert Bormans
ID: 20363654
yes, you can set a parameter on the highest level in your stylesheet
<xsl:param name="loginCheck"/>

use that parameter in a test as $loginCheck

and pass the value of the ession variable to the stylesheet
I can show you how, if you show how you call the XSLT
Make sure you use a template processor instead of a simple transform
in order to be able to pass parameters

cheers


Geert
0
 
LVL 1

Author Comment

by:jandhb
ID: 20365333
Geert,

When you say "use that parameter in a test as $loginCheck" can you show me how that would be done? In this particular case I just need to check if the value of that is > 1.

How would I pass the value of the session variable to the stylesheet? Right now I'm calling the XSLT with - <asp:Xml Runat="server" ID="xmlMenu" TransformSource="../navigation/menu.xslt" />
0
 
LVL 60

Expert Comment

by:Geert Bormans
ID: 20365774
<xsl:choose>
  <xsl:when test="$loginCheck = 1">
    output the column here
  </xsl:when>
  <xsl:otherwise>
    don't output the column
  </xsl:otherwise>
</xsl:choose>

you can leave the "otherwise" clause out if you don't need it
0
Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
LVL 1

Author Comment

by:jandhb
ID: 20365787
ok, i follow that, but i thought you said i had to pass the session variable to the xslt page first?
0
 
LVL 60

Expert Comment

by:Geert Bormans
ID: 20365809
yes, that is a bit trickier when you use an XML control
Here is an article that shows you how to do that

http://www.braintrove.com/article/13

cheers

Geert
0
 
LVL 1

Author Comment

by:jandhb
ID: 20366205
I took a look at the article and have some quesions.

1. In the XSLT he is using xls:when should I use - <xsl:if test="$loginCheck > 1">

2. In my aspx this is not a query string. It is a session variable. So should I only do this without the request.querystring part?...

Args.AddParam("loginCheck ", "", loginCheck );
0
 
LVL 60

Accepted Solution

by:
Geert Bormans earned 25 total points
ID: 20366270
1. xsl:when is a statement inide an xsl:choose
xsl:if is equivalent to a single xsl:when without an xsl:otherwise
the adventage of xsl:if is that you don't need the xsl:choose
<xsl:choose><xsl:when test="sometest">blabla</xsl:when></xsl:choose>
and
<xsl:if test="sometest">blabla</xsl:if>
are equivalent

note that in the XSLT you best replace > with &gt;
<xsl:if test="$loginCheck &gt; 1">

2. just make sure that the value for $loginCheck gets put in the loginCheck variable in the ASP
it doesn't really matter whether it comes originally from a session variable or a request string
This line is where you pass the variable to the parameter
Args.AddParam("loginCheck", "", loginCheck );
note that I removed a space in the first argument to the method

cheers

Geert
0
 
LVL 1

Author Comment

by:jandhb
ID: 20366351
I have this in my page load now...

XsltArgumentList Args = new XsltArgumentList();
 
    Args.AddParam("loginCheck", "", loginCheck );
 
    xmlMenu.TransformArgumentList = Args;

look right?
0
 
LVL 60

Expert Comment

by:Geert Bormans
ID: 20366361
looks right
0
 
LVL 1

Expert Comment

by:Computer101
ID: 21146866
Forced accept.

Computer101
EE Admin
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Browsers only know CSS so your awesome SASS code needs to be translated into normal CSS. Here I'll try to explain what you should aim for in order to take full advantage of SASS.
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
Viewers will learn one way to get user input in Java. Introduce the Scanner object: Declare the variable that stores the user input: An example prompting the user for input: Methods you need to invoke in order to properly get  user input:
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

820 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