FREE Subscription to Dr. Dobb’s Digest: Same Great Content, New Digital Edition
Site Archive (Complete)
Architecture & Design
Email
Print
Reprint

add to:
Del.icio.us
Digg
Google
Furl
Slashdot
Y! MyWeb
Blink
TABLE OF CONTENTS
April 05, 2007

XSL Transformations

(Page 3 of 4)

Sample Web Application

In our sample application, the user decides on a function to invoke (one of "Factorial," "Fibonacci," "IsPrime" and "nthPrime"), provides the parameter, and clicks on the button corresponding to the desired operation. The basic structure of the code that processes the client input is:

  1. XmlDocumentObject <-XML document containing the XIM code of the requested computation.
  2. Get user input parameter and insert it into XmlDocumentObject.
  3. Insert the processing instruction element to declare the interpreter stylesheet.
  4. Save the modified document in a file.
  5. Redirect the client to the saved XML file.

First, the stored "prepackaged" XIM code for the requested computation (whose only missing part is the input parameter value) is loaded into an XmlDocument object and the parameter supplied by the user is inserted into the code at the correct spot. Then the processing instruction indicating the name of the stylesheet (the XIM interpreter) to be applied to the document is inserted into the code. The resulting code in the object is stored in an XML document, and the client browser is redirected to this XML document. To demonstrate what happens when the client supplies a parameter and makes a choice, this code processes a "factorial" request:

private void FactBtn_Click(object sender, System.EventArgs e) { XmlDocument xmlDoc=new XmlDocument(); xmlDoc.Load("c://inetpub/wwwroot/xim/fact5.xml"); XmlElement var_n=xmlDoc.CreateElement("var_declare",""); var_n.InnerText=TextBox1.Text; var_n.SetAttribute("name","nb"); // Adding name attribute to variable element // Appending client input as a variable to XIM code // for factorial computation xmlDoc.DocumentElement.FirstChild.AppendChild(var_n); XmlProcessingInstruction newPI; // Processing instruction to declare stylesheet name String PItext = "type='text/xsl' href='interp.xsl'"; // Assigning the name of the interpreter // stylesheet to processing instruction newPI = xmlDoc.CreateProcessingInstruction ("xml-stylesheet", PItext); // Add processing instruction node to the document xmlDoc.InsertBefore(newPI, xmlDoc.DocumentElement); xmlDoc.Save("c://Inetpub/wwwroot/XIM/test.xml"); // Save the modifications to the XIM code // Redirectng the client response // to the just created XIM file Response.Redirect("http://194.27.78.64/XIM/test.xml"); }

See Figure 3 for the result of the interpretation on the client machine of the factorial function, applied to number "20."

[Click image to view at full size]

Figure 3: The result of the computation of 20! executed and displayed on client's browser.

Previous Page | 1 XSL Transformations | 2 The Minimal Imperative Language XIM | 3 Sample Web Application | 4 Related Work Next Page
TOP 5 ARTICLES
No Top Articles.



MICROSITES
FEATURED TOPIC

ADDITIONAL TOPICS

INFO-LINK