TinyBrowser/0.2

This example explores the using XSL Processor on the client side. TinyServer does not attempt to apply XSL rules on the XML document since it realizes that the client is TinyBrowser/0.2 by using User-Agent HTTP header.

Figure 1:

TinyServer handles HTTP Requests. It sends XML documents without processing to the TinyBrowser/0.2 client.

TinyBrowser needs to find out how to get XSL file before it can apply these rules on the document. TinyBrowser looks for two things in the following order:

If it can not find any of them, then TinyBrowser renders the XML document as an ASCII file. When it finds the XSL file address, it loads the file from this address.

Figure 2:

A memory layout of the XML document. The root node of the Document object encapsulates the content.

This example contains the following files:

GetURL.java

Gets the URL of the page from the user.

TinyBrowser.java

Swing based GUI. This object gets the URL of the page and displays it. It uses JEditorPane object to handle the rendering.

TinyBrowser builds DOM representations of the XML document and the XSL document. Then it applies XSL processing on this document to render it.

Figure 3:

The XSL engine accepts the DOM of the XML document and XSL rules to produce the output.

The following code snippet is taken from TinyBrowser code. It gets the implementation of iwt.web.xmldomxsl.XMLDOMXSL interface, the Document object of the XML document, the address of the XSL document, the Document object of the XSL document, and applies XSL rules on the XML document.

iwt.web.xmldomxsl.XMLDOMXSL web = null;
String xmldomxsl = props.getProperty("org.w3c.xmldomxsl");

// Code for obtaining implementation
Document doc = web.openDocument(urlConnection.getInputStream(),url.toString());

// Code for obtaining XSL File address
URL styleURL = new URL(styleSheet);

// Get the document
Document styleDoc = web.openDocument(styleURL);

// Produce the XSL rule output
ByteArrayOutputStream bout = new ByteArrayOutputStream();
PrintStream pout = new PrintStream(bout);
web.applyXSLRules(doc,styleDoc,bout); 

// set the text in the htmlPane
htmlPane.setText(bout.toString());

TinyBrowser/0.2 uses the same XSL processing to render the directory resource, therefore, it does not need DIRDOM and ResourceRecord objects in the previous example.

Figure 4: TinyBrowser/0.2 renders the directory resource by using XSL Engine.
Figure 5:

A snapshot of GUI after browsing the same student.xml file. Browser loads the XSL rules and XSL engine renders the document on the client side. Snapshots are overlapped to show GUI before and after user entered the URL.

The following snippet shows the portion of student.xml file where axml-stylesheet processing instruction placed in the XML document.

<?xml version="1.0"?>
<!DOCTYPE students SYSTEM "http://hawaii.npac.syr.edu:5005/xsl2/student.dtd">
<?axml-stylesheet href="http://hawaii.npac.syr.edu:5005/xsl2/ex4.xsl"?>
<students class="CPS700">

<student stdid="a125">
  <name>Allen</name>
  <surname>fox</surname>
</student>

</students>

Exercises