N341 - Homework 3
Project Start

Modified

Downloads

Find errors in HTML/XML/XSL - msxsl.exe Download

Note

The solution is to require IE to check for new versions on every visit to a page by:

Tools | Internet Options | Browsing history | Settings | Every Visit to Page

<FORM NAME=ONE>
    <INPUT type=text name="TWO" >
</form>

but has the following errors as XML/XSL:

  1. ONE must be quoted,
  2. text must be quoted,
  3. INPUT requires a matching end tag </INPUT>
  4. </form> must match <FORM>

Below is valid XML/XSL:

<FORM NAME="ONE">
    <INPUT type="text" name="TWO"/>
</FORM>
 

Overview 

The assignment is for familiarization with the project basics and how to build user interface components in a moderately complex Web system.

We have discussed prototyping and testing. The class project will serve as an example for analysis, prototyping, testing and implementation.

Homework 2 performed the initial analysis and design; a partial prototyped user interface was implemented and tested using paper.

Homework 3 will develop the skills needed to implement an interactive Web site for trading stocks.

 

Analysis - Separating the User Interface from the Blue Sky

Project Description

Our class is creating a stock trading Web-site that will undercut the brick-and-mortar stock brokers by allowing traders to perform all trading functions online without a broker: from registration, stock analysis, to buying and selling stocks. For our services, each stock trade will incur a small percentage of the trade fee.

The site must be easy to use while providing the  traders a sense that our Web-site and their money is secure. Security will be enforced by requiring traders to first register to create a unique trader identification and password that controls access to their account; to access an account, the trader must first provide their chosen identification and password. Further security is enforced by limiting account access to a single trader account at a time.

Stocks are traded in a usual way. In order to buy stocks, traders must transfer funds to their account using a valid credit card; sufficient funds must be in the account to cover the cost of the stock and trading fees before a stock can be purchased. Stocks held in the trader's portfolio can be sold and the funds added to their account, minus the trading fee of course. Account funds are withdrawn by transference to a credit card account.

Trading is modeled as a shopping cart to which stocks can be added or removed for buying or selling until the trader decides to finalize the trade. When the trade is finalized, the portfolio and account are updated to reflect the trade and the cart is emptied.

Planned additions to the basic stock trading site include our own mutual fund, bonds, and a random number generator for selecting stocks to trade. 

Implementation

  1. Download project files and extract to a directory named \N341. A subdirectory named Project will contain the project files.
     
  2. Enter the browser address of: iu-uits-eiwp1.ads.iu.edu/username/N341/Project/Welcome.xml
  3. Register.
  4. Login.
  5. Logout.
  6. That's all it does for now.

Project parts - There are three main parts:

  1. ASP - The logic.
  2. XML/HTML - The user interface.
  3. Database - The data.

The project discussion presented a partial user interface for welcome, registration and log in of stock traders, these are to be completed. Additional interface elements and corresponding names used in the N342 logic implementations are listed below:

  1. User name not registered - usernameNotregistered.xml
  2. User name already logged in - usernameLoggedinAlready.xml
  3. Successful login - manageTrading.xml
  4. Attempt to login as another trader before logging out - logoutRequired.xml
  5. User password fails - userpasswordFails.xml
  6. User password missing - userpasswordMissing.xml
  7. Credit card number missing - creditcardMissing.xml
  8. Amount missing - amountMissing.xml
  9. User logged out - logoutSuccessFul.xml

 

Starting

User Interface - The following two files are a simple user interface for indicating user password missing. While it seems overly complex to have two files, the XML to invoke the HTML, it provides a method for implementing a consistent and modular user interface.

Missing.xml
<?xml-stylesheet type="text/xsl" 
               href="Missing.htm"?>
<top>
</top>
Missing.htm
<h1>User password missing</h1>

 

Step 1

  • A simple example
  1. Open FrontPage.
  2. Copy and paste the above.
  3. Save the above Missing.xml to a virtual drive (i.e. W:\N341\Project).
  4. Repeat steps 2 and 3 and save for Missing.htm
  5. Test by loading Missing.xml into the IE browser.

 

Building User Interfaces - include and call-template

We would like to build user interfaces from several small modules of common user interface elements. For the example at right, the top navigation of the stock trading program appears on every page of the site, it should be implemented once and shared by all pages.

To implement a modular error page for display when user password missing:

  1. topNavigation.htm - separate file for the top navigation interface element
     
  2. <xsl:include href="topNavigation.htm" /> - the include copies the file
     
  3. <xsl:call-template name="topNavigation" /> - the call-template generates the interface element
Missing.xml
<?xml-stylesheet type="text/xsl" 
               href="Missing.htm"?>
<top>
</top>

topNavigation.htm

<xsl:stylesheet 
  xmlns="http://www.w3.org/1999/xhtml" 
  xmlns:xsl="http://www.w3.org/1999/XSL/Transform" 
                     version="2.0">

<xsl:template name="topNavigation">
   <title>Stock Trader</title>
  <table cellSpacing="5" cellPadding="0" width="100%" 
           		bgColor="fuchsia" border="0">
    <tr>
      <td><A href="welcome.xml">Welcome</A></td>
      <td><A href="Register.xml">Register</A></td>
      <td><A href="Login.xml">Login</A></td>
      <td><A href="Logout.asp">Logout</A></td>
    </tr>
   </table>
</xsl:template>
</xsl:stylesheet>
Missing.htm
<xsl:stylesheet version="2.0" 
  xmlns:xsl="http://www.w3.org/1999/XSL/Transform" 
  xmlns="http://www.w3.org/1999/xhtml">

<xsl:include href="topNavigation.htm" />

<xsl:template match="/">
      <xsl:call-template name="topNavigation" />
       <h1>User password missing</h1>
</xsl:template>
</xsl:stylesheet>

 

Step 2

  • Modules  - Example using the topNavigation template module stored in another file. topNavigation.htm is already in the Project directory.
  1. In FrontPage, open File | New.
  2. Select the Code tab at the bottom left.
  3. Copy and paste Missing.htm,
  4. Save to a virtual drive (i.e. W:\N341\Project).
  5. Test by loading Missing.xml into the IE browser.
  • Duplicate the <xsl:call-template name="topNavigation" /> line several times and refresh the browser.

 

User Interface Standardization

Modules make it easier to implement and maintain user interfaces by breaking the interface into smaller pieces and provide a way of automatically generating a standard user interface across all pages.

One common Web page organization is Top, Left and Center (TLC) using two navigation bars: the top for site navigation and the left for application navigation; for example the Submit and Reset buttons for the registration and login applications. Page content, unique for the page, is placed in the center right of the page.

The following presents the Welcome page consisting of the four files:

  1. Welcome.xml - The entry file that loads Welcome.htm
     
  2. Welcome.htm - The page that displays the top and left navigation, and the content.
     
  3. topNavigation.htm - The top navigation.
     
  4. welcomeContent.htm - The content.

The preferred entry to the stock trading site is through a welcome page named Welcome.xml which is listed with supporting files below. The welcome page should serve as a model for implementing other files listed above needed for the limited user interface implemented for this assignment.

For most project pages, the only significant change required is to the content of the page implemented by the "welcomeContent.htm" file in the example.

Welcome.xml

<?xml-stylesheet type="text/xsl" 
               href="welcome.htm"?>
<top>
</top>

topNavigation.htm

<xsl:stylesheet 
  xmlns="http://www.w3.org/1999/xhtml" 
  xmlns:xsl="http://www.w3.org/1999/XSL/Transform" 
                     version="2.0">

<xsl:template name="topNavigation">
  <table cellSpacing="5" cellPadding="0" width="100%" 
           		            bgColor="fuchsia" border="0">
    <tr>
      <td><A href="welcome.xml">Welcome</A></td>
      <td><A href="Register.xml">Register</A></td>
      <td><A href="Login.xml">Login</A></td>
      <td><A href="Logout.asp">Logout</A></td>
    </tr>
   </table>
</xsl:template>
</xsl:stylesheet>

welcomeContent.htm

<xsl:stylesheet 
  xmlns="http://www.w3.org/1999/xhtml"
  xmlns:xsl="http://www.w3.org/1999/XSL/Transform" 
  version="2.0">

<xsl:template name="welcomeContent">
 <h1 align="center">Welcome to Stock Trader</h1>
 <UL>
  <LI>
   <DIV align="left">Register to open an account.</DIV>
  </LI>
  <LI>
   <DIV align="left">Login to access your account.</DIV>
  </LI>
 </UL>
</xsl:template>
</xsl:stylesheet>
Welcome.htm
<xsl:stylesheet version="2.0" 
  xmlns:xsl="http://www.w3.org/1999/XSL/Transform" 
  xmlns="http://www.w3.org/1999/xhtml">

<xsl:include href="topNavigation.htm" />
<xsl:include href="welcomeContent.htm" />

<xsl:template name="leftNavigation">
  <table border="0" cellpadding="10" 
             cellspacing="0" align="left">
   <tr><td></td></tr>
   <tr><td></td></tr>
  </table>
</xsl:template>

<xsl:template match="/">
 <html>
  <head>
   <link rel="stylesheet" type="text/css" href="basic.css" />
   <title>Stock Trader</title>
  </head>
  <body>
   <center>
    <table border="0" cellpadding="0" cellspacing="0" 
               width="100%">
     <tr>
      <td></td>
      <td>
	<!-- Top Navigation -->
	<center>
               <xsl:call-template name="topNavigation" />
             </center>
      </td>
     </tr>
     <tr>
      <td><br/></td>
     </tr>
    <tr>
     <td>
      <!-- Left Navigation -->
      <xsl:call-template name="leftNavigation" />
     </td>
     <td>
       <!-- Content -->
       <center>
         <xsl:call-template name="welcomeContent" />
       </center>
     </td>
    </tr>
   </table>
  </center>
 </body>
</html>
</xsl:template>
</xsl:stylesheet>

 

Step 3

  • Standard navigation - The Welcome page files listed above are already located in the Project directory. For practice, we will modify the Missing files for the user password missing page.
  1. Modify the Missing.htm from Step 2 to include and call the welcomeContent template of welcomeContent.htm.
  2. Test by refreshing Missing.xml in the browser.
    • If the file fails to refresh in IE, try: Tools | Internet Options | Temporary Internet Files | Settings | Every Visit to Page
       

    We'll modify the Missing.htm file to follow the user interface organization established by the Welcome.htm file.

     

  3. Copy and paste the text of Welcome.htm to overwrite the text Missing.htm
  4. Modify the Missing.htm:
    1. Display <h1>User password missing</h1> instead of calling the welcomeContent template.
    2. Delete the statement: <xsl:include href="welcomeContent.htm" />
  5. Test by loading Missing.xml into the browser.
  1. Modify the leftNavigation template in Missing.htm to include two HREF links between the each of the <td></td>:
    1. your IUS homepage
    2. Welcome.xml page
  2. Test by loading Missing.xml into the browser.

 

Debugging syntax errors

HTML/XML/XSL syntax errors can be hard to locate from the error message given by the browser. Use the following files to practice locating the file and line number where an error occurs.

Missing.xml
<?xml-stylesheet type="text/xsl" 
               href="Missing.htm"?>
<top>
</top>

topNavigation.htm

<xsl:stylesheet 
  xmlns="http://www.w3.org/1999/xhtml" 
  xmlns:xsl="http://www.w3.org/1999/XSL/Transform" 
                     version="2.0">

<xsl:template name="topNavigation">
   <title>Stock Trader</title>
  <table cellSpacing="5" cellPadding="0" width="100%" 
           		bgColor="fuchsia" border="0">
    <tr>
      <td><A href="welcome.xml">Welcome</A></td>
      <td><A href="Register.xml">Register</A></td>
      <td><A href="Login.xml">Login</A></td>
      <td><A href="Logout.asp">Logout</A></td>
    </tr>
   </table>
</xsl:template>
</xsl:stylesheet>
Missing.htm
<xsl:stylesheet version="2.0" 
  xmlns:xsl="http://www.w3.org/1999/XSL/Transform" 
  xmlns="http://www.w3.org/1999/xhtml">

<xsl:include href="topNavigation.htm" />

<xsl:template match="/">
      <xsl:call-template name="topNavigation" />
       <h1>User password missing</h1>
</xsl:template>
</xsl:stylesheet>

Debugging syntax errors

  • Syntax errors can most easily be located using msxsl.
  • For practice, we will create an error in the topNavigation.htm file.
  1. Download and save msxsl.exe to the W:\N341\Project directory.
  2. Copy and paste the three files into W:\N341\Project.
  3. In FrontPage, open W:\N341\Project\topNavigation.htm and change the </tr> to </tr, deleting the >.
  4. Open a Command Prompt (in Accessories folder) and, to open missing.xml in IE, enter:

    W:
    cd \N341\Project
    missing.xml

    The browser will display an error message:

    The XML page cannot be displayed

    Cannot view XML input using XSL style sheet. Please correct the error and then click the Refresh button, or try again later.

    A name contained an invalid character.

    The error message is not very helpful.
     

  5. To determine the offending file, in the Command Prompt window, enter:

    msxsl missing.xml missing.htm

    Error occurred while compiling stylesheet 'missing.htm'.

    Code: 0x80004005
    Error while parsing "file:///W:/N341/Project/topNavigation.htm". A name contained an invalid character.

    topNavigation.htm contains the error.
     

  6. Now to drill down into the offending file, in the Command Prompt window, enter:

    msxsl missing.xml topNavigation.htm

    Error occurred while parsing document.

    Code: 0xc00ce505
    URL: file:///W:/N341/Project/topNavigation.htm
    Line: 10
    Column: 3
    A name contained an invalid character.

    Line and column identified.

Assignment

The following project interface files have already been implemented similar to the model from User Interface Standardization described above and Step 3, parts 1-5 above.

  1. Welcome - Welcome.htm
  2. User name not registered - usernameNotregistered.htm
  3. User name already logged in - usernameLoggedinAlready.htm
  4. Successful login - manageTrading.htm
  5. Attempt to login as another trader before logging out - logoutRequired.htm
  6. User password fails - userpasswordFails.htm
  7. User password missing - userpasswordMissing.htm
  8. Amount missing - amountMissing.htm
  9. User logged out - logoutSuccessful.htm

Part 1

  1. Define bottomNavigation.htm with a template named bottomNavigation to:
    • Display a clickable email address for inquiries or problem report, use your email address.
    • Form with a text box for entering a stock symbol and linking to the Google, Yahoo or other stock quote page.
    • Display your name.
    • Copyright notice.
       
  2. Modify each of the above 1-9 files to:
    • Display the bottom navigation centered at the end (last few lines) of the page.
      • Include bottomNavigation.htm
      • Call the bottomNavigation template.
         
  3. Test each. View video

    Remember that each of the 9 files have a companion XML file.

    For example, Welcome.htm can be tested by any of the following:

    1. Browser:
       
      • iu-uits-eiwp1.ads.iu.edu/username/N341/Project/Welcome.xml
         
      • W:\N341\Project\Welcome.xml
         
    2. Command prompt:
       
      • msxsl Welcome.xml Welcome.htm
         
      • Welcome.xml

Hints:

Part 2

Eventually, portfolio information will be integrated into the trading site; for now, we will practice by implementing a stand-alone application to display the portfolio.

Copy and save the following data to a file named HW3-2.xml in the Project directory.

<?xml version="1.0"?>
<?xml-stylesheet type="text/xsl" href="HW3-2-1.htm"?>
<Portfolio>
    <STOCKID>
	<ID>Ray</ID><SYMBOL>IBM</SYMBOL><PRICE>10</PRICE>
    </STOCKID>
    <STOCKID>
	<ID>Ray</ID><SYMBOL>MSFT</SYMBOL><PRICE>100</PRICE>
    </STOCKID>
    <STOCKID>
	<ID>Harold</ID><SYMBOL>FORD</SYMBOL><PRICE>15</PRICE>
    </STOCKID>
    <STOCKID>
	<ID>Robin</ID><SYMBOL>UAL</SYMBOL><PRICE>230</PRICE>
    </STOCKID>
    <STOCKID>
	<ID>Robin</ID><SYMBOL>FORD</SYMBOL><PRICE>100</PRICE>
    </STOCKID>
</Portfolio>

  1. Implement the XSL to display the above Portfolio XML data as the table below using for-each (see example).

    1. Add a hyperlink (e.g. Google or Yahoo) to each SYMBOL to look up information on the stock (see example).
    2. Save the XSL file in the Project directory as: HW3-2-1.htm
    3. Test by loading HW3-2.xml into the browser.

       
      ID Symbol
      Ray IBM
      Ray MSFT
      Harold FORD
      Robin UAL
      Robin FORD

     

  2. Implement JavaScript to load the Portfolio XML and generate the table above.

    This is the essence of Asynchronous Javascript and XML (AJAX) in which Javascript loads a file into a DOM tree and displays selected element values in the user interface.

    1. Add a hyperlink (e.g. Google or Yahoo) to each SYMBOL to look up information on the stock.
    2. Save the JavaScript file in the Project directory as: HW3-2-2.htm
    3. Test by loading HW3-2-2.htm into the browser.

    The below example illustrates the essentials of loading an XML file into JavaScript and accessing the DOM tree structure.

    The process is similar to loading a text file (remember the ; delimited file of HW1). However, XML is automatically parsed into a tree, we only need to access the proper parts of the tree.

    New concepts:

    • var xmlDoc = new ActiveXObject("Microsoft.XMLDOM");  
      xmlDoc.async = false;
      xmlDoc.loadXML(req.responseText);
    Parses the XML from the file HW3-2.xml into a DOM tree.
    • xmlDoc.getElementsByTagName('Portfolio/STOCKID')
    Returns an array of the 5 <Portfolio/STOCKID> elements.
    • xmlDoc.getElementsByTagName('Portfolio/STOCKID').length
    Length of the array is 5.
    • xmlDoc.getElementsByTagName('Portfolio/STOCKID/ID')[2]
    Returns the index 2 <Portfolio/STOCKID/ID> element.
    • xmlDoc.getElementsByTagName('Portfolio/STOCKID/ID')[2].text
    Returns the index 2 <Portfolio/STOCKID/ID> element text, Harold.
    <?xml version="1.0"?>
    <?xml-stylesheet type="text/xsl" href="HW3-2-1.htm"?>
    <Portfolio>
        <STOCKID>
    	<ID>Ray</ID><SYMBOL>IBM</SYMBOL><PRICE>10</PRICE>
        </STOCKID>
        <STOCKID>
    	<ID>Ray</ID><SYMBOL>MSFT</SYMBOL><PRICE>100</PRICE>
        </STOCKID>
        <STOCKID>
    	<ID>Harold</ID><SYMBOL>FORD</SYMBOL><PRICE>15</PRICE>
        </STOCKID>
        <STOCKID>
    	<ID>Robin</ID><SYMBOL>UAL</SYMBOL><PRICE>230</PRICE>
        </STOCKID>
        <STOCKID>
    	<ID>Robin</ID><SYMBOL>FORD</SYMBOL><PRICE>100</PRICE>
        </STOCKID>
    </Portfolio>

    Example

    • Save the following as HW3Example.htm in same directory as HW3-2.xml
    • Then test by loading HW3Example.htm in the browser.
       
    Portfolio contents:<br/>

    <span id="displayPortfolio">.</span>

    <script language="JavaScript">
       var req = new ActiveXObject("Microsoft.XMLHTTP");       // For IE only;

       req.open("GET", "HW3-2.xml", false);
       req.send(null);

       var xmlDoc = new ActiveXObject("Microsoft.XMLDOM");
       xmlDoc.async = false;
       xmlDoc.loadXML( req.responseText );

       result="";

       for(i=0; i<xmlDoc.getElementsByTagName('Portfolio/STOCKID').length; i++) {

           result=result+xmlDoc.getElementsByTagName('Portfolio/STOCKID/ID')[i].text;
           result=result+"|";
           result=result+"<a href='http://www.google.com/search?q="+
                                xmlDoc.getElementsByTagName('Portfolio/STOCKID/SYMBOL')[i].text+"'>"+   
                                xmlDoc.getElementsByTagName('Portfolio/STOCKID/SYMBOL')[i].text+"</a>";          
           result=result+"|";
           result=result+xmlDoc.getElementsByTagName('Portfolio/STOCKID/PRICE')[i].text;
           result=result+"<br/>";

       }

       displayPortfolio.innerHTML = result;

    </script>

    Results:

    Portfolio contents:
    Ray|IBM|10
    Ray|MSFT|100
    Harold|FORD|15
    Robin|UAL|230
    Robin|FORD|100

     

  3. Google Charts produce high-quality chart images that can be embedded in HTML.

    For example, the following hand-coded HTML:

    <img src="http://chart.apis.google.com/chart?chs=250x100&chd=t:60,40&cht=p3&chl=Hello|World"/>

    produces the image:

    Add a hand-coded Google chart to the JavaScript above, HW3-2-2.htm, that displays each SYMBOL and summed PRICE from the Portfolio table. In a later homework we will dynamically generate charts from live data.

    A pie chart should appear similar to:

    Note that the Ford SYMBOL appears twice in the Portfolio data ($15 and $100) but only once in the pie chart and the PRICE is summed to $115.

     

Hints:

Turn in - Due before class on the date listed in the syllabus.

  1. OnCourse Drop Box
    1. Compress the Project folder containing the homework files.
      • In Windows Explorer, right-click on the Project folder.
      • Click Send to then click Compressed (zipped) Folder.
      • Project.zip will be created.
    2. Upload Project.zip to your CSCI N341 OnCourse Drop Box using the Display Name of HW3.
       
  2. Web server
    1. Copy files to W:\N341\Project drive
    2. Test in IE. The Welcome.xml is a default page.
      • In browser address enter: http://iu-uits-eiwp1.ads.iu.edu/username/N341/Project/Welcome.xml
         
  3. Email notice of completion to rwisman@ius.edu with subject: YOUR NAME - N341 HW3 - username