<?xml version="1.0"?>
<!--
    Multiple File Viewer Combiner
    Copyright (c) 1999 by XMLNews.org    
    
    This stylesheet takes as input an XML file of filenames for data files and
    stylesheets and renders a control frame for dynamically refreshing the
    screen with the XSL stylesheets applied selectively to the XML files.
    
    Date:        1999-04-14 10:00
    XSL Version: Microsoft IE5 5.00.2014.0216

  CAVEAT - The XSL syntax used in this file follows the Microsoft
           Internet Explorer 5 conventions and is not necessarily 
           representative of any finalized or authorized recommendation.

The description of a single collection of files (note that when the collection
is loaded, the first data file is displayed using the first stylesheet file):

     <!ELEMENT files  ( data+, ss-xsl+ )>
     <!ELEMENT data   ( #PCDATA )>
     <!ELEMENT ss-xsl ( #PCDATA )>
     
  Example:
  
     <?xml version="1.0"?>
     <?xml:stylesheet href="support/controls.msxsl" type="text/xsl"?>
     <files>
     <data>eastern.xml</data>
     <data>western.xml</data>
     <ss-xsl>division.msxsl</ss-xsl>
     <ss-xsl>conference.msxsl</ss-xsl>
     <ss-xsl>points.msxsl</ss-xsl>
     </files>
-->

<xsl:stylesheet
       xmlns:xsl="http://www.w3.org/TR/WD-xsl"
       xmlns="http://www.w3.org/TR/REC-html40"
       result-ns="">

<!--default behaviours-->

<xsl:template match="*"><xsl:apply-templates/></xsl:template>
<xsl:template match="text()"><xsl:value-of select="."/></xsl:template>

<!--specific behaviour-->

<xsl:template match="/"><xsl:apply-templates select="/files"/></xsl:template>

<xsl:template match="/files">   <!--handle all processing as a select events
                                     without use of match pattern templates-->
<HTML>
  <HEAD>
    <STYLE>
      BODY { font-family:Arial; font-size:10pt; color:#4682b4; }
      .instructions { font-style:italic; color:gray; margin-left:.5em; }
      .headline { background-color:#4682b4; color:white; 
                  font-family:Arial Black; font-size:16pt;
                  text-align:center; }
      .group { font-family:Arial Black; font-size:14pt; 
               margin-top:.5em; margin-left:.5em; margin-bottom:.5em; }
      .button { font-family:Arial; font-size:10pt; font-weight:bold;
                text-align:center; color:gray; }
      .arrow { font-family:Courier }
    </STYLE>
  </HEAD>


  <BODY onload="init()">
 
  <SCRIPT>
    var source;
    var style;
    var sourceURL;
    var styleURL;
    var viewingSSsrc;
    var ssType;
    
    function showMessage( message )       <!--render a message in the window-->
     {
      parent.results.displayXSL( message );
     }

    function refreshResults(ssChangeType) <!--render combo in results window-->
     {
      var message = "";
      ssType = ssChangeType;            <!--remember for when data changes-->
      
      if( source.parseError != 0 )
        message = "<br/>Problem loading XML file: " + sourceURL +
                  "<ul><li>" + source.parseError.reason + "</li></ul>";

      if( style.parseError != 0 )
        message = message + "<br/>Problem loading stylesheet file: " + 
                  styleURL +
                  "<ul><li>" + style.parseError.reason + "</li></ul>";

      if( message != "" )
        showMessage( message  );
      else if( ssType == "CSS" )        <!--ask results window to render-->
        parent.results.displayCSS(styleURL,source,sourceURL);
      else if (style.documentElement)   <!--a XSL stylesheet is defined-->
        if (source.documentElement)     <!--an XML data file is defined--> 
          parent.results.displayXSL(source.transformNode(style));
     }

    function changeXML(xmldoc)  <!--change the data file being rendered-->
     {
      if (viewingSSsrc)        <!--revert to user selected stylesheet-->
       {                           <!--after using stylesheet's stylesheet-->
        styleURL = sourceURL;   <!--name of stylesheet previously selected-->
        style.load(styleURL);   <!--bring it into the DOM model-->
        viewingSSsrc = false;  <!--no longer viewing the stylesheet -->
       }
      sourceURL = xmldoc;       <!--name of document being requested-->
      source.load(sourceURL);   <!--bring it into the DOM model-->

      refreshResults(ssType);
    }

    function changeSS(xsldoc, type)  <!--change the stylesheet being ref'd-->
    {
      if (viewingSSsrc)        <!--in process of looking at stylesheets-->
       {
        sourceURL = xsldoc;     <!--render contents of new stylesheet-->
        source.load(sourceURL);
       }
      else                      <!--in process of looking at XML data-->
       {
        styleURL = xsldoc;      <!--render current data using new stylesheet-->
        style.load(styleURL);
       }

      showMessage( "Rendering '" + sourceURL + "' with stylesheet '" +
                   styleURL + "'" );
      refreshResults(type);
    }

    function viewSS()           <!--view the stylesheet itself-->
    {
      if (!viewingSSsrc)        <!--not already doing so-->
      {
        changeXML(styleURL);    <!--use the existing stylesheet as data-->
        changeSS("support/raw-xml.msxsl", "XSL");<!--hardwire raw stylesheet-->
        viewingSSsrc = true;
      }
    }

  </SCRIPT>

  <SCRIPT>
    // ----- Scripts to activate buttons ------
    var oldXMLitem;
    var oldXSLitem;
    var oldCSSitem;

    function over(item)         <!--the pointer is over a file item-->
     {
      item.style.color = "#4682b4";
      item.style.textDecoration="underline";
     }

    function out(item)          <!--the pointer has left a file item-->
     {
      item.style.color = "gray";
      if( item != oldXMLitem )   <!--the XML escaped ampersands for AND are-->
       {                         <!--not interpreted properly, so the if-->
        if( item != oldXSLitem ) <!--construct is explicit-->
         {
          if( item != oldCSSitem )
           {
            item.style.textDecoration="";
           }
         }
       }
     }

    function select(group, item)    <!--the user has selected an item-->
     {
      if (group == "XML")
       {
        oldXMLitem.style.textDecoration = "";
        oldXMLitem = item;
       } else if (group == "XSL")
       {
        oldXSLitem.style.textDecoration = "";
        if( oldCSSitem )
         {
          oldCSSitem.style.textDecoration = "";
         }
        oldXSLitem = item;
       } else if (group == "CSS")
       {
        oldXSLitem.style.textDecoration = "";
        oldCSSitem.style.textDecoration = "";
        oldCSSitem = item;
       }
      item.style.textDecoration = "underline";
     }

    // called by parent frame when the whole frameset is ready
    function init()
    {
      oldXMLitem = document.all.item("first-XML-item"); <!--set first file-->
      oldXMLitem.style.textDecoration = "";
      select("XML", oldXMLitem);
      oldCSSitem = document.all.item("first-CSS-item");
      if( oldCSSitem )
       {
        oldCSSitem.style.textDecoration = "";
       }
      oldXSLitem = document.all.item("first-XSL-item"); <!--and first sheet-->
      oldXSLitem.style.textDecoration = "";
      select("XSL", oldXSLitem);
    
      source = new ActiveXObject("Microsoft.XMLDOM"); <!--create containers-->
      style = new ActiveXObject("Microsoft.XMLDOM");
      
      source.async = false;
      style.async = false;
                                            <!--first application of sheets-->
      changeXML("<xsl:apply-templates select="data[0]"/>");
      changeSS("<xsl:apply-templates select="ss-xsl[0]"/>", "XSL");
    }
  </SCRIPT>

    <DIV CLASS="instructions">
      (Select below an XML file and an XSL stylesheet
      with which to view it.  The results will appear in the frame at right.)
    </DIV>
    
    <TABLE>
    <TR valign="top">               <!--table headers-->
    <TD>
    <DIV CLASS="group">XML<xsl:entity-ref name="nbsp"/>File
    </DIV>
    </TD>
    <TD bgcolor="gray" width="1"/>
    <TD>
    <DIV CLASS="group">XSL<xsl:entity-ref name="nbsp"/>Style
    </DIV>
    </TD>
    </TR>
    
    <TR>                                        <!--table contents-->
    <TD valign="top">                           <!--first column has XML-->
     <xsl:for-each select="data[0]">
      <xsl:element name="DIV">
       <xsl:attribute name="CLASS">button</xsl:attribute>
       <xsl:attribute name="ID">first-XML-item</xsl:attribute>
       <xsl:attribute name="onMouseOver">over(this)</xsl:attribute>
       <xsl:attribute name="onMouseOut">out(this)</xsl:attribute>
       <xsl:attribute name="onClick">changeXML("<xsl:apply-templates/>");
                                     select("XML",this)</xsl:attribute>
        <xsl:apply-templates/>
      </xsl:element>
     </xsl:for-each>
     <xsl:for-each select="data[index() $gt$ 0]">
      <xsl:element name="DIV">
       <xsl:attribute name="CLASS">button</xsl:attribute>
       <xsl:attribute name="onMouseOver">over(this)</xsl:attribute>
       <xsl:attribute name="onMouseOut">out(this)</xsl:attribute>
       <xsl:attribute name="onClick">changeXML("<xsl:apply-templates/>");
                                     select("XML",this)</xsl:attribute>
        <xsl:apply-templates/>
      </xsl:element>
     </xsl:for-each>
    </TD>

    <TD bgcolor="gray" width="1"/>              <!--second column filler-->

    <TD valign="top">                           <!--third column XSL files-->
     <xsl:for-each select="ss-xsl[0]">
      <xsl:element name="DIV">
       <xsl:attribute name="CLASS">button</xsl:attribute>
       <xsl:attribute name="ID">first-XSL-item</xsl:attribute>
       <xsl:attribute name="onMouseOver">over(this)</xsl:attribute>
       <xsl:attribute name="onMouseOut">out(this)</xsl:attribute>
       <xsl:attribute name="onClick">changeSS("<xsl:apply-templates/>", "XSL");
                                     select("XSL",this)</xsl:attribute>
        <xsl:apply-templates/>
      </xsl:element>
     </xsl:for-each>
     <xsl:for-each select="ss-xsl[index() $gt$ 0]">
      <xsl:element name="DIV">
       <xsl:attribute name="CLASS">button</xsl:attribute>
       <xsl:attribute name="onMouseOver">over(this)</xsl:attribute>
       <xsl:attribute name="onMouseOut">out(this)</xsl:attribute>
       <xsl:attribute name="onClick">changeSS("<xsl:apply-templates/>", "XSL");
                                     select("XSL",this)</xsl:attribute>
        <xsl:apply-templates/>
      </xsl:element>
     </xsl:for-each>
    </TD>
    </TR>
    </TABLE>

    <HR/>
    
    <DIV CLASS="instructions">
      Data file source ("raw-xml.msxsl") or data file hierarchy
      ("showtree.msxsl") or stylesheet source can be viewed 
      by clicking here:
    </DIV>

    <DIV CLASS="group">
      <DIV CLASS="button"
           onMouseOver="over(this)"
           onMouseOut="out(this)"
           onClick='changeSS( "support/raw-xml.msxsl", "XSL" ); 
                    select("XSL",this)'>
        Raw XML file
      </DIV>
    </DIV>

    <DIV CLASS="group">
      <DIV CLASS="button"
           onMouseOver="over(this)"
           onMouseOut="out(this)"
           onClick='changeSS( "support/showtree.msxsl", "XSL" ); 
                    select("XSL",this)'>
        XML file hierarchy
      </DIV>
    </DIV>

    <DIV CLASS="group">
      <DIV CLASS="button"
           onMouseOver="over(this)"
           onMouseOut="out(this)"
           onClick='viewSS(); select("XML",this)'>
        Raw XSL stylesheet
      </DIV>
    </DIV>

    <DIV CLASS="instructions">
      After viewing a stylesheet, click on an XML data file above 
      to resume viewing XML data.
    </DIV>
    <HR/>
    
  </BODY>
</HTML>

</xsl:template>

</xsl:stylesheet>