Site hosted by Angelfire.com: Build your free website today!
 
Web Services  |   .NET  |   IIS 5.0  |   IIS 4.0  |   Data Access  |   Beginning  |   Troubleshooting  |   Security  |   Performance  |   Component Building  |   ADSI  |   ISAPI  |   Site Server  |   FTP  |   Upload  |   State  |   Email  |   Scripting  |   XML
 
  Pioneering Active Server
 Power Search



Subscribe Now!
15 Seconds Weekly Newsletter

Text

HTML

More Free Newsletters
Reference
News
Articles
Archive
Writers
Code Samples
Components
WebHosts
FAQ
Books
Glossary
KB Index
Links
News Groups
Tools
DL Archives
Community
List Servers
Mailing List
Consultants
Jobs
15 Seconds
Home
Site Map
Press
Legal
Privacy Policy
internet.com
     Internet News
     Internet Investing
     Internet Technology
     Windows Internet Tech.
     Linux/Open Source
     Web Developer
     E-Commerce/Marketing
     ISP Resources
     ASP Resources
     Wireless Internet
     Downloads
     Internet Resources
     Internet Lists
     International
     EarthWeb
     Career Resources

     Search internet.com
     Advertising Info
     Corporate Info
     Internet Trade Shows
internet.commerce
     





Advanced UI Design Using XML and XSL - Part 1:
Folder Tree Creation

By Joe Slovinski



email this article to a colleague

Introduction

Welcome to Advanced UI Design Using XML and XSL. Each article in my series will demonstrate the creation of a specific user interface (UI) component using eXtensible Markup Language (XML) and eXtensible Stylesheet Language (XSL). This article explains how to create a folder tree of unlimited depth by using XML and XSL, the style-sheet language for XML. The folder tree discussed in this article functions by taking an XML feed of a specific format and applying an XSL style sheet to it. The resulting transformation is then printed to the client. The client handles all requests to expand, collapse, maximize or minimize entities within the tree, or the whole tree itself. The client used in this article is Internet Explorer 5.5+.

The actual folder tree demonstrated is available for download at the end of this article.

Folder -Tree-Specific Architecture

Like most Web page objects, there are several ways to build them. When developing your specific folder tree, you should keep in mind some architectural decisions adherent to a folder tree such as:

  1. Nesting
  2. Lines

Nesting


    Figure 1. No nesting within the browser

    Figure 2. Nesting within the browser

In Both Figures 1 and 2 borders were temporarily applied to the tree so that one can more easily see the relationships and nesting of objects within the Document Object Model (DOM).

Lines

Lines within your tree can provide a greater visual effect and make larger tree structures easier to read. The negative effect on having lines within your tree is performance. A tree with 100 items may use about 300 images just to display the relationship between entities. Caching and preloading images can help, but they still exist as individual objects within the DOM. Without lines, simple indenting can show the relationship between parent and child. In this article I will demonstrate the creation of a tree without lines.

XML Structure

All corporations' requirements differ from one another. Odds are the requirements I have for my tree are much different than the requirements you may have for yours. XML provides us with the perfect interface to describe our unique tree entities. The format you choose will have a direct effect on your XSL style sheets and your client operations. The format I have chosen is good for a recursive XSL style sheet, which satisfies the requirement within this article for a folder tree of unlimited depth.

The XML document I have constructed contains a root element named "tree" that can contain only "entity" elements. The structure of your tree is implicitly defined here by nesting entity elements within the "contents" element of other entity elements. Below is a listing of all elements or attributes that belong to the "entity" element.

Name Type Description
id Attribute Unique string or integer used to identify the individual entity
description Element Description of individual entity. This is the text displayed to the user.
onClick Element Name of the client-side function fired upon the onClick event
image Element Image displayed when entity is closed or not selected
imageOpen Element Image displayed when entity is open
contents Element Contains entity elements. The content element is used to determine whether or not an entity has children.

Within your individual trees, use the entity element to append specific data about each object in your tree. This could be the ID of a record in a database that the entity is representing. In upcoming articles I will demonstrate how to create an entity-specific context menu that is implemented by the addition of an "oncontextmenu" element to our entity element.

The following XML is the XML we will be using in this article. For illustration purposes I have created a static XML document instead of implementing a dynamic XML database query.


<?xml version="1.0"?>
<tree>
  <entity id="e1">
    <description>Customers</description>
    <oncontextmenu></oncontextmenu>
    <image>images/book.gif</image>
    <imageOpen>images/bookOpen.gif</imageOpen>
    <contents>
      <entity id="e2">
        <description>Microsoft</description>
        <image>images/book.gif</image>
        <imageOpen>images/bookOpen.gif</imageOpen>
        <onClick>displayCustomer(12345)</onClick>
        <contents>
          <entity id="e3">
            <description>Orders</description>
            <image>images/book.gif</image>
            <imageOpen>images/bookOpen.gif</imageOpen>
            <onClick></onClick>
            <contents/>
          </entity>
        </contents>
      </entity>
      <entity id="e4">
        <description>IBM</description>
        <image>images/book.gif</image>
        <imageOpen>images/bookOpen.gif</imageOpen>
        <onClick>displayCustomer(12346)</onClick>
        <contents>
          <entity id="e5">
            <description>Orders</description>
            <image>images/book.gif</image>
            <imageOpen>images/bookOpen.gif</imageOpen>
            <onClick></onClick>
            <contents/>
          </entity>
        </contents>
      </entity>
      <entity id="e6">
        <description>Sun Microsystems</description>
        <image>images/book.gif</image>
        <imageOpen>images/bookOpen.gif</imageOpen>
        <onClick>displayCustomer(12347)</onClick>
        <contents>
          <entity id="e7">
            <description>Orders</description>
            <image>images/book.gif</image>
            <imageOpen>images/bookOpen.gif</imageOpen>
            <onClick></onClick>
            <contents>
              <entity id="e8">
                <description>#12345</description>
                <image>images/paper.gif</image>
                <imageOpen>images/paper.gif</imageOpen>
                <onClick></onClick>
                <contents/>
              </entity>
              <entity id="e9">
                <description>#12346</description>
                <image>images/paper.gif</image>
                <imageOpen>images/paper.gif</imageOpen>
                <onClick></onClick>
                <contents/>
              </entity>
            </contents>
          </entity>
        </contents>
      </entity>
      <entity id="e10">
        <description>Oracle</description>
        <image>images/book.gif</image>
        <imageOpen>images/bookOpen.gif</imageOpen>
        <onClick>displayCustomer(12348)</onClick>
        <contents>
          <entity id="e11">
            <description>Orders</description>
            <image>images/book.gif</image>
            <imageOpen>images/bookOpen.gif</imageOpen>
            <onClick></onClick>
            <contents/>
          </entity>
        </contents>
      </entity>
    </contents>
  </entity>
  <entity id="e12">
    <description>Reports</description>
    <oncontextmenu></oncontextmenu>
    <image>images/book.gif</image>
    <imageOpen>images/bookOpen.gif</imageOpen>
    <contents>
      <entity id="e13">
        <description>Income</description>
        <oncontextmenu></oncontextmenu>
        <image>images/paper.gif</image>
        <imageOpen>images/paper.gif</imageOpen>
        <contents>
        </contents>
      </entity>
      <entity id="e14">
        <description>Expenses</description>
        <oncontextmenu></oncontextmenu>
        <image>images/paper.gif</image>
        <imageOpen>images/paper.gif</imageOpen>
        <contents>
        </contents>
      </entity>
    </contents>
  </entity>
</tree>

The above XML file is named "tree.xml" and is available for download at the end of this article.

XSL Style Sheet

Both Figures 1 and 2 were the result of transformations with our XML document and separate XSL style sheets. Below is the standard XSL style sheet that is applied to our XML document(s).


<xsl:stylesheet xmlns:xsl="http://www.w3.org/TR/WD-xsl" language="JavaScript">

<xsl:template match="tree">
  <xsl:apply-templates select="entity"/>
</xsl:template>

<xsl:template match="entity">
  <div onclick="window.event.cancelBubble = true;clickOnEntity(this);" onselectstart="return false" ondragstart="return false">
  <xsl:attribute name="image"><xsl:value-of select="image"/></xsl:attribute>
  <xsl:attribute name="imageOpen"><xsl:value-of select="imageOpen"/></xsl:attribute>
  <xsl:attribute name="open">false</xsl:attribute>
  <xsl:attribute name="id">f<xsl:value-of select="@id"/></xsl:attribute>
  <xsl:attribute name="open">false</xsl:attribute>
  <xsl:attribute name="STYLE">
    padding-left: 20px;
    cursor: hand;
    <xsl:if expr="depth(this) > 2">
      display: none;
    </xsl:if>
  </xsl:attribute>
    <table border="0" cellspacing="0" cellpadding="0">
      <tr>
        <td valign="middle">
          <img border="0" id="image">
            <xsl:attribute name="SRC">
              <xsl:value-of select="image"/>
            </xsl:attribute>
          </img>
        </td>
        <td valign="middle" nowrap="true">
        <xsl:attribute name="STYLE">
          padding-left: 7px;
          font-family: Verdana;
          font-size: 11px;
          font-color: black;
        </xsl:attribute>
        <xsl:value-of select="description"/></td>
      </tr>
    </table>
  <xsl:apply-templates select="contents/entity"/>
  </div>
</xsl:template>

</xsl:stylesheet>

Figure 3 (below) displays the folder tree that is created using the above XSL style sheet.


Figure 3. XSL transformation

Client Operations

In order for our folder tree to function, we require the following client-side operations:

  1. Initialize
  2. Expand
  3. Collapse
  4. Expand All (Maximize)
  5. Collapse All (Minimize)
Below is the code that performs these five operations. This code can be found within the "tree.js" file included with this article.

function initialize() {
  var xmlDoc
  var xslDoc

  xmlDoc = new ActiveXObject('Microsoft.XMLDOM')
  xmlDoc.async = false;

  xslDoc = new ActiveXObject('Microsoft.XMLDOM')
  xslDoc.async = false;

  xmlDoc.load("tree/tree.xml")
  xslDoc.load("tree/tree.xsl")

  folderTree.innerHTML = xmlDoc.documentElement.transformNode(xslDoc)
}

function clickOnEntity(entity) {
  if(entity.open == "false") {
    expand(entity, true)
  }
  else {
    collapse(entity)
  }
  window.event.cancelBubble = true
}

function expand(entity) {
  var oImage

  oImage = entity.childNodes(0).all["image"]
  oImage.src = entity.imageOpen

  for(i=0; i < entity.childNodes.length; i++) {
    if(entity.childNodes(i).tagName == "DIV") {
      entity.childNodes(i).style.display = "block"
    }
  }
  entity.open = "true"
}

function collapse(entity) {
  var oImage
  var i

  oImage = entity.childNodes(0).all["image"]
  oImage.src = entity.image

  // collapse and hide children
  for(i=0; i < entity.childNodes.length; i++) {
      if(entity.childNodes(i).tagName == "DIV") {
        if(entity.id != "folderTree") entity.childNodes(i).style.display = "none"
        collapse(entity.childNodes(i))
      }
    }
  entity.open = "false"
}

function expandAll(entity) {
  var oImage
  var i

  expand(entity, false)

  // expand children
  for(i=0; i < entity.childNodes.length; i++) {
    if(entity.childNodes(i).tagName == "DIV") {
      expandAll(entity.childNodes(i))
    }
  }
}

Future of Web-Based Folder Trees

As Web technologies grow, they allow us to maintain state within our Web applications. This increases the complexity of our interfaces as more operations are moved from server to client. This is a blessing that will increase the usability of our interfaces and the performance of our applications by taking the load off of our servers.

In future articles I may expand on the tree discussed in this article by explaining how to create an API to dynamically insert, remove, rename, and refresh objects within your trees.

Closing

I hope the contents of this article will help increase the quality of your Web applications interface. If you have any questions, comments, or suggestions, please feel free to email me at the address listed in the author section.

On a side note, I would like to thank Lee McGraw for helping me proofread and validate this document.

The second article in this series addresses custom context menu creation.

Download

Download the example.zip file that contains the files that make up the tree, including tree.xsl, tree.xml, tree.js, tree.css, common.js, and images.

About the Author

Joe Slovinski is president of Internet Solutions, Inc., and is currently developing .NET applications in Nashville, while at the same time working on the next generation of Web application UI objects. Programming Internet sites and Web applications since 1993, he has seen the Internet grow into what it is today and is helping to create the Internet of tomorrow.

When not working, and depending on location, he enjoys listening to most all forms of music, playing the guitar, surfing, and spending time outdoors.

Joe can be reached via email at jslovinski@unrealcity.com.

Supporting Products/Tools
Stonebroom.ASP2XML
Stonebroom.ASP2XML(c) is an interface component designed to make building applications that transport data in XML format much easier. It can be used to automatically pass updates back to the original data source.
[Top]
Other Articles
Dec 12, 2001 - Advanced UI Design Using XML and XSL - Part 5:
Progress Indicator Creation
Joe Slovinski creates a Progress Indicator object that uses XML and XSLT. This object has several uses, including updating the client browser of the progress of a data binding routine or the preloading of images.
[Read This Article]  [Top]
Nov 29, 2001 - Advanced UI Design Using XML and XSL - Part 4:
Folder Tree Drag and Drop
Joe Slovinski creates a drag-and-drop object for folder trees. This control has the capability to drag and drop entities from one point within a tree to another or between multiple trees.
[Read This Article]  [Top]
Nov 13, 2001 - Advanced UI Design Using XML and XSL - Part 3:
Folder Tree Administration
Joe Slovinski explains how to dynamically insert, update, rename, and delete entities within a folder tree. Providing features such as unlimited metadata support via XML and XSLT this version of the folder tree can be re-used to represent any array of data.
[Read This Article]  [Top]
Sep 27, 2001 - Advanced UI Design Using XML and XSL - Part 2:
Custom Context Menu Creation
Joe Slovinski explains how to use XML and XSL to create custom context menus on the fly. Using XML and XSL makes these menus low-maintenance and reusable, and reduces load on the server when transformed on the client.
[Read This Article]  [Top]
Sep 18, 2001 - Creating Web Service Client Code Automatically
Robert Chartier explains how to use the WSDLReader Component, part of the Microsoft SOAP Toolkit, to automatically read any Web Service and automatically create your client-sided code. This can be a big time saver.
[Read This Article]  [Top]
Aug 29, 2001 - Advanced Web-Enabled Applications and Services Architecture Using XML and XSL - Part 2
This article builds on the concepts introduced in Part 1. It will show you an actual implementation in Visual Basic 6 that solves the problems faced by many companies and described in Part 1. This implementation shows you how to serve data up to any client, independent of programming language or operating system.
[Read This Article]  [Top]
Aug 10, 2001 - Converting XML to HTML Using Sun's Java API for XML Processing and Microsoft's MSXML 3.0 API
In this article, Robert Galante describes two solutions he employed in applications to generate custom reports. His solutions convert XML data to HTML using XSL Transformations. One solution uses the Sun Java API for XML Processing, which is called JAXP. The other solution uses the Microsoft MSXML API.
[Read This Article]  [Top]
Aug 8, 2001 - An Introduction to the SOAP Toolkit - Part 2
This is the second part of a two-part series geared to get you quickly started with Web services and the Microsoft Simple Object Access Protocol (SOAP) Toolkit. It will allow you to consume the server that we created in the first part of this article.
[Read This Article]  [Top]
Aug 6, 2001 - Advanced Web-Enabled Applications and Services Architecture Using XML and XSL - Part 1
This article will introduce you to common mistakes and how to avoid them when dealing with Web-enabled application architecture. It also offers a robust example of how to build an expandable solution using XML and XSLT.
[Read This Article]  [Top]
Aug 1, 2001 - Tracking Web Page Visitors with XML
In this article Lai Yuen Kit creates a simple stats tracking program to demonstrate how to deal with records using XML, instead of ADO Object.
[Read This Article]  [Top]
Jul 25, 2001 - An Introduction to the SOAP Toolkit - Part 1
With the Server with the SOAP Toolkit (V2, Gold Release) from Microsoft, you can easily get a Web service on line in minutes. This article will take you through, step by step, the quick and easy way of taking your custom business logic and deploying it as a Web service.
[Read This Article]  [Top]
Jun 20, 2001 - Implement a Division-of-Labor Approach to Complex XML Manipulation
Learn how to use XML and IE's modal dialog functionality to manipulate data from a single Web page.
[Read This Article]  [Top]
Jun 1, 2001 - Converting Your existing HTML to XML
In this article Ashwin Kamanna shows how to easily migrate HTML pages to XML using HTML Tidy and a COM Wrapper.
[Read This Article]  [Top]
May 22, 2001 - Using XML to Improve File-Upload Processing
In this article, Marco Nanni examines an example of multiple binary file uploading for Web applications using XML, without the typical limitations of traditional file upload processing.
[Read This Article]  [Top]
May 11, 2001 - Using the Application Object to Improve Performance
Learn what types of data exchanges are targets for optimization and the benefits and disadvantages of using persistence with the Application object.
[Read This Article]  [Top]
Apr 10, 2001 - Creating an In-Memory Database Using XML and XPath -- Part 2
Learn how to successfully apply an IMDB to large volumes of data and still get phenomenal searching speeds that outperform a dedicated SQL Server database.
[Read This Article]  [Top]
Apr 9, 2001 - Creating an In-Memory Database Using XML and XPath -- Part 1
In this article Niall Ginsbourg takes a look at using Microsoft's XML Parser, along with its in-built XPath query processor, to create an In-Memory Database that provides superior searching operations over an equivalent SQL Server solution.
[Read This Article]  [Top]
Mar 5, 2001 - Distributing Server Load to the Client with XML and XSL
Using traditional ASP, Web servers are forced to do all the work in creating a page. This includes getting the data, formatting the output, and sending it to the client. With XML and XSL, the server only needs to get the data in XML format and send that and the XSL to the client. The client will then use its CPU power to transform the XML into HTML using the XSL style sheet. This approach will allow your Web servers to handle many more concurrent users.
[Read This Article]  [Top]
Feb 5, 2001 - Binding Client Side Controls Dynamically to an XML Data Source Object
The XML data island in IE 5.x provides a simple and convenient way to dynamically alter the content of a Web page using data stored either locally or remotely in XML format.
[Read This Article]  [Top]
Dec 11, 2000 - SQL Server 2000 and XfA
At XML 2000 last week in Washington, D.C., David Turner of Microsoft introduced a new technology called XfA. Get a glimpse of the technology in this summary report.
[Read This Article]  [Top]
Nov 17, 2000 - Somewhere in XML
This article discusses how Windows DNA affects team development and how it can be improved using XML, XSLT, and XML Schemas.
[Read This Article]  [Top]
Nov 2, 2000 - Retrieving Dynamic XML from SQL Server 7.0 and 2000
SQL Server is packed with features for retrieving XML documents. Steven Woods offers a demonstration of extending a SQL Query via the RAW, AUTO, and EXPLICIT modes to illustrate the functionality available. The article then discusses the concept of templates, which allow the creation of dynamic parameter-based XML documents, and how templates can be executed via Visual Basic.
[Read This Article]  [Top]
Jun 12, 2000 - GUI Input: Solving the "Hard Refresh" Problem Using XML and ASP
Doing a hard refresh every time the client needs more information makes the interface difficult for a user to use in complex applications and causes unnecessary strain on the network because frequently the same data is being sent to the client repeatedly. Dennis Hurst examines the problem and provides a XML/ASP solution.
[Read This Article]  [Top]
Nov 25, 1999 - XMLHTTP: Super Glue for the Web
Kyle Patrick explains how using the XMLHTTPConnection object that Microsoft packaged with its MSXML parser is a fast, free, and powerful method for communication between any client and server application that supports COM objects. Using this, instead of CGI, means you can have a client-server interaction between the browser and the Web server that can be done without changing the Web page. Sample code and URLs are included.
[Read This Article]  [Top]
May 27, 1999 - Server-Side XML in ASP
With the upcoming release of Internet Explorer 5.0, it is much easier to use XML in Web applications. Here is some information on how to harness the power of the updated XML Document Object Model (DOM) on the server to parse and use XML data in ASP applications.
[Read This Article]  [Top]
Mailing List
Want to receive email when the next article is published? Just Click Here to sign up.

Support the Active Server Industry

Copyright 2001 INT Media Group Incorporated. All Rights Reserved.
Legal Notices,  Licensing, Reprints, & Permissions,  Privacy Policy.