Comments
Richard Davies wrote: The UK has a good crop of technology pioneers in cloud computing - for example ElasticHosts, FlexiScale, Flexiant, OnApp - and also some strong government initiatives such as G-Cloud. We will have to see whether this kind of technical leadership converts into swift mass-market adoption or not.
Cloud Expo on Google News

SYS-CON.TV
Cloud Expo & Virtualization 2009 East
PLATINUM SPONSORS:
IBM
Smarter Business Solutions Through Dynamic Infrastructure
IBM
Smarter Insights: How the CIO Becomes a Hero Again
Microsoft
Windows Azure
GOLD SPONSORS:
Appsense
Why VDI?
CA
Maximizing the Business Value of Virtualization in Enterprise and Cloud Computing Environments
ExactTarget
Messaging in the Cloud - Email, SMS and Voice
Freedom OSS
Stairway to the Cloud
Sun
Sun's Incubation Platform: Helping Startups Serve the Enterprise
POWER PANELS:
Cloud Computing & Enterprise IT: Cost & Operational Benefits
How and Why is a Flexible IT Infrastructure the Key To the Future?
Click For 2008 West
Event Webcasts
Got XSLT?
Got XSLT?

XSLT is a powerful technology that can provide many benefits. In this tutorial we examine how you can use XSLT to transform an XML example to the WML (Wireless Markup Language) that
WAP (Wireless Application Protocol) devices such as
PDAs - Palm Pilots, digital cell phones, pagers - use or understand.

In Part 1 of this series (Vol. 2, issue 10) we briefly discussed how to transform our XML document into HTML by using Microsoft's Internet Explorer (MSXML parser 2.0). We were able to do this because IE 5.0 is more than just an XML parser - it's also an XSLT processor. This kind of transformation is sometimes called client-side transformation,
that is, the client (IE 5.0) performed the transformation.

In the case of WAP, the WAP devices can't perform the transformation since they're typically "dump" devices with limited processing power and memory (at least for the time being). Therefore, in a real-world case, the transformation is most often performed on the server side.
In other words, the Web server transforms the XML document into WML.

This tutorial requires the following software:

  • LotusXSL from
    www.alphaworks.ibm.com/tech/LotusXSL
  • Openwave UP.SDK, release 4.0 or 4.1, from
    http://developer.openwave.com/

  • JDK 1.2 or 1.3 from www.javasoft.com (I assume you've already installed JVM on your machine)

    LotusXSL implements an XSL processor in Java that can be used from the command line, in an applet or a servlet, or as a module in other programs. By default, it uses the XML4J XML parser (available as a xerces.jar file when you download LotusXSL) using xerces, but it can interface to any XML parser that conforms to the DOM level 2 or SAX level 1 specification. The freely available LotusXSL used to be a tool developed by alphaWorks, but has now been donated to the Apache project, which maintains it under the name Xalan. LotusXSL is a version (or distribution) of Xalan that has been tested and approved by IBM alphaWorks.

    Openwave's software developer kit, UP.SDK, is the leading solution for creating WAP 1.1-compatible Internet services and applications for wireless handsets. The freely available UP.SDK contains the tools and interfaces necessary for a developer to create innovative applications for the wireless Internet.

    UP.SDK includes the robust UP.Simulator software, available for Windows platforms and designed to accurately simulate the behavior of a variety of Internet-enabled handsets.

    Finally, you need a JVM since LotusXSL is a Java implementation of the XSL engine and needs a container to run.

    * * *

    The primary purpose of this tutorial is to introduce you to the following concepts:

    • Transforming an XML document into WML
    • Using XSLT, XML, and WML
    What Is WAP?
    WAP - Wireless Application Protocol - is the leading standard for information services on wireless terminals like digital mobile phones. The WAP standard is based on Internet standards (HTML, XML ,and TCP/IP). It consists of a WML language specification, a WMLScript specification, and a Wireless Telephony Application Interface (WTAI) specification.

    WAP is published by the WAP Forum, founded in 1997 by Ericsson, Motorola, Nokia, and Unwired Planet. Forum members now represent over 90% of the global handset market, as well as leading infrastructure providers, software developers, and other organizations.

    What Is WML?
    WML - Wireless Markup Language - is a markup language inherited from HTML, but it's based on XML, so it's much stricter than HTML.

    WML is used to create pages that can be displayed in a WAP browser. Pages in WML are called decks, which are constructed as a set of cards. WML is mostly about text. Tags that would slow down the communication with handheld devices are not a part of the WML standard, and the use of tables and images is strongly restricted.

    Since WML is an XML application, all tags are case sensitive (<wml> isn't the same as <WML>), and all tags must be properly closed.

    When a WML page is accessed from a mobile phone, all the cards in the page are downloaded from the WAP server. Navigation between the cards is done by the phone computer (inside the phone) without any extra access trips to the server. See the Resources section for more information about WAP and WML.

    Okay, enough theory stuff...let's gets started!

    Recalling Our XML Document
    I hope you still remember our XML example (mybooks.xml). To refresh your memory, Listing 1 depicts our XML file. As explained in my previous article, you're free to modify your XML document any way you like, but you'll then have to pay extra attention to some of the details when we get into creating our WML stylesheet.

    Note that we won't reference any XSL stylesheet onto our XML document. This is because we'll explicitly plug in our WML, XSL, and XML documents to perform the translation from a command line.

    Our goal is to produce a WML page that looks like Figure 1, using UP.SDK simulator software.

    Creating the Stylesheet Document
    Let's see how we can devise a stylesheet to display the mybooks.xml document nicely on a WML browser. Listing 2 shows a complete XSL file to render our XML file (mybooks.xml) into a WML page. As you can see, it's a bit more complex than our previous XSL document.

    Understanding the WML Stylesheet
    Let's now take a closer look at our mybooks_wml.xsl stylesheet. The second line of the XSLT stylesheet is:

    <xsl:stylesheet version="1.0" xmlns:xsl=
    "http://www.w3.org/1999/XSL/Transform">
    Here we define the namespace for the XSL stylesheet with the <xsl:stylesheet> element. Note that we use the new W3C XSLT recommendation, which requires an additional attribute named version to be included. In the previous article we used MSXML 2.0, which is not 100% compatible with this recommendation, so we use the following line instead:

    <xsl:stylesheet xmlns:xsl=
    "http://www.w3.org/TR/WD-xsl">
    The <xsl:output> specifies options for use in serializing the result tree. In this case we output nicely indented XML:

    <xsl:output method=
    "xml" indent="yes"/>
    The <xsl:template> element:

    <xsl:template match="/">
    is used as a template to match against the source XML document. This is a template that corresponds to the root (/) of the XML source document.

    Now we begin to construct the body of our WML page using <wml> tags:

    <wml>
    <xsl:apply-templates select="//ITEM" />
    </wml>
    The <xsl:apply-templates> element first selects a set of nodes using the query specified in the select attribute. If this attribute is left unspecified, all children of the current node are selected. For each of the selected nodes, <xsl:apply-templates> directs the XSLT processor to find an appropriate <xsl:template> to apply. In our case the XSLT processor will apply all ITEM templates (see Listing 3).

    Now we'll start to define those ITEM templates. The <xsl:element> element allows an element to be created with a computed name. The name of the element to be created is specified by a required name attribute (card) and an optional namespace attribute. In other words, this creates the <card> element with attributes id="Book<xsl:number/> and title="My Book Catalog". The element <xsl:number/> is an empty element and serves as a counter.

    Similarly, we created the element <do> with the attribute type="accept" and the label="Next Book".

    The last element we created is <go> with the attribute name href="#Book<xsl:number value="position() + 1". This translates to #Book2 (since the position of this template is 1).

    We close the card and do elements.

    The XSL <xsl:value-of> element can be used to select the value of the element matched by the select predicate.

    The XSL stylesheet then closes all open element tags in order, with no nesting allowed.

    Listing 4 is the second half of our stylesheet.

    The XSL <xsl:template match="ITEM[position() = last()]"> checks for the last ITEM element in our XML document. If it actually is the last element, the XSLT processor will continue with the next line; otherwise it will skip and apply <xsl:template match="ITEM"> again. The rest is pretty simple, except for element go attribute <xsl:attribute name="href">#Book<xsl:numbervalue="count(//ITEM) - count(//ITEM) + 1"/></xsl:attribute>.

    The XSLT count() function returns the number of nodes in the argument node-set. In our example it returns three (since there are only three books in our XML document). Thus the result is an attribute value of #Book1, which forces the WML browser (or our WAP simulator) to go back to the Book1 card.

    I'm sure there are several other and possibly easier ways to create this behavior using other XSLT functions, but I'll leave this as an exercise for the reader.

    Performing Your Own Transformations
    Both Xalan (LotusXSL) and UP.SDK have an HTML start-up page: readme.html (make sure to read the getting-started link) and upsdk40.html, respectively. They will show you how to set your classpath for the Xalan processor. At a minimum, you must include xalan.jar and xerces.jar on your system class path to perform the translation.

    Java.org.apache.xalan.xslt.Process provides a basic utility for performing transformations from the command line. The command line for most standard transformations is as follows:

    java org.apache.xalan.xslt.Process -
    in xmlSource -xsl stylesheet -
    out outputfile
    where xmlSource is the XML source file name, stylesheet is the XSL stylesheet file name, and outputfile is the output file name. If you want the output to be displayed onscreen, simply omit the -out flag and argument.

    Both mybooks_.xml and mybooks_wml.xsl are saved under gotxslt directory as d:\gotxslt\*.*

    To perform the translation, type the following:

    D:\>cd gotxslt
    D:\gotxslt>java
    org.apache.xalan.xslt.Process -in
    mybooks.xml -xsl mybooks_wml.xsl
    -out mybooks.wml
    If all goes well, the new output file mybooks.wml will be the resultant output from the XML to WML translation (see Figure 2). The file mybooks.wml is a pure WML ASCII file, so you can open it and study it in any text editor.

    Testing the Deck In order to test our WML output file, you need to start the UP.Simulator program (upsim.exe) and type the URL of your file (in this case file://d:/gotxsl/mybooks.wml) in the Go field and press Enter. The results of a successful request are shown in Figure 3:

    Upon clicking the Next button (which is just below the text labeled "Next Book"), a second card will display the second book. Clicking again for our third book, you'll see that this time the label shows "Back" (see right-hand picture in Figure 3). Clicking on the Next button again will take you to our first book, and the loop will continue.

    Conclusion
    This article has shown a way to use XML and XSL transformation to create a WAP-compatible WML file. We've just scratched the surface of the potential of WAP/WML. XSLT is a powerful technology that can provide many benefits and hopefully you'll now feel confident to play with other examples on your own.

    In Part 3 we'll translate our XML file into VoiceXML.

    Resources

    About Shouki Souri
    Shouki Souri is a lead Software Engineer at PanAmSat Corporation. He has several years of experience working with Java, CORBA, XML/XSL, C/C++ and other technologies. He holds a bachelor’s degree in Electrical Engineering and a master’s degree in Computer Science..

  • In order to post a comment you need to be registered and logged in.

    Register | Sign-in

    Reader Feedback: Page 1 of 1

    Good article and easy to follow but Listing 2 has errors in it. Every instance of "ITEM" should be replaced with "BOOK". There are 5 occurrences.


    Your Feedback
    Orion wrote: Good article and easy to follow but Listing 2 has errors in it. Every instance of "ITEM" should be replaced with "BOOK". There are 5 occurrences.
    Latest Cloud Developer Stories
    Swisscom, the Swiss telecom, is going into the cloud business. Its subsidiary Swisscom IT Services AG has signed up with Red Hat as a Certified Cloud Provider and launched a public cloud Infrastructure-as-a-Service (IaaS) cloud targeting enterprise-class customers primarily in ...
    Apache Deltacloud, the Red Hat-contributed ReSTful API that abstracts differences between clouds so services on any cloud can be managed – provided of course there’s a driver – has graduated from the Apache Foundation’s incubator and is now a full-fledged Top-Level Project (TLP)....
    In a surprise move on Tuesday, January 10, Oracle wheeled out its Big Data Appliance. That’s the one it said in October would be ready sometime in the first half. Only nobody believed it meant early in the first half. Heck, it’s not even clear anybody thought Oracle could make ...
    Rackspace Hosting, the service leader in cloud computing, on Thursday announced its acquisition of SharePoint911, an industry leader in SharePoint consulting, training, and "JumpStart" services within SharePoint. The unification of both companies provides capabilities to deliver ...
    CloudLinux, Inc., on Thursday released CafeFS 3, a virtualized file system for shared hosters that cages each customer within its own virtualized file system. CageFS becomes part of CloudLinux OS at no additional charge. CloudLinux OS, the only commercially-supported Linux OS m...
    Subscribe to the World's Most Powerful Newsletters
    Subscribe to Our Rss Feeds & Get Your SYS-CON News Live!
    Click to Add our RSS Feeds to the Service of Your Choice:
    Google Reader or Homepage Add to My Yahoo! Subscribe with Bloglines Subscribe in NewsGator Online
    myFeedster Add to My AOL Subscribe in Rojo Add 'Hugg' to Newsburst from CNET News.com Kinja Digest View Additional SYS-CON Feeds
    Publish Your Article! Please send it to editorial(at)sys-con.com!

    Advertise on this site! Contact advertising(at)sys-con.com! 201 802-3021

    SYS-CON Featured Whitepapers
    ADS BY GOOGLE

    Breaking Cloud Computing News

    BEACHWOOD, Ohio, Feb. 16, 2012 /PRNewswire/ -- DDR Corp. (NYSE: DDR) today announced operating re...