asp tutorials, asp.net tutorials, sample code, and Microsoft news from 15Seconds
Data Access  |   Troubleshooting  |   Security  |   Performance  |   ADSI  |   Upload  |   Email  |   Control Building  |   Component Building  |   Forms  |   XML  |   Web Services  |   ASP.NET  |   .NET Features  |   .NET 2.0  |   App Development  |   App Architecture  |   IIS  |   Wireless
 
Pioneering Active Server
 Power Search








Active News
15 Seconds Weekly Newsletter
• Complete Coverage
• Site Updates
• Upcoming Features

More Free Newsletters
Reference
News
Articles
Archive
Writers
Code Samples
Components
Tools
FAQ
Feedback
Books
Links
DL Archives
Community
Messageboard
List Servers
Mailing List
WebHosts
Consultants
Tech Jobs
15 Seconds
Home
Site Map
Press
Legal
Privacy Policy
internet.commerce














internet.com
IT
Developer
Internet News
Small Business
Personal Technology
International

Search internet.com
Advertise
Corporate Info
Newsletters
Tech Jobs
E-mail Offers

HardwareCentral
Compare products, prices, and stores at Hardware Central!

Advanced UI Design Using XML and XSL - Part 5: Progress Indicator Creation
By Joe Slovinski
Rating: 4.3 out of 5
Rate this article


  • email this article to a colleague
  • suggest an article

    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 discusses a Progress Indicator object. Below is the screenshot of the Progress Indicator demo located deeper within this article. This screenshot captures the progress indicator in 50 percent.


    Figure 1. Progress Indicator demo

    Progress Indicator Uses

    The Progress Indicator object has the following uses for showing progress (but is not limited to):

    1. Data binding
    2. Preloading images
    3. Charting and graphing

    Progress Indicator Control

    Our progress indicator control exists on the client and is defined as follows:

    
    function ProgressIndicator()
    {
      this.xmlDoc = null;
      this.xslDoc = null;
      this.target = null;
    
      this.init = ProgressIndicator_init;
      this.refresh = ProgressIndicator_refresh;
      this.update = ProgressIndicator_update;
    
      this.xmlObj = new ActiveXObject('MSXML2.DOMDocument');
      this.xmlObj.async = false;
    
      this.xslObj = new ActiveXObject('MSXML2.DOMDocument');
      this.xslObj.async = false;
    }
    
    
    Our control has the following members:

    Properties

    xmlDoc
    The xmlDoc property contains the path to the Progress Indicator configuration file. These XML documents are discussed later in this article.

    xslDoc
    The xslDoc property contains the path to the Progress Indicator XSLT (eXtensible Stylesheet Language Transformations) file. This XSL document is discussed later in this article.

    target
    The target property contains a reference to the object that will contain the Progress Indicator upon its initialization.

    xmlObj
    The xmlObj property contains a reference to the actual XML Parser that contains our Progress Indicator XML configuration document.

    xslObj
    The xslObj property contains a reference to the actual XML Parser that contains our Progress Indicator XSLT document.

    Methods

    init()
    The init() method is defined as follows:

    
    function ProgressIndicator_init()
    {
      this.xmlObj.load(this.xmlDoc);
      this.xslObj.load(this.xslDoc);
    
      this.refresh();
    }
    
    
    refresh()
    The refresh() method is defined as follows:
    
    function ProgressIndicator_refresh()
    {
      this.target.innerHTML = this.xmlObj.documentElement.transformNode(this.xslObj);
    }
    
    
    This method applies our XSLT style sheet to our configuration file and places the resulting transformation within the innerHTML property of our target element.

    update()
    The update() method is defined as follows:

    
    function ProgressIndicator_update(percent)
    {
      this.percentComplete = percent;
      this.xmlObj.documentElement.selectSingleNode("percentComplete").text = this.percentComplete;
    
      this.refresh();
    }
    
    
    This method receives an integer representing a percent, which for practical purposes is normally a range of 0 through 100. The method then proceeds to set the percentComplete property of the Progress Indicator object, after which it updates the XML configuration file. After the XML configuration file mirrors this percent, the refresh method is called to perform a new transformation and update the client browser.

    XML Configuration File

    Below is a valid Progress Indicator configuration file.

    
    <?xml version="1.0"?>
    <ProgressIndicator>
      <styles>
        <leftBackgroundColor>gray</leftBackgroundColor>
        <leftFontColor>white</leftFontColor>
        <rightBackgroundColor>white</rightBackgroundColor>
        <rightFontColor>black</rightFontColor>
        <borderTop>1px solid black</borderTop>
        <borderLeft>1px solid black</borderLeft>
        <borderBottom>1px solid black</borderBottom>
        <borderRight>1px solid black</borderRight>
        <height>25</height>
        <width>200</width>
      </styles>
      <percentComplete>0</percentComplete>
    </ProgressIndicator>
    
    
    This file defines your styles and default percent of your Progress Indicator.

    XSLT File

    Below is the XSLT document that is applied to a Progress Indicators XML during initialization and updating.

    
    <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
     xmlns:dt="urn:schemas-microsoft-com:datatypes">
      <xsl:template match="ProgressIndicator">
        <TABLE BORDER="0" CELLSPACING="0" CELLPADDING="0">
          <xsl:attribute name="STYLE">
            border-top: <xsl:value-of select="styles/borderTop"/>;
            border-left: <xsl:value-of select="styles/borderLeft"/>;
            border-bottom: <xsl:value-of select="styles/borderBottom"/>;
            border-right: <xsl:value-of select="styles/borderRight"/>;
            height: <xsl:value-of select="styles/height"/>;
            width: <xsl:value-of select="styles/width"/>;
          </xsl:attribute>
          <TR>
            <TD ALIGN="right">
              <xsl:attribute name="STYLE">
                background-color: <xsl:value-of select="styles/leftBackgroundColor" />;
                color: <xsl:value-of select="styles/leftFontColor" />;
                font-family: arial;
                font-size: 11px;
                font-weight: bold;
                width: <xsl:value-of select="styles/width div 100 * percentComplete" />px;
              </xsl:attribute>
              <xsl:if test="percentComplete > 50">
                <span style="padding-left: 5px; padding-right: 5px;">
                  <xsl:value-of select="percentComplete" />%
                </span>
              </xsl:if>
            </TD>
            <TD ALIGN="left">
              <xsl:attribute name="STYLE">
                background-color: <xsl:value-of select="styles/rightBackgroundColor" />;
                color: <xsl:value-of select="styles/rightFontColor" />;
                font-family: arial;
                font-size: 11px;
                font-weight: bold;
                width: <xsl:value-of select="styles/width - (styles/width div 100 * percentComplete)" />px;
              </xsl:attribute>
              <xsl:if test="percentComplete <= 50">
                <span style="padding-left: 5px; padding-right: 5px;">
                  <xsl:value-of select="percentComplete" />%
                </span>
              </xsl:if>
            </TD>
          </TR>
        </TABLE>
      </xsl:template>
    </xsl:stylesheet>
    
    
    This style sheet creates a table with two cells. As the percent grows from 0 to 50, the placement of the percentage label (contained in an HTML "SPAN" element) is switched from the right cell to the left. The formula for calculating the left and right cells varies. These formulas are displayed above.

    Demo

    The demo Progress Indicator provided within this article is set to update in tens of percents every second. When attaching the Progress Indicator included in this article to a data-bound table and updating it with a simple record/row formula you can achieve a real-time update of the progress of any client-side Data--Binding process.

    Click to view the demo.

    Download the source code.

    Future Articles

    In an upcoming article I will explain how to use this Progress Indicator on a data-bound table. Below is a sneak peak from this article.


    Figure 2. Preview of future article

    Closing

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

    On a side note I would like to thank Barry Carter for the use of his facilities during my stay here in Nashville!

    Other Articles in the Series

    Advanced UI Design Using XML and XSL

    Part 1 -- Folder Tree Creation
    http://www.15seconds.com/issue/010921.htm

    Part 2 -- Custom Context Menu Creation
    http://www.15seconds.com/issue/010927.htm

    Part 3 -- Folder Tree Administration
    http://www.15seconds.com/issue/011113.htm

    Part 4 - Folder Tree Drag and Drop
    http://www.15seconds.com/issue/011129.htm

    Part 6 -- Progress Indicator Usage
    http://www.15seconds.com/issue/020109.htm

    Part 7 -- Relational Folder Tree Lines
    http://www.15seconds.com/issue/020424.htm

    About the Author

    Joe Slovinski has been programming Web applications since 1993. For more information on the code in this article, contact the Joe Slovinski.

  • Rate This Article
    Not HelpfulMost Helpful
    1 2 3 4 5
    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
    Sep 22, 2005 - Implementing Remote Calling Without Using AJAX
    Right now the latest buzzword around town is AJAX. AJAX is an acronym for Asynchronous JavaScript and XML and is a method used to implement remote calling. The problem is that AJAX is only implemented in ASP.NET 2.0. This article will show you one way to implement remote calling without using AJAX or the XMLHttpRequest object. The technique outlined can even be used from classic ASP and is sufficient for most remote calling needs.
    [Read This Article]  [Top]
    Aug 18, 2005 - SQL Server 2005 XQuery and XML-DML - Part 3
    This article is the third and final installment of Alex Homer's series covering the new XML support in Microsoft SQL Server 2005. In it he covers updating the contents of xml columns, comparing traditional XML update techniques with XQuery, and using XQuery in a managed code stored procedure.
    [Read This Article]  [Top]
    Aug 11, 2005 - SQL Server 2005 XQuery and XML-DML - Part 2
    In the second part of his series on SQL Server 2005's new XML support, Alex Homer looks at extracting data from XML columns, comparing traditional XML data access approaches with XQuery, and combining XQuery and XSL-T.
    [Read This Article]  [Top]
    Aug 3, 2005 - SQL Server 2005 XQuery and XML-DML - Part 1
    Microsoft SQL Server 2005 now offers great support for and close integration with XML as a data persistence format. In the first article of his series examining this new support, Alex Homer offers an overview of how SQL Server 2005 stores XML documents and schemas, examines how it supports querying and manipulating XML documents, and provides a simple test application that allows you to experiment with XQuery.
    [Read This Article]  [Top]
    Jun 30, 2005 - Reading and Writing XML in .NET Version 2.0 - Part 3, Cont'd
    In the final article of his series on reading and writing XML in .NET 2.0, Alex Homer looks at how the updated XML document store objects XmlDocument, XmlDataDocument and PathDocument can be used to read, persist and write XML documents and fragments more easily and more efficiently than in .NET 1.x.
    [Read This Article]  [Top]
    Jun 29, 2005 - Reading and Writing XML in .NET Version 2.0 - Part 3
    In the final article of his series on reading and writing XML in .NET 2.0, Alex Homer looks at how the updated XML document store objects XmlDocument, XmlDataDocument and PathDocument can be used to read, persist and write XML documents and fragments more easily and more efficiently than in .NET 1.x.
    [Read This Article]  [Top]
    Jun 16, 2005 - Reading and Writing XML in .NET Version 2.0 - Part 2, Cont'd
    Alex Homer continues his series on reading and writing XML in .NET 2.0. In part one, we focused on the reading side of things, examining the XmlReader and XmlReaderSettings classes. In this article, we move on to look at the XmlWriter and XmlWriterSettings classes, and how they can be used to write XML documents and fragments more easily and more efficiently than in version 1.x of .NET.
    [Read This Article]  [Top]
    Jun 15, 2005 - Reading and Writing XML in .NET Version 2.0 - Part 2
    Alex Homer continues his series on reading and writing XML in .NET 2.0. In part one, we focused on the reading side of things, examining the XmlReader and XmlReaderSettings classes. In this article, we move on to look at the XmlWriter and XmlWriterSettings classes, and how they can be used to write XML documents and fragments more easily and more efficiently than in version 1.x of .NET.
    [Read This Article]  [Top]
    Jun 2, 2005 - Reading and Writing XML in .NET Version 2.0 - Part 1, Cont'd
    In the first part of his series on reading and writing XML in .NET 2.0, Alex Homer discusses the XmlReader and XmlReaderSettings classes. The XmlReader exposes several useful new features and the all new XmlReaderSettings class makes it easy to generate single or multiple instances of an XmlReader with a range of useful properties.
    [Read This Article]  [Top]
    Jun 1, 2005 - Reading and Writing XML in .NET Version 2.0 - Part 1
    In the first part of his series on reading and writing XML in .NET 2.0, Alex Homer discusses the XmlReader and XmlReaderSettings classes. The XmlReader exposes several useful new features and the all new XmlReaderSettings class makes it easy to generate single or multiple instances of an XmlReader with a range of useful properties.
    [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



    JupiterOnlineMedia

    internet.comearthweb.comDevx.commediabistro.comGraphics.com

    Search:

    Jupitermedia Corporation has two divisions: Jupiterimages and JupiterOnlineMedia

    Jupitermedia Corporate Info


    Legal Notices, Licensing, Reprints, & Permissions, Privacy Policy.

    Advertise | Newsletters | Tech Jobs | Shopping | E-mail Offers