From an XSL file, what is the best way to process a cookie?

Discussion in 'XML' started by slacker, May 30, 2006.

  1. slacker

    slacker Guest

    By clicking a link on a website I set a USERINFO cookie and then I
    redirect to a program which ultimately executes an XSL file which
    dynamically builds an input form. The input form, while having some non

    dynamic hidden INPUT tags, has one hidden INPUT tag that is dynamic. In

    the XSL file I attempt to bring this dynamic hidden INPUT tag in via
    the following statements:

    <xsl:template match="/">
    <xsl:value-of select="document('http://localhost/getcookie.jsp')"/>

    </xsl:template>

    Unfortunately, the XSLT processor produces the following errors:

    obhtmlpage.cpp:146: Error: Exception rethrown in
    ObHTMLPage::GenerateHTML.
    obdgxtxsl.cpp:213: Error: ObDgxtTransform
    obdgxtxsl.cpp:153: Error: ObCallDgxtTransform
    obdgxtxsl.cpp:32: Error: 0: syntax error at line 1, col 49: syntax
    error
    obdgxtxsl.cpp:32: Error: 0: xpl_document: error parsing
    http://localhost/getcookie.jsp


    Below is the getcookie.jsp. I thought I was being straight forward with

    this. But I'm confused as to what the processor is talking about; the
    XSL above or the JSP below? What does it mean line 1 column 49? Any and

    all help is appreciated, thanks.

    P.S. - I know I removed " + cookievalue + " below in lieu of the non
    dynamic which you see, but even that failed. :-( I also tried
    xsl:copy-to and import with this fixed code, but to no avail. Again,
    any and all help is appreciated.


    <%@ page import="javax.servlet.http.Cookie"
    %><%


    Cookie info = null;
    Cookie[] cookies = request.getCookies();
    for (int i=0; i < cookies.length; i++) {
    info = cookies;
    String cookiename = info.getName();
    String cookievalue = info.getValue();
    if (cookiename.equals("USERINFO")) {
    %>
    <input type="hidden" name="varuserinfo" id="varuserinfo"
    value="cookievalue"></input>
    <% }
    }
    %>

    I'm not really fluent in XML/XSL/XSLT but need to come up with a way
    of removing
    a set of radio buttons on an XSL produced form. I thought, good, I'll
    set a cookie and somehow use that value in the value clause of a hidden
    HTML INPUT tag. Hence the so
    called "dynamically" generated HTML tag which I tought would be
    considered well formed because I gave it an ending INPUT tag.

    I also thought initially that maybe I could just have a javascript
    extract the cookie value via an ONLOAD statement in a BODY tag, but
    then I couldn't figure out the XSL like syntax I would need to make use

    of this javascript variable. So more poking around on the internet led
    me to the XSL:value-of statement below and copy-of and import
    statements with the document parameter and I thought, okay, this looks
    promising. But no such luck.

    Nelson
    slacker, May 30, 2006
    #1
    1. Advertising

  2. slacker

    slacker Guest

    This is what I had tried the Javascript way which also doesn't seem to
    work.
    The XSL file has:

    <xsl:stylesheet version="1.0"
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    xmlns:eek:blix="http://www.oblix.com/">

    ....

    <script language="JavaScript" xml:space="preserve"
    src="../../common/bin/functions.js"></script>

    ....

    <xsl:variable name="cookie"
    select="cookie:getUserInfo()"></xsl:variable>

    (The transformer barfs on the above, but loves everything else about
    the XSl file if I comment out the above).

    ....

    <xsl:if test="@cookie = 'uservalue'">
    <input type="hidden" name="userinfo" id="userinfo" value="uservalue"/>
    </xsl:if>

    ....

    and the javascript which returns the cookie looks like this:

    function getUserInfo() {
    var arrayofcookies = document.cookie.split(";");

    var i = 0;
    var userinfo = "USERINFO";
    var nocookie = 1; // Set for later
    //document.write(arrayofcookies.length);
    while (i<arrayofcookies.length)
    {

    //Split the current cookie into name=pairs.
    //Index 0 should be the name, and Index 1
    //should be the value.

    var cookiename = arrayofcookies.split("=")[0];
    var cookievalue = arrayofcookies.split("=")[1];

    if (cookiename == userinfo)
    {
    nocookie = 0;
    return(cookievalue);
    // userrole.setAttribute("select",""+cookievalue+"");
    }
    i = i + 1;

    }

    Any and all help is appreciated.

    Nelson
    slacker, May 31, 2006
    #2
    1. Advertising

  3. slacker wrote:
    > <xsl:variable name="cookie"
    > select="cookie:getUserInfo()"></xsl:variable>


    Did you define the cookie: namespace for that extension function
    invocation? Correctly?
    Joe Kesselman, May 31, 2006
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. =?Utf-8?B?UGF1bA==?=

    Cookie Question (IP as domain and cookie file location)

    =?Utf-8?B?UGF1bA==?=, Jan 10, 2006, in forum: ASP .Net
    Replies:
    1
    Views:
    2,471
    Bruce Barker
    Jan 10, 2006
  2. Me
    Replies:
    3
    Views:
    425
    shriop
    Jan 31, 2006
  3. Matt

    Best way to debug XSL?

    Matt, Oct 12, 2004, in forum: XML
    Replies:
    2
    Views:
    499
    Arto Viitanen
    Oct 15, 2004
  4. Replies:
    1
    Views:
    3,595
    A. Bolmarcich
    May 27, 2005
  5. Xeno Campanoli
    Replies:
    2
    Views:
    136
    Xeno Campanoli
    Jul 10, 2008
Loading...

Share This Page