With ThePort’s platform, our customers are able to customize their site to meet their needs in numerous ways. But how are we able to do that? Because we are SaaS, we’re unable to build custom sites for each individual customer. Instead, we’ve taken advantage of XML and its sister language, XSLT, to build a robust and dynamic Template system.
The first and most fundamental part of our Template system is XML. We take advantage of the fact that all of our data is represented in the form of XML business objects. That is, every user, customer, event, and social space, can be serialized into XML. Since .NET exposes a number of built-in serialize routines, and makes it extremely simple to tailor the schema of these objects, it was a no-brainer for us to make XML serialization a base part of our core framework.
Secondly, and certainly the most important part, is XSLT. XSLT is a style language that allows us to take basic XML and mark it up into HTML so it can be served over the web. While XSLT isn’t a fully formed OO language, it offers all of the basic constructs necessary to create living breathing webpages: variables, conditionals, loops, etc. Now to really make this whole thing work, we used a seldom used part of XSLT called “XSLT Extension Objects”. This is something that allows us, from the XSLT, to call back into our codebase. All we have to do is expose a method in an object, and then pass that object into the transform. Then, with a little import style code at the top of the XSLT, we have access to that object and all of its publicly exposed methods. We can use this to call into our database or make utility calls.
So how we do marry the two, XML and XSLT? Let’s take for example a simple module on a page: Latest Members. The Latest Members module is one of our most commonly used call-outs on our community page. It does exactly what you may think it does: it shows the latest 5 (or 10, or 15…) members who have joined the community.
When a page loads that contains this module, we use an XSLT extension method (described above) called “ProcessServerModule” that tells the XSLT page to go off and grab a certain subset of data (in this case, LatestMembers). I’ll skip our data access and caching methodologies (blog entries for another day) but suffice to say that this ProcesServerModule call will return an XPathNavigator that contains the relevant data needed to display this data: the 10 users we want to display, including their data (ID, Name, ProfileImage, etc). This data is typically enough to display what we want. However, if we wanted to, we could take another extension method “GetUser” and instantiate one of our User objects. This would give us another XPathNavigator with a lot more information about the user.
Now that we have these navigator objects, what do we do? From here, it’s pretty simple. We loop through the object in XSLT and display the data however we see fit using standard HTML / CSS / JavaScript.
More on the modules, schemas, and other XSLT goodies
here.