<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN">

<HTML>
  <HEAD>
    <TITLE>Dynamically Generated XSLT
    Michael Floyd
    January 2001
    </TITLE>
  </HEAD>
  
  <BODY ONLOAD="Parse()">

   <SCRIPT>

   function Parse()
   {

    // Create a Document object and report the results.
    // The following instantiate  different versions of the MSXML parser
    // Version 1  ProgID: Microsoft.XMLDOM
    // Version 2  ProgID: MSXML2.DOMDocument
    // Version 3  ProgID: MSXML2.DOMDocument.3.0

   var schemaDocument = new ActiveXObject("MSXML2.DOMDocument");
   var xslDocument = new ActiveXObject("MSXML2.DOMDocument");

    schemaDocument.load("schema.xml");
    if (schemaDocument.documentElement == null)
       alert("Error loading schema document..."); 

    else {
       var skeletonXSL = '<?xml version="1.0"?><xsl:stylesheet xmlns:xsl="http://www.w3.org/TR/WD-xsl" 
             xmlns="http://www.w3.org/TR/REC-html40" result-ns=""></xsl:stylesheet>';
       xslDocument.loadXML(skeletonXSL);

       // Create the Root Template
       var templateElem = xslDocument.createElement("xsl:template");
       xslDocument.documentElement.appendChild(templateElem);
       xslDocument.documentElement.lastChild.setAttribute("match", "/");

       var htmlElem = xslDocument.createElement("HTML");
       xslDocument.documentElement.lastChild.appendChild(htmlElem);
       var bodyElem = xslDocument.createElement("BODY");
       htmlElem.appendChild(bodyElem);
       
       // Link in a CSS style sheet
       var linkTag = xslDocument.createElement("LINK");
       linkTag.setAttribute("REL","STYLESHEET");
       linkTag.setAttribute("TYPE","text/css");
       linkTag.setAttribute("href","g:/inetpub/wwwroot/rocket/stylesheets/themes/traditional/ie5/traditional.css");
       bodyElem.appendChild(linkTag);
 
       var tags = schemaDocument.documentElement.getElementsByTagName("ElementType");
       for (i = 0; i < tags.length; i++)
       {
          node = tags.item(i);
          if (node.getAttribute("name") == "article")           
          {
             elements = node.childNodes;

             // ignore 1st two logo elements and last copyright element
             for (i = 2; i < elements.length - 1; i++){
                element = elements.item(i);
                if (element.getAttribute("type") == "headline") {
                   cssStyle = "BoxCopy";
                }
                else {
                   cssStyle = element.getAttribute("type");
                }
                xmlElem = "article/" + element.getAttribute("type");

                // Create a DIV tag to apply CSS styles
                var divElem = xslDocument.createElement("DIV");
                divElem.setAttribute("CLASS", cssStyle);
                bodyElem.appendChild(divElem);

                if (element.getAttribute("type") == "aBody") {
                   xslApplyTemplates = xslDocument.createElement("xsl:apply-templates");
                   xslApplyTemplates.setAttribute("select", xmlElem);
                   divElem.appendChild(xslApplyTemplates);
                }
                else {
                 
                // Display the headline
                var xslValueOf = xslDocument.createElement("xsl:value-of");
                xslValueOf.setAttribute("select", xmlElem);
                divElem.appendChild(xslValueOf);
                }
             }
          }
       }

       // *** Add additional templates
       
       // aBody Template
       templateElem = xslDocument.createElement("xsl:template");
       templateElem.setAttribute("match", "aBody");
       xslDocument.documentElement.appendChild(templateElem);
       
       var pTag = xslDocument.createElement("P");
       xslApplyTemplates = xslDocument.createElement("xsl:apply-templates");
       templateElem.appendChild(pTag);
       pTag.appendChild(xslApplyTemplates);
       
       // para1 Template
       templateElem = xslDocument.createElement("xsl:template");
       templateElem.setAttribute("match", "para1");
       xslDocument.documentElement.appendChild(templateElem);
       
       var pTag = xslDocument.createElement("P");
       xslApplyTemplates = xslDocument.createElement("xsl:apply-templates");
       templateElem.appendChild(pTag);
       pTag.appendChild(xslApplyTemplates);
       
       // para Template
       templateElem = xslDocument.createElement("xsl:template");
       templateElem.setAttribute("match", "para");
       xslDocument.documentElement.appendChild(templateElem);
       
       var pTag = xslDocument.createElement("P");
       xslApplyTemplates = xslDocument.createElement("xsl:apply-templates");
       templateElem.appendChild(pTag);
       pTag.appendChild(xslApplyTemplates);

       // para2 Template
       templateElem = xslDocument.createElement("xsl:template");
       templateElem.setAttribute("match", "para2");
       xslDocument.documentElement.appendChild(templateElem);
       
       var pTag = xslDocument.createElement("P");
       xslApplyTemplates = xslDocument.createElement("xsl:apply-templates");
       templateElem.appendChild(pTag);
       pTag.appendChild(xslApplyTemplates);

       // dropCap Template
       templateElem = xslDocument.createElement("xsl:template");
       templateElem.setAttribute("match", "dropCap");
       xslDocument.documentElement.appendChild(templateElem);
       
       var divElem = xslDocument.createElement("DIV");
       divElem.setAttribute("CLASS", "dropCap");
       templateElem.appendChild(divElem);

       xslApplyTemplates = xslDocument.createElement("xsl:apply-templates");
       divElem.appendChild(xslApplyTemplates);

       // Template to display italics
       templateElem = xslDocument.createElement("xsl:template");
       templateElem.setAttribute("match", "italic");
       xslDocument.documentElement.appendChild(templateElem);
       
       var italTag = xslDocument.createElement("I");
       xslApplyTemplates = xslDocument.createElement("xsl:apply-templates");
       templateElem.appendChild(italTag);
       italTag.appendChild(xslApplyTemplates);

       // Template to display italics
       templateElem = xslDocument.createElement("xsl:template");
       templateElem.setAttribute("match", "bold");
       xslDocument.documentElement.appendChild(templateElem);
       
       var boldTag = xslDocument.createElement("B");
       xslApplyTemplates = xslDocument.createElement("xsl:apply-templates");
       templateElem.appendChild(boldTag);
       boldTag.appendChild(xslApplyTemplates);
       
       // Template to display hyperlinks
       templateElem = xslDocument.createElement("xsl:template");
       templateElem.setAttribute("match", "link");
       xslDocument.documentElement.appendChild(templateElem);
       
       var xslElement = xslDocument.createElement("xsl:element");
       xslElement.setAttribute("name","A");
       templateElem.appendChild(xslElement);
             
       var xslAttribute = xslDocument.createElement("xsl:attribute");
       xslAttribute.setAttribute("name","href");
       xslElement.appendChild(xslAttribute);
       
       xslValueOf = xslDocument.createElement("xsl:value-of");
       xslValueOf.setAttribute("select","@href");
       xslAttribute.appendChild(xslValueOf);

       xslApplyTemplates = xslDocument.createElement("xsl:apply-templates");
       xslElement.appendChild(xslApplyTemplates);

       // Add the text() template **required only by MSXML*** 
       templateElem = xslDocument.createElement("xsl:template");
       templateElem.setAttribute("match", "text()");
       xslDocument.documentElement.appendChild(templateElem);
       
       xslValueOf = xslDocument.createElement("xsl:value-of");
       templateElem.appendChild(xslValueOf);

       // Depending upon permissions, this call may or may not work. If
       // you receive a file permissions error, rename this file with a .hta
       // file extension and rerun.
       
       xslDocument.save("stylesheet.xsl");
       alert("Document Saved in stylesheet.xml");

    } // else
   } // Parse
   
   </SCRIPT> 
    
  </BODY>
</HTML>