I want to access the cookie (basically document.cookie from javascript)
from inside XSL document, something similer to the sample shown below
and I want to support both IE and Netscape.
XML:
<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet href="test.xsl" type="text/xsl"?>
<ABC></ABC>
XSL:
<?xml version="1.0"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:msxsl="urn:schemas-microsoft-com:xslt"
xmlns:funcs="some:unique:uri">
<msxsl:script language="JavaScript" implements-prefix="funcs" >
<![CDATA[
function MyFunc() {
return "read cookie and return data from cookie";
}
]]>
</msxsl:script>
<xsl:template match="/ABC">
<html>
<body>
<p><xsl:value-of select="funcs:MyFunc()"/></p>
</body>
</html>
</xsl:template>
</xsl:stylesheet>
Thanks in advance.
Sanjay
You might be overcooking this a bit - why not just put in your HTML
something like the following...
<html>
<head>
<script type="text/js" language="javascript" src="remote path to
file.js"/>
<head>
<body>
<p><script>document.write(myFunc())</script></p>
</body>
</html>
This is all legitimate from an XHTML point of view, it is portable as
it means you can use standard ECMA 1.2 or something like that in your
javascript and it will make your XSL LOADS more readable....
I know you can do it this way but I reckon long term your code will be
more maintainable the other way....
Cheers
AndrewF
I tried this but seems that XSL does not like this. Actually it will
work inside the <xsl:template>. But I need it at the top level at the
global section.
Basically I have to set a global variable (currently I am using
<xsl:param>) with the value from cookie.
Thanks
-Sanjay
I'm not sure exactly how to do it using MSXML from within javascript
but I know for example within .NET you create an XslArgumentList
object, add the parameters in [which could be determined by a cookie
for example] and then when you do the translation it automatically
provides the info to the XSL template....
Cheers
Andrew
If you are using CGI as the means then why not create an XSL file which
in iteself is a template. Make the XSL valid in that in the parameter
value you put in someting like <xsl:param name="thename">[COOKIE VALUE
HERE]</xsl:param>
Then what you do is load up the XSL file as a normal file read into
memory. Pull the cookie value from the HTTP headers passed in the
request, replace the bit of text [COOKIE VALUE HERE] and then load the
XSL document from memory as a string rather than as a file...
That should work and you have sidestepped the parameter issue by making
it the default value in the document anyway.
Cheers
Andrew
Thanks Andrew for your help.