This article shows you how to use XML transformation classes defined in the .NET Framework class library to transform XML data into various user interfaces.
Your XML document is a well-organized container of information, but it seems static.Although the document format is useful in representing information structurally, you still tied down to software applications specifically made to handle it.
What if you want to see the document in an HTML browser that doesn't support XML?
Or output it as text for printing.
You see how an XML application can replace a word processor or a browser. This is advantageous because you can begin with an XML document (which can be read from a database, a file in your local system, or downloaded from the Web) and transform it through a style sheet by processor, (or manipulated through the myriad of XML tools available to us) yielding another document (possible another filtered XML document). The XML solution is then to separate authoring from publishing therefore the author of the pages writes the document in XML, thinking in a well-formed and logic structure adopting an XML vocabulary that focuses on the organization of the document, and not handle the presentation in terms of sections, titles, abstracts and more.
So publishing the document then simply requires converting the document into HTML, WML, or another popular format.
There are three main roles:
1. The documents in structure-rich XML providing the static information.
2. XLST style sheets that implements the conversion to HTML, WML or another format. This is a scripting language optimized for conversion of XML documents.
3. An XSLT processor that is responsible for applying the style sheets and generating an output format, which options might be:
- HTML: is not an XML vocabulary. There is no XML to XML transformation, but HTML is used by Web browser to display information.
- XHTML: an XML application of HTML. The major advantage is that it is based on HTML so it will be familiar for Web designers. Currently it is too complex for mobile phones. W3C is working to simplify XHTML.
- ML: the markup language for WAP devices. It is an XML application used for wireless applications, such as mobile phones. You can think of WML as an HTML for mobile users.
- OpenBook: the format for eBook, based on HTML. Another interesting format for mobile users designed for eBook, a different groups a mobile user. An eBook can take a lot of forms, but it is generally a palm-size device on which readers download books.
- XSLFO: a new display language that is optimized for printed documents.
For more information about XSLT, there is an XSLT specification on the Web; you can rich it at www.w3.org/TR/xslt.
This paper shows how we can take advantage of the former ideas, using the technologies shipped in Microsoft.NET platform.
Suppose you have a bookstore and you want to publish all the books for sale. For this solution, I'll use ASP.NET over Microsoft.NET as the Web environment.
First of all you have to analyze and design your solution, so define the items (objects holding information) to publish, and the attributes of such items, in this case: the title, author, an abstract according the theme exposed, and a collection of paragraphs.
Figure 1 shows an XML document with all the information of my bookstore.
You may notice how the items are represented in this document in a logic manner, expressing the containment of objects, so the parent-child relationship.
<?xml-stylesheet type="text/xsl" href="BookFair.xslt"?>
A new intermediate/advanced book for XML developers.
Learn advanced XML programming with Applied XMLSolutions. This hands-on teaching book is filled with practical examples.
Applied XML Solutions is a great complement to XML by Example.
This is the end paragraph.
XML for novice.
This is a book for novice in XML as Web technologies.
About everything in .NET platform.
A book that explains how you can use Microsoft.NET for your Web Solutions.</Para>
The best book about Microsoft.NET.
How to use Windows API.
A very instructive book about how to program to Win32.
You can learn to use the Windows API.
I then define the transformation rules to generate an HTML table for showing to the Web customers. In figure 2, you can see the XSL rules.
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform>"
<h1>Show items of my company.</h1>
<table width="735" height="130" border="1">
<th width="33" scope="col">Pos</th>
<th width="162" scope="col">Author</th>
<th width="169" scope="col">Title</th>
<th width="343" scope="col">Param</th>
Figure 2. (BookFair.xlst).
The Web application that processes the documents is composed by page named BookFair.aspx (figure 3) as the view of the application, and a file hosting all the objects that implements the logic of the application it is named BookFair.aspx.cs (figure 4).
<%@ Page language="c#" Codebehind="BookFair.aspx.cs" AutoEventWireup="false" Inherits="BookFair.BookFairForm" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
<meta name="GENERATOR" Content="Microsoft Visual Studio .NET 7.1">
<meta name="CODE_LANGUAGE" Content="C#">
<meta name="vs_targetSchema" content="http://schemas.microsoft.com/intellisense/ie5>"
<h1>John Olamendy Test.</h1>
Figure 3.( (BookFair.aspx)
public class BookFairForm : System.Web.UI.Page
protected string m_strXmlOutput;
private void Page_Load(object sender,System.EventArgs e)
//This is the logic of the application.
XslTransform objTransform=new XslTransform();
XmlDocument objDocument=new XmlDocument();
StringWriter objStream=new StringWriter();
override protected void OnInit(EventArgs e)
private void InitializeComponent()
this.Load += new System.EventHandler(this.Page_Load);
Figure 4. (BookFair.aspx.cs)
And as you can see this is an application for Web. But in the same manner it is possible create an application for Mobile Users, only changing the view side, and maintaining the documents. This is a good practice of design named model-view, where you have the logic of your application and this logic can be applied for any view no matter if it is a desktop application, a Web application or Wireless application.
Eng. John Charles Olamendy Turruellas.