John Sands' Radio Weblog :
Updated: 9/19/2002; 12:09:06 PM.

 

 
 

Click to see the XML version of this web page.

Click here to send an email to the editor of this weblog.

 
 

Wednesday, June 05, 2002

A moment of XSLT clarity from the most incredibly useful mailing list I've ever used:
 
> I understand that the value of a variable cannot be modified 
> once it has been assigned, but is it possible to allocate a 
> global variable at the start of a stylesheet and then assign 
> it a value at a later time, such as within a named template?
 
No, it isn't possible. You need to stop thinking sequentially. 
There is no such thing as "a later time" in XSLT.

Michael Kay


9:24:05 PM    

Including the same JavaScript file on the client and the server

I've often been frustrated that there is no simple way to include a file of JavaScript functions on the server (ASP) and the client (the browser). I have a whole library of functions that convert, format, process and otherwise stretch and squeeze dates, strings, and xml documents. I keep copying code from a server-only file to a client-only file or vice versa. So today I finally fixed the problem by writing a function (to be executed on the server) that reads the file, chops off the silly <% and %> that the ASP include insists on, and writes it into the page. It's just:

function convert_to_client(filename) {
  var fso = Server.CreateObject("Scripting.FileSystemObject");
  var ts = fso.OpenTextFile(filename, 1);	//ForReading
  Response.Write("<script language='javascript'>");
  var code = ts.ReadAll();
  Response.Write(code.substring(code.indexOf("%")+1, code.lastIndexOf("%")));
  Response.Write("</script>");
}
My test ASP is like this (the convert_to_client function is in script_converter.js):
<%@language="javascript" %>
<!-- #include file = "test.js" -->
<!-- #include file = "script_converter.js" -->
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html>
  <head>
    <% Response.Write(convert_to_client(Server.MapPath("test.js"))); %>
    <script language="javascript">
        function runtest() {
          client.innerText = test("from the client");
        }
    </script>
  </head>
  <body onload="runtest();">
    server: <% Response.Write(test("from the server")); %>
    <hr/>
    client: <span id="client"></span>
  </body>
</html>
Notice that test.js is included on the server, and also passed to the convert_to_client function to be written to the page so that it is available on the client. The test.js file is just this:
<%
function test(parm) {
  return parm;
}
%>
The output when the test ASP page executes is:
server: from the server 
--------------------------------------------------------------------------------
client: from the client

4:54:19 PM    

A good article (as usual) from Zeldman on DOCTYPES. In case anyone else uses UltraEdit, here's my taglist for all seven doctypes (remove the linebreaks when you paste it into your taglist.txt):
[Tag Group - DOCTYPES]
0="HTML 4.01 Strict :UEDS:<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" 
 "http://www.w3.org/TR/html4/strict.dtd"> ... "
1="HTML 4.01 Transitional :UEDS:<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" 
 "http://www.w3.org/TR/html4/loose.dtd"> ... "
2="HTML 4.01 Frameset :UEDS:<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Frameset//EN" 
 "http://www.w3.org/TR/html4/frameset.dtd"> ... "
3="XHTML 1.0 Strict :UEDS:<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" 
 "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> ... "
4="XHTML 1.0 Transitional :UEDS:<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
 "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> ... "
5="XHTML 1.0 Frameset :UEDS:<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Frameset//EN" 
 "http://www.w3.org/TR/xhtml1/DTD/xhtml1-frameset.dtd"> ... "
6="XHTML 1.1 DTD :UEDS:<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" 
 "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd"> ... "
7=

8:19:57 AM    


© Copyright 2002 John Sands.



Click here to visit the Radio UserLand website.

 


June 2002
Sun Mon Tue Wed Thu Fri Sat
            1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30            
May   Jul

PicoSearch
blogchalk: John/Male/46-50. Lives in United States/Palm Bay/Lockmar and speaks English. Spends 80% of daytime online. Uses a Faster (1M+) connection.