Geeks With Blogs
I'd rather be writing low-level stuff... ...but .NET pays the bills
| Home |
Having had my brush with SharePoint and its intricacies, and after learning that its original iteration was classic ASP flavored with Javascript and XML, I became intrigued about re-usable web components and how I could go about creating my own.

I decided not to bother with .NET, as this was just a little experiment designed to get me into coding-for-fun once again. I decided to go classic ASP with a sprinkling of Javascript and XML and a whole lot of XSLT.

My project was a webpart-enabled web portal that would be hosted on my own PC.  Now browser bookmarks and Live Bookmarks do their thing, but sometimes I like my links arranged just so. My wife is an avid fan of television series, so I wanted to make her a list of her favorite Wikipedia links to keep her updated on the latest episodes of Supernatural or Desperate Housewives.

 I also run a lot of searches on different search engines, so I wanted a re-usable widget that would emit the HTML I needed to post a search query  to a search engine.

Finally I was starting to subscribe via RSS to news sites and I wanted them on the first page I load into when I launch FireFox.

Getting started

My data was to be stored in XML, with XSLT used to shape the data into the final output. 

I wrote a small function to read the XML and apply the XSLT, all very very simple:

' used to inject parameters into XSL
public sub insert_node(target, nodename, nodevalue)

    set newvar = target.createNode(1, "xsl:variable", "http://www.w3.org/1999/XSL/Transform")
    newvar.setAttribute "name", nodename
    set newvalue = target.CreateTextNode(nodevalue)
    newvar.appendChild newValue
    target.childNodes(0).insertBefore newvar, target.childNodes(0).childNodes(1)
end sub

public function create_webpart(name, webparttype, datasrc, stylesrc, configsrc, params)
    Dim document, stylesheet
    Set document = Server.CreateObject("Msxml2.DOMDocument")
    document.async = False
    document.load Server.MapPath(datasrc)
   
    Set stylesheet = Server.CreateObject("Msxml2.DOMDocument")
    stylesheet.async = False
    stylesheet.load Server.MapPath(stylesrc)

    insert_node stylesheet, "name", name
    insert_node stylesheet, "webparttype", webparttype
    insert_node stylesheet, "datasource", datasrc
   
    a = split(params,";")
    for each b in a
        c = split(b, "=")
        insert_node stylesheet, c(0), c(1)
    next
       
    Response.Write document.transformNode(stylesheet)
   
    Set document = Nothing
    Set stylesheet = Nothing   

end function

That's in a separate asp file, INC'd into the host page, that would then be called within said page like so:

<% create_webpart webpart_name, webpart_type, xml_data_src, xsl_style_src, configuration_src, params %>

There it is, your basic webpart.  Granted, it doesn't look as elegant as <MyAssembly:MyWebpart .../> but then it also stripped-down, bare-naked, sleek and sexy.

So it's mostly JavaScript and XSLT powering the site.

Here's a few screenshots of the output.  Visually, the portal isn't too design-savvy as I have never been too much into design (thank goodness for blog sites and templates).

Links list webpart

RSS webpart

WebSearch webpart

 

Posted on Tuesday, July 21, 2009 11:01 AM | Back to top


Comments on this post: Back to the Basics - part 1

No comments posted yet.
Your comment:
 (will show your gravatar)


Copyright © EnderSoft | Powered by: GeeksWithBlogs.net