• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 453
  • Last Modified:

Can I test for an ASP session variable with the XSLT <xsl:when> statement?


Hello,

Is there a way to use the xsl 'when' statement with an asp variable? I have an ASP page that has xslt in it, and it has a session variable that is set to 'metasecured'. I am wanting to test for this with the xslt. The session variable is not in the xml, so I don't know if this is possible. My session variable is set at the top of the asp page, like so, 'metasecured = SESSION("metasecured")'.

I have tried the below arrangments and all of them produce asp errors that point at the quotation marks and say, "Expected end of statement" or something like that...

Thank you,
JA67


<xsl:when test=<%metasecured="True"%>>

<xsl:when test="<%metasecured=""True""%>">

<xsl:when test="<%metasecured='True'%>">

<xsl:when test='<%metasecured="True"%>'>

<xsl:when test=""<%metasecured="True"%>"">
0
JA67
Asked:
JA67
  • 7
  • 5
1 Solution
 
Geert BormansCommented:
Hi JA67,

In your XSLT you can have a global parameter, eg <xsl:param name="metasecured" />
then you can test <xsl:when test="$metasecured = 'True'">

you have to pass the parameter to the transformer like this
oProc.addParameter("metasecured ", metasecured);

Cheers!
0
 
JA67Author Commented:
Thanks for responding. I have added the parameter as you see below in Example 1.  I put the two lines under my stylesheet line. Is that where they belong?  Then see below in Example 2., to see how I have the xsl:when statement. I am getting an error now with these changes, "The stylesheet does not contain a document element."

I know that my ASP session variable is only true, dependant on the results of a recordset that either pulls back a vaule of 'metasecured' or not. Would this xsl:param that I've added  be aware of this recordset value?

Example1:
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:msxsl="urn:schemas-microsoft-com:xslt" version="1.0">
<xsl:param name="metasecured" />
oProc.addParameter("metasecured ", metasecured)


Example2:
<xsl:element name="a">    
        <xsl:choose>
            <xsl:when test="$metasecured = 'True'">                
            <a target="_blank">            
                <xsl:attribute name="href">CRMR/frame.asp</xsl:attribute>
                   <xsl:attribute name="onClick">javascript:window.open( this.href,'','width='+screen.width+',height='+screen.height+ ',top=0,left=0,resizable=yes,toolbar=yes,menubar=yes,status=yes,scrollbars=yes');return false;</xsl:attribute>
          </a>
            </xsl:when>
            <xsl:otherwise>
0
 
Geert BormansCommented:
Example1 and Example2 are OK,
if they are part of one stylesheet

this line should go in your ASP though
oProc.addParameter("metasecured ", metasecured)

I assume you have a Template Processor in your ASP (that is what you need to pass parameters to XSLT in classic ASP)
If not, can you show me the part where you call the XSLT process from your ASP,
I might have to change that

the XSLT now has access to the recordset, if the variable metasecured is set to true based on the recordset before it is passed to the stylesheet
From what I see now, the XSLT wil be fine,
but you will need some work on the ASP still

cheers

Geert
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
JA67Author Commented:
Here is the entire ASP page. I am not really sure if I have a Template Processor or not...  Just  a few lines into the code you will see the session variable, if that's the right thing to call it. This is set from a login.asp page. The login page is what queries a database looking for 'metasecured' based on the login ID.

I hope this helps you help me. I am so far beneath you in my understanding, that it's hard for me to explain what I need. But you seem to be deciphering me pretty well. lol.


Thank you!
JA67


<!-- #include file="../../includes/adovbs.inc" -->

<%
metasecured = SESSION("metasecured")

Dim oCon

''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
'The dsts.dll has to be registered with the webserver
Set oDsts = Server.CreateObject("DSTS.connection")
'The constants gcServer, gcDatabase, gcUserID, gcPassword have been
'declared in the connAdworc.inc file.
Set oCon = oDsts.SQLServer(gcServer, gcDatabase, gcUserID, gcPassword)
oCon.Open
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
%>

<%
' This recordset is for the CRDW Help Desk Welcome To message.
Set rstWelcTo = Server.CreateObject("ADODB.recordset")
      rstWelcTo.CursorLocation = adUseClient
      rstWelcTo.Open "SELECT mdi_txt FROM mdi  WHERE mdi_type_cd = 'WT' And mdo_id = 507", oCon, adOpenDynamic, adLockPessimistic
      
Set rstWelcTo.ActiveConnection = Nothing
oCon.Close
Set oCon = Nothing
%>


<html>

<head>
<title>CRDW Help Desk</title>
<link rel="stylesheet" type="text/css" href="../../includes/whitespace_style.css"/>
<link rel="stylesheet" href="../../includes/drop_down.css" type="text/css" media="screen"/>

<script language="JavaScript" type="text/javascript" src="../../js/drop_down.js"></script>
      <script language="JavaScript"  type="text/javascript" src="../../js/bookmark.js"></script>
      <script language="javascript">
                  var oDom = null;
                  var oProcessor = null;
                  function initializeData() {
                        oDom = xmlMetaSubMnu.XMLDocument;
                        var oProcessor = getProcessor(metaSubMnu_xsl.XMLDocument);
                        divMetaSubMnu.innerHTML = oDom.transformNode(metaSubMnu_xsl.XMLDocument);
                  }
                  function getProcessor(oSrc) {
                        var oDoc = new ActiveXObject("Msxml2.FreeThreadedDOMDocument.3.0"); //5.0
                        var oTemplate = new ActiveXObject("Msxml2.XSLTemplate.3.0"); //5.0
                        
                        oDoc.async = false;
                        oDoc.load(oSrc);
                        oTemplate.stylesheet = oDoc;
                        loProcessor = oTemplate.createProcessor();
                        return loProcessor;
                  }
                  function displayXML(oDoc) {
                        oWin = window.open('','mywin');
                        oWin.document.write(oDoc.xml);
                  }
                        
                  
                  //Meta
                  metaOverview=new Image();
                  metaOverview.src="../../images/SecNavBar/metaOverview.gif"
                  
                  metaCRMR=new Image();
                  metaCRMR.src="../../images/SecNavBar/metaCRMR.gif"

                  metaAdw=new Image();
                  metaAdw.src="../../images/SecNavBar/metaAdw.gif"
                        
                  metaBusObjct=new Image();
                  metaBusObjct.src="../../images/SecNavBar/metaBusObjct.gif"
                  
                  metaBCBS=new Image();
                  metaBCBS.src="../../images/SecNavBar/metaBCBS.gif"
                  
                  metaBusInfo=new Image();
                  metaBusInfo.src="../../images/SecNavBar/metaBusInfo.gif"
      </script>

</head>


<body onResize="window.location.reload(false);" onLoad="initializeData();loadFrames();" style="background-color:transparent" topmargin="0" bottommargin="10" rightmargin="10" marginwidth="0" marginheight="0">
<!--<input type="button" onclick="displayXML(oDom)" value="click me!">-->
<!-- SubMenu -->
      <div id="divMetaSubMnu"></div>
      <xml id="xmlMetaSubMnu" src="../../metaSubMenuObject.asp?strSQL=exec mdo_ownr_sp 507,OWNCTNMETACRDW"/>
      <xml id="metaSubMnu_xsl">
            <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:msxsl="urn:schemas-microsoft-com:xslt" version="1.0">
            <xsl:param name="metasecured" />
            oProc.addParameter("metasecured ", metasecured)

            <xsl:template match="/">
                  <!--Main Menu-->
                  <div id="MainMenu" style="display:block">
                        <!-- ImageReady Slices (metaOverview.psd) -->
                        <img src="../../images/SecNavBar/metaAdw.gif" width="552" height="50" name="meta" border="0" usemap="#metaOverview_map"  />
                        <map name="metaOverview_map">
                        <area shape="rect" coords="0,3,110,49" href="../../xml_object.asp?mdo_sp=mdo_id_sp&amp;mdo_rltn_type_cd=OWNCTNMETACRDW,OWNCTNCRMR,OWNCTNBUSOBJCT,OWNCTNBCBSMO,OWNCTNBUSINFO&amp;mdi_type_cd=DFN,PARA,BODY,DESC&amp;mdo_xsl=meta/metaOverview.xsl&amp;mdo_id=7" target="white_space" onMouseOver="changeImages('meta','metaOverview')" onMouseOut="closeAll();changeImages('meta','metaAdw')" />
                        <area shape="rect" coords="104,9,189,48" href="../../CRMR/frame.asp" onclick="window.open( this.href,'','width='+screen.width+',height='+screen.height+ ',top=0,left=0,resizable=yes,toolbar=yes,menubar=yes,status=yes,scrollbars=yes');return false;" target="_blank" onmouseover="changeImages('meta','metaCRMR')" onmouseout="closeAll();changeImages('meta','metaAdw')" />
                        <area shape="rect" coords="183,9,286,47" href="HelpDeskOverview.asp" target="white_space" onMouseOver="controlSubMenu('metaCRDWmnu');changeImages('meta','metaAdw')" onMouseOut="closeAll();changeImages('meta','metaAdw')" />
                        <area shape="rect" coords="283,9,386,48" href="../../xml_object.asp?mdo_sp=mdo_ownr_sp&amp;mdo_rltn_type_cd=OWNCTNBUSINFO&amp;mdi_type_cd=DFN,PARA,BODY,DESC&amp;mdo_xsl=meta/BusInfo/metaBusInfo.xsl&amp;mdo_id=519" target="white_space" onMouseOver="controlSubMenu('metaBusInfoMnu');changeImages('meta','metaBusInfo')" onMouseOut="closeAll();changeImages('meta','metaAdw')" />
                        <area shape="rect" coords="380,9,463,48" href="../../xml_object.asp?mdo_sp=mdo_bcbs_ownr_sp&amp;mdo_rltn_type_cd=&amp;mdi_type_cd=DFN,PARA,BODY,DESC&amp;mdo_xsl=meta/BCBSMO/BCBSMOOverview.xsl&amp;mdo_id=11" target="white_space" onMouseOver="changeImages('meta','metaBCBS')" onMouseOut="closeAll();changeImages('meta','metaAdw')" />
                        <area shape="rect" coords="457,9,551,48" href="../../xml_object.asp?mdo_sp=mdo_id_sp&amp;mdo_rltn_type_cd=OWNCTNBUSOBJCTTOC,OWNCTNBUSOBJCTOWNR,OWNCTNBUSOBJCTSBJA,OWNCTNBUSOBJCTBUSFCT&amp;mdi_type_cd=DFN,PARA,BODY,DESC&amp;mdo_xsl=meta/busObjct/busObjctOverview.xsl&amp;mdo_id=8" target="white_space" onMouseOver="changeImages('meta','metaBusObjct')" onMouseOut="closeAll();changeImages('meta','metaAdw')" />
                        </map>
                         <!--End ImageReady Slices -->
                  </div>
                  
                  <span id="metaSubMnuTable">
                        <xsl:apply-templates  select="root"/>
                  </span>
                  
            </xsl:template>
            <xsl:template match="root">
                        
                  <div id="metaCRDWmnu" class="SubMenu" onMouseOut="changeImages('meta','metaAdw')">
                        <xsl:for-each select="//metadata_detail[@mdo_type_cd='HELPRQST'] | //metadata_detail[@mdo_type_cd='HLPRQSTSRCH']">
                        <xsl:sort select="@mdo_nm"/>
                              <table cellpadding="2" cellspacing="0" border="0" width="240" class="SubMenu">
                                    
                                    <xsl:element name="a">    
        <xsl:choose>
            <xsl:when test="$metasecured = 'True'">                
            <a target="_blank">            
                <xsl:attribute name="href">CRMR/frame.asp</xsl:attribute>
                   <xsl:attribute name="onClick">javascript:window.open( this.href,'','width='+screen.width+',height='+screen.height+ ',top=0,left=0,resizable=yes,toolbar=yes,menubar=yes,status=yes,scrollbars=yes');return false;</xsl:attribute>
          </a>
            </xsl:when>
            <xsl:otherwise>
                              
                        
                                    
                                    
                                    <a target="_self">
                                          <xsl:attribute name="href">
                                                <xsl:for-each select=".">
                                                       <xsl:value-of select="@mdo_type_url" />
                                                </xsl:for-each>
                                          </xsl:attribute>
                                          <tr class="SubMenuItem" onMouseOver="this.style.color='#ffffff'" onMouseOut="this.style.color='#000000'">
                                                 <td class="SubMenuItem" id="metaCRDWmnuDrpDwn" style="cursor:hand; background-color:#FFFFFF" onMouseOver="stopAll();changeImages('meta','metaAdw');this.style.backgroundColor='#ff9900'" onMouseOut="closeAll();this.style.backgroundColor='#FFFFFF'">
                                                      <xsl:value-of select="@mdo_nm"/>
                                                </td>
                                          </tr>
                                    </a>
                              </table>
                        </xsl:for-each>
                  </div>
                  <div id="metaBusInfoMnu" class="SubMenu" onMouseOut="changeImages('meta','metaAdw')">
                        <xsl:for-each select="//metadata_detail[@mdo_type_cd='LOADSTATUS'] | //metadata_detail[@mdo_type_cd='KNWLGBASE'] | //metadata_detail[@mdo_type_cd='SRVLVLAGRMNTS'] | //metadata_detail[@mdo_type_cd='PRIORITYPRJCT'] | //metadata_detail[@mdo_type_cd='USRGRPREPRESNT'] | //metadata_detail[@mdo_type_cd='RECONRPTS']">
                        <xsl:sort select="@mdo_nm"/>
                              <table cellpadding="2" cellspacing="0" border="0" width="240" class="SubMenu">
                                    <a target="_self">
                                          <xsl:attribute name="href">
                                                <xsl:for-each select=".">
                                                      <xsl:value-of select="@mdo_type_url" />
                                                </xsl:for-each>
                                          </xsl:attribute>
                                          <tr class="SubMenuItem" onMouseOver="this.style.color='#ffffff'" onMouseOut="this.style.color='#000000'">
                                                 <td class="SubMenuItem" id="metaBusInfoMnuDrpDwn" style="cursor:hand; background-color:#FFFFFF" onMouseOver="stopAll();changeImages('meta','metaBusInfo');this.style.backgroundColor='#ff9900'" onMouseOut="closeAll();this.style.backgroundColor='#FFFFFF'">
                                                      <xsl:value-of select="@mdo_nm"/>
                                                </td>
                                          </tr>
                                    </a>
                              </table>
                        </xsl:for-each>
                  </div>
            </xsl:template>
            </xsl:stylesheet>
      </xml>
      <!-- End SubMenu -->


<table width="552px" cellpadding="0" cellspacing="0" border="0">      
      <tr>
                  <td><img src="../../images/spacer.gif" width="60"></img></td>
            </tr>
            
      <tr>
      <td class="mdi" colspan="2">
                        <p/>
      <%Response.Write rstWelcTo.Fields("mdi_txt")%>
            </td>
      </tr>
      
      
      <tr>
            <td style="height: 5px" colspan="2"><hr/></td>
      </tr>
      <tr>
            <td>       
                  <div style="clear:both; margin-top:15px; width:552px;">
                  <div class="mdi">
                    
                    <p><a href="xxxxxxx Access Request Procedures.doc" class="mdo" target="_blank">CRDW Access Request Procedures<span style="padding-left:3px"><img src="../../images/word.ico" border="0"/></span></a>
                  <br/>
                  Procedures on how to request access to the Central Region Data Warehouse (CRDW).</p>
                          
        <%if metasecured="True" then %>
                  <p><a href="TransformationLog/TL_LogSummary.asp" class="mdo" target="_blank">Log Summary</a><br />
                  View all Transformation Logs.</p>
                  <%end if%>
                                
                    <p><a href="DHR_SearchDHRs.asp" class="mdo">Search for a CRDW Help Request</a><br />
                     Search for a previous request by various criteria.</p>
                  
                  <%if metasecured="True" then %>
                  <p><a href="dhr_demo_new.asp" class="mdo" target="_blank">Submit a secure CRDW Help Request</a><br />
                  To submit a request/question to the CRDW Warehouse Team.</p>
                  <%end if%>
                  
                  <%if metasecured<>"True" then %>
                  <p><a href="DHR_SubmitRequest.asp" class="mdo">Submit a CRDW Help Request</a><br />
                  To submit a request/question to the CRDW Warehouse Team.</p>
                  <%end if%>
                  
            
                  
                  <%if metasecured="True" then %>
                  <a href="DHR_SearchDHRs.asp?rfr=secured" class="mdo">Update a CRDW Help Request</a>
                  <br />
                  Update a previously submitted Help Request.
                  <%end if%>

                  
                  </div>
            </td>
      </tr>
</table>
</body>
</html>

0
 
Geert BormansCommented:
well, you have a processor here
                    oTemplate.stylesheet = oDoc;
                    loProcessor = oTemplate.createProcessor();

add this line underneath it
loProcessor.addParameter("metasecured ", metasecured)

and make sure that metasecured has a value before you pass it

cheers
0
 
JA67Author Commented:

I sure hate taking so much of your time. Feel free to tell me to get lost. I will give you the points and close the question. If I had half a brain I could probably get this working with what you've given me so far...

Anyway, I have added the line, and I get an error, "The stylesheet does not contain a document element." It refers to line 26. I did a view source (since this is not an ASP error. At least I don' think it is, because it's a pop up message.) and line 26 is this:

      oDoc.load(oSrc);

0
 
JA67Author Commented:
FYI: I am logged in, and therefore metasecured should have the value of true.
0
 
JA67Author Commented:
FYI:  I had the code like this:

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:msxsl="urn:schemas-microsoft-com:xslt" version="1.0">
<xsl:param name="metasecured" />
oProc.addParameter("metasecured ", metasecured)

But I figured I should probably remove the oProc.addParameter line, since you had me put it elsewhere. I removed it as a test, and I still get the same error. I am going to leave it out however, unless you tell me it should be there. I am understanding though that we moved this line, so I will leave it out of this location...
0
 
Geert BormansCommented:
> Feel free to tell me to get lost

Get Lost!
No, sorry, I could not resist the joke.
Don't worry, we ll get this working

> oDoc.load(oSrc);
well, I would not do it the way you do this.
I am not sure how you can load the XSLT from within the ASP
(can be allowed, but I don't know how this works)

I always make my XSLT a seperate file
The error message you get is that oDoc.load expects a XML document and it is not getting that
At least make sure it loads it from the page
or make the XSLT a seperate file and load the file

you have to remove the oProc.addParameter line,

cheers

Geert

0
 
JA67Author Commented:

I appreciate it Gertone. Maybe this explanation will help. The XML for this page is contained in a data island. The data island is generated/referened on the ASP page in the lines below. I use the resulting XML to drive submenus that I display when mousing over various image maps. What I want to do, from within the XSLT, is detect when the ASP session variable is present, and when it is present, I want to hard code the URL of one of the drop down links, instead of using the values that are in the XML from the XML data island. Does this give you any ideas?

Thank you!
JA67

<div id="divMetaSubMnu"></div>
<xml id="xmlMetaSubMnu" src="../../metaSubMenuObject.asp?strSQL=exec mdo_ownr_sp 507,OWNCTNMETACRDW"/>
<xml id="metaSubMnu_xsl">

0
 
JA67Author Commented:
Hope you're OK Gertone. I have not heard back from you on this in a long while. Thanks for your help anyway. I'll just close the question.

JA67
0
 
Geert BormansCommented:
JA67,

sorry for leaving this question a while, I took some holidays and that created a bit of a  backlog.

the error surely means the XSLT can't get loaded...
I have not much experience loading XSLTs from within the document.
Is there a reason why you don't want the XSLT in a seperate file?
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

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

  • 7
  • 5
Tackle projects and never again get stuck behind a technical roadblock.
Join Now