Introduction
In a previous article, we made our initial foray into XSLT and XPath, finishing with an example that
demonstrated the transformation of XML into HTML. Now that we have seen the stylesheet for transforming XML into HTML, we can
now look at how we can transform XML into WML.
Looking at the stylesheet below, you can see that it is quite similar to the stylesheet for transforming
to HTML. Before we look into the differences, let's see how this stylesheet can be applied to the XML document.
|
Course Title:
Synopsis:
Duration: days
Fees: S$$
Dates:
//
From hrs to hrs
@ -
|
Recall that the earlier example performs the transformation on the client-side? That is, the web browser,
IE5, performed the transformation. In the case of WAP, it is not possible for the WAP device to perform the
transformation since they are typically "dumb" devices with limited processing power (at least for the moment).
What we need to do here is to perform the transformation on the server-side. In other words, the web server
will transform the XML document into WML.
To do that, we will make use of the Microsoft Active Server Pages (ASP) technology
and the Microsoft Document Object Model (DOM) to do the transformation:
|
<%
'---Create an instance of the DOM object---
Set xml = Server.CreateObject("MSXML2.DOMDocument")
'---Let it run synchronously---
xml.async = false
'---Load the XML document---
xml.load (Server.MapPath("XMLCourse.xml"))
Set xsl = Server.CreateObject("MSXML2.DOMDocument")
xsl.async = false
'---Load the XSLT stylesheet---
xsl.load (Server.MapPath("WML.xsl"))
'---Set the MIME type---
Response.ContentType = "text/vnd.wap.wml"
'---Send the WML prologue---
Response.Write
Response.Write ""
'---Performs the transformation---
Response.write (xml.transformNode(xsl))
%>
|
To view the above document in a WAP device, simply key in the URL:
You would need a web server and a WAP emulator to try this example. Here I am using the Microsoft IIS 4.0 and UP.Simulator by Phone.com: