XML & CSS

Newsflash — Microsoft has a new example online. List of examples:

  1. A simple XSL transformation for contacts
  2. Posting XML to the server
  3. Applying CSS stylesheets (“themes”)

Example 1: A simple XSL transformation for contacts

This example was constructed in December 2000. I was annoyed with the lack of documentation for XML support on the Pocket PC (Compaq iPAQ). References about support (DOM, data islands etc.) seemed to contradict each other. Even the references at Microsoft Pocket PC and MSDN are far from complete. I wanted a complete solution using embedded XML files and a schema.

The reason for having a schema is obvious, and it works on IE5. In PIE, I noticed, it will work once (!) if used as a local file. According to the people Chris Muench contacted at Microsoft, there is no official Rapier (CE 3.0/Pocket PC) support for local XML files. Possibly it will work with external files (i.e. from the net), please try and let me know. It is also possible to connect to the Internet through a serial or USB connection. For details look at for instance this site. If the site is unavailable for whatever reason, you may want to use a search engine with terms like “iPAQ”, “AnalogX” and “6588”, since that is a suitable proxy server.

My personal reason for using embedded (in contrast to direct viewing) XML files, is a separation of static content (an index or main page), and possibly dynamic content (a XML instance file).

Click to view or download the example. I noticed a very similar example at NNSysDev’s Windows CE projects page. This is concentrated at direct viewing of XML files. It’s worthwile to take a look at that example as well.

This is what the schema (DTD++) looks like:

And this is the stylesheet. For some reason it does not display in the browser correctly when viewed over the Internet. Update April 11th, 2002: this really needed the following header:

Example 2: Posting XML to the server

This is an adaption of a Microsoft Example sometimes referred to as “Extreme RTM”; it concerns posting XML data to a server from an inline Microsoft.XMLHTTP object. It will work on a Pocket PC, albeit that the versions I have seen on the Internet do not. Most versions will not even run correctly on the server, I guess. A summary of mistakes spotted:

  • If IsNull(CUSTDUP) is incorrectly written as If isNull(CUSTDUP) in the ASP page.
  • Pocket Internet Explorer does not support template.XMLDocument.documentElement. This mistake also occurs in some instances of Example 1.
  • Pocket Internet Explorer has problems with sending template.XMLDocument. I created a workaround using an extra Microsoft.XMLDOM object.

Here is the correct ASP page:

<%@LANGUAGE=VBScript%>
<%
Set NEWCUSTINFO = Server.CreateObject(“Microsoft.XMLDOM”)
Set CUSTLIST = Server.CreateObject(“Microsoft.XMLDOM”)NEWCUSTINFO.async=false
NEWCUSTINFO.load(Request)CUSTLIST.async = false
CUSTLIST.load(Server.MapPath(“customers.xml”))

Set CUSTROOT = CUSTLIST.documentElement
Set CUSTOMERS = CUSTROOT.childNodes
Set NEWCUSTROOT = NEWCUSTINFO.documentElement
QUERY = “./customer[name='” & NEWCUSTROOT.childNodes.item(0).text & “‘]”

Set CUSTDUP = CUSTROOT.selectSingleNode(QUERY)

If IsNull(CUSTDUP) = False Then

CUSTROOT.removeChild(CUSTDUP)

End If

CUSTROOT.appendChild(NEWCUSTROOT)
CUSTLIST.save(Server.MapPath(“customers.xml”))

Response.Write CUSTLIST.xml
%>

To be continued. If you want to, you can download the example already.

Example 3: Applying CSS stylesheets (“themes”) to more or less arbitrary content

Parts of this example are based on an initial attempt by Ruud Steltenpool and our discussions that followed from that. Essentially, it is the idea to create an editing environment that allows you to load a document and apply stylesheets to it (in about any possible combination of HTML, CSS, XML & XSL one can think of), to demonstrate the effect of the various stylesheets.

The environment, examples and accompanying text are not finished yet. The best thing you can do right now (if you use at least Internet Explorer version 5 or so) is download the example and try for yourself (locally). I intend to rewrite this into the form of the W3C XSLT Service, with nicer examples and elobrate on the explanations. Mozilla 0.9.x+ and Netscape 6.1 support are also planned. I had this working more or less once, but compatibility was broken during the development.

References for this example include: