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.
|
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.
|
This example contains the following files:
Gets the URL of the page from the user.
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.
|
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.
|
|
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>