<!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 xmlDocument = new ActiveXObject("Microsoft.XMLDOM");
      var xslDocument = new ActiveXObject("MSXML2.DOMDocument");
//    var xslDocument = new ActiveXObject("MSXML2.DOMDocument.3.0");

    xslDocument.load("template.xsl");
    if (xslDocument.documentElement == null)
       alert("Document is null"); 

    else {
       // 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);
 
       // Create a DIV tag to apply CSS styles
       var divElem = xslDocument.createElement("DIV");
       divElem.setAttribute("CLASS", "BoxCopy");
       bodyElem.appendChild(divElem);
       
       // Get the data from the XML document
       var xslValueOf = xslDocument.createElement("xsl:value-of");
       xslValueOf.setAttribute("select", "article/headline");
       divElem.appendChild(xslValueOf);

       // Display the deck
       divElem = xslDocument.createElement("DIV");
       divElem.setAttribute("CLASS", "deck");
       bodyElem.appendChild(divElem);

       xslValueOf = xslDocument.createElement("xsl:value-of");
       xslValueOf.setAttribute("select", "article/deck");
       divElem.appendChild(xslValueOf);

       // Display the byline
       divElem = xslDocument.createElement("DIV");
       divElem.setAttribute("CLASS", "byline");
       bodyElem.appendChild(divElem);

       xslValueOf = xslDocument.createElement("xsl:value-of");
       xslValueOf.setAttribute("select", "article/byline");
       divElem.appendChild(xslValueOf);

       // Display the article body
       divElem = xslDocument.createElement("DIV");
       divElem.setAttribute("CLASS", "aBody");
       bodyElem.appendChild(divElem);

       xslApplyTemplates = xslDocument.createElement("xsl:apply-
          templates");
       xslApplyTemplates.setAttribute("select", "article/aBody");
       divElem.appendChild(xslApplyTemplates);
       
       // *** 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>