Solved

XSL Session variable check syntax

Posted on 2007-11-27
11
1,556 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
Optimizing Cloud Backup for Low Bandwidth

With cloud storage prices going down a growing number of SMBs start to use it for backup storage. Unfortunately, business data volume rarely fits the average Internet speed. This article provides an overview of main Internet speed challenges and reveals backup best practices.

 
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

NAS Cloud Backup Strategies

This article explains backup scenarios when using network storage. We review the so-called “3-2-1 strategy” and summarize the methods you can use to send NAS data to the cloud

Question has a verified solution.

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

There are two main kinds of selectors in CSS: One is base selector like h1, h2, body, table or any existing HTML tags.  For instance, the following rule sets all paragraphs (<p> elements) to red: (CODE) CSS also allows us to define our own custom …
SASS allows you to treat your CSS code in a more OOP way. Let's have a look on how you can structure your code in order for it to be easily maintained and reused.
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

773 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