Home > Articles > Web Development

  • Print
  • + Share This
Like this article? We recommend

Server-Side Application

Our Frequently Asked Questions application has three transactions:

As you can see, the three transactions are quite short, primarily due to the supporting functions in my Ajax library:

  • The NewXMLObject function creates a new DOM object, inserts the XML processing instruction (<?xml version=’1.0’>) and the root element.
  • The NewXMLElement function creates a new node in the XML tree and inserts it as the last child of the specified parent.
  • The NewXMLTextElement function is very similar to the NewXMLElement function, but it also sets the text of the new XML node.
  • The InsertHTMLFragment subroutine parses the HTML fragment passed to it and inserts the resulting collection of DOM nodes as children of the specified DOM node. We use this function for easy transfer of HTML texts stored in the database into the XML result tree.
  • The OutputXMLResponse writes the final DOM tree to the output stream as an XML response or translated into HTML with the desired XSLT transformation. The output is always sent in the XML format if the xml=1 parameter is present in the query string or if the HTTP Accept: header contains x-ajax private MIME type (which we’ll use to indicate that our client-side AJAX code wants XML results).

Once the individual transactions are written and tested, we can start developing the XSLT transformations. Yet again, a modular approach is the most effective: the common.xsl file imported into all final XSLT documents with the xsl:import command transforms the root of the XML tree (match=’/’) into a template HTML page and the individual XSLT transformation documents supply only the missing bits-and-pieces. For example, the categories.xsl transformation displays a lead-in paragraph for the CategoryList XML element and a bullet line with a hyperlink to the list of category-specific questions for each Category element.

The questions.xsl (displaying the list of all questions in the selected category) and answer.xsl (displaying the selected question-and-answer pair) transformations are also less than a page long each. The end result: Because of a structured approach, good support libraries and the right mix of technologies (XML and XSLT), we built a dynamic server-side application that is ready to support client-side AJAX code as well as non-AJAX users with six modules, each shorter than a printed page.

  • + Share This
  • 🔖 Save To Your Account