Proceed to WirelessDevNet Home Page
Publications, e-books, and more! Community Tutorials Store Downloads, tools, & Freebies! IT Career Center News Home
newnav.gif

Newsletters
EMail Address:



   Content
  - Articles
  - Columns
  - Training
  - Library
  - Glossary
 
   Career Center
  - Career Center Home
  - View Jobs
  - Post A Job
  - Resumes/CVs
  - Resource Center
 
   Marketplace
  - Marketplace Home
  - Software Products
  - Wireless Market Data
  - Technical Books
 
   News
  - Daily News
  - Submit News
  - Events Calendar
  - Unsubscribe
  - Delivery Options
 
   Community
  - Discussion Boards
  - Mailing List
  - Mailing List Archives
 
   About Us
  - About WirelessDevNet
  - Wireless Source Disks
  - Partners
  - About MindSites Group
  - Advertising Information
 
INDEX
>Introduction
>Dissecting The ASP Document
>Dissecting The XSL Stylesheet
>Conclusion

Transforming XML into WML

by Wei Meng LEE

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.

<?xml version='1.0'?> <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0"> <xsl:output omit-xml-declaration="yes"/> <xsl:template match="/"> <wml> <card id="card1" title="Courses"> <p> <b>Course Title: </b><xsl:value-of select="Course/Title" /><br/> <b>Synopsis: </b><i><xsl:value-of select="Course/Synopsis" /></i><br/> <b>Duration: </b><xsl:value-of select="(Course/Duration) div 8"/> days <br/> <b>Fees: </b>S$$<xsl:value-of select="Course/Fees" /><br/> <b>Dates:</b><br/> <xsl:for-each select="Course/CourseDates/Date[Day!='']" > <xsl:value-of select="Day"/>/<xsl:value-of select="Month"/>/<xsl:value-of select="Year"/> From <xsl:value-of select="Time/From"/>hrs to <xsl:value-of select="Time/To" />hrs @ <xsl:value-of select="Venue"/> - <xsl:value-of select="(/Course/Duration) div (((Time/To) - (Time/From)) div 100)"/> <xsl:value-of select="Mode" /> <br/> </xsl:for-each> </p> </card> </wml> </xsl:template> </xsl:stylesheet>

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 <?xml version='1.0'?> Response.Write "<!DOCTYPE wml PUBLIC ""-//WAPFORUM//DTD " & _ "WML 1.1//EN"" ""http://www.wapforum.org/DTD/wml_1.1.xml"">" '---Performs the transformation--- Response.write (xml.transformNode(xsl)) %>

To view the above document in a WAP device, simply key in the URL:

http://localhost/Courses.asp

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:

Next: Dissecting The ASP Document

Sponsors

Search

Eliminate irrelevant hits with our industry-specific search engine!









Wireless Developer Network - A MindSites Group Trade Community
Copyright© 2000-2010 MindSites Group / Privacy Policy
Send Comments to:
feedback@wirelessdevnet.com