#!/usr/bin/perl

$Type{"department"}="param";
$Default{"department"}=q();

$Type{"homeLabel"}="param";
$Default{"homeLabel"}=q(Home);

$Type{"homeURL"}="param";
$Default{"homeURL"}=q(/);

$Type{"homeWords"}="param";
$Default{"homeWords"}=q(Home);

$Type{"institution"}="param";
$Default{"institution"}=q();

$Type{"parentURL"}="param";
$Default{"parentURL"}=q();

$Type{"parentWords"}="param";
$Default{"parentWords"}=q(Parent Institution);

$Type{"searchURL"}="param";
$Default{"searchURL"}=q();

$Type{"feedbackURL"}="param";
$Default{"feedbackURL"}=q();

$Type{"alignNavigationPanel"}="param";
$Default{"alignNavigationPanel"}=q(right);

$Type{"bottomNavigationPanel"}="param";
$Default{"bottomNavigationPanel"}=q(true);

$Type{"htmlTitlePrefix"}="param";
$Default{"htmlTitlePrefix"}=q();

$Type{"linkPanel"}="param";
$Default{"linkPanel"}=q(true);

$Type{"consecutiveFNs"}="param";
$Default{"consecutiveFNs"}=q(false);

$Type{"autoEndNotes"}="param";
$Default{"autoEndNotes"}=q(false);

$Type{"oddWeaveLite"}="param";
$Default{"oddWeaveLite"}=q(false);

$Type{"parIndent"}="param";
$Default{"parIndent"}=q(1em);

$Type{"biblioStyle"}="param";
$Default{"biblioStyle"}=q();

$Type{"DOIResolver"}="param";
$Default{"DOIResolver"}=q();

$Type{"parSkip"}="param";
$Default{"parSkip"}=q(0pt);

$Type{"separator"}="param";
$Default{"separator"}=q(
  <xsl:text> </xsl:text>);

$Type{"treestyle"}="param";
$Default{"treestyle"}=q(googlechart);

$Type{"filePerPage"}="param";
$Default{"filePerPage"}=q(false);

$Type{"viewPortWidth"}="param";
$Default{"viewPortWidth"}=q(1200);

$Type{"viewPortHeight"}="param";
$Default{"viewPortHeight"}=q(1700);

$Type{"footnoteBackLink"}="param";
$Default{"footnoteBackLink"}=q(false);

$Type{"columnHeader"}="template";
$Default{"columnHeader"}=q();

$Type{"contentStructure"}="param";
$Default{"contentStructure"}=q(body);

$Type{"divOffset"}="param";
$Default{"divOffset"}=q(2);

$Type{"footnoteFile"}="param";
$Default{"footnoteFile"}=q(false);

$Type{"hdr"}="template";
$Default{"hdr"}=q(
  <xsl:call-template  name="pageHeader">
    <xsl:with-param  name="mode"/>
  </xsl:call-template>);

$Type{"hdr2"}="template";
$Default{"hdr2"}=q(
  <xsl:call-template  name="navbar"/>);

$Type{"preBreadCrumbPath"}="template";
$Default{"preBreadCrumbPath"}=q();

$Type{"hdr3"}="template";
$Default{"hdr3"}=q(
  <a  href="#rh-col"
    title="Go to main page content"  class="skiplinks">Skip links</a>
  <a  class="hide">
    <xsl:value-of  select="$separator"/>
  </a>
  <xsl:call-template  name="crumbPath"/>
  <a  class="hide">
    <xsl:value-of  select="$separator"/>
  </a>
  <xsl:if  test="not($parentURL='')">
    <a  class="bannerright"
      href="{$parentURL}"  title="Go to home page">
      <xsl:value-of  select="$parentWords"/>
    </a>
  </xsl:if>);

$Type{"lh-col-bottom"}="template";
$Default{"lh-col-bottom"}=q(
  <xsl:param  name="currentID"/>
  <xsl:call-template  name="leftHandFrame">
    <xsl:with-param  name="currentID"
      select="$currentID"/>
  </xsl:call-template>);

$Type{"lh-col-top"}="template";
$Default{"lh-col-top"}=q(
  <xsl:call-template  name="searchbox"/>
  <xsl:call-template  name="printLink"/>);

$Type{"logoPicture"}="template";
$Default{"logoPicture"}=q(
  <a  class="framelogo"
    href="https://www.tei-c.org/Stylesheets/">
    <img  src="https://www.tei-c.org/release/common/doc/tei-xsl-common/teixsl.png"
      vspace="5"  width="124"  height="161"  border="0"
      alt="created by TEI XSL Stylesheets"/>
  </a>);

$Type{"metaHTML"}="template";
$Default{"metaHTML"}=q(
  <xsl:param  name="title"/>
  <meta  name="author">
    <xsl:attribute  name="content">
      <xsl:sequence  select="tei:generateMetadataAuthor(.)"/>
    </xsl:attribute>
  </meta>
  <xsl:if  test="$filePerPage='true'">
    <meta  name="viewport"
      content="width={$viewPortWidth}, height={$viewPortHeight}"/>
  </xsl:if>
  <meta  name="generator"
    content="Text Encoding Initiative Consortium XSLT stylesheets"/>
  <xsl:choose>
    <xsl:when  test="$outputTarget='epub3'">
      <meta  charset="utf-8"/>
    </xsl:when>
    <xsl:otherwise>
      <meta  http-equiv="Content-Type"
        content="text/html; charset={$outputEncoding}"/>
      <meta  name="DC.Title">
        <xsl:attribute  name="content">
          <xsl:value-of  select="normalize-space(translate($title,'<>','〈〉'))"/>
        </xsl:attribute>
      </meta>
      <meta  name="DC.Type"  content="Text"/>
      <meta  name="DC.Format"
        content="text/html"/>
    </xsl:otherwise>
  </xsl:choose>);

$Type{"navbar"}="template";
$Default{"navbar"}=q(
  <xsl:choose>
    <xsl:when  test="$navbarFile=''">
      <xsl:comment>no nav bar</xsl:comment>
    </xsl:when>
    <xsl:otherwise>
      <xsl:element  name="{if ($outputTarget=('html5', 'html')) then 'nav' else 'div'}">
        <xsl:for-each  select="document($navbarFile,document(''))">
          <xsl:for-each  select="tei:list/tei:item">
            <span  class="navbar">
              <a  href="{$URLPREFIX}{tei:xref/@url}"
                class="navbar">
                <xsl:apply-templates  select="tei:xref/text()"/>
              </a>
            </span>
            <xsl:if  test="following-sibling::tei:item">
              <xsl:value-of  select="$separator"/>
            </xsl:if>
          </xsl:for-each>
        </xsl:for-each>
      </xsl:element>
    </xsl:otherwise>
  </xsl:choose>);

$Type{"navbarFile"}="param";
$Default{"navbarFile"}=q();

$Type{"pageHeader"}="template";
$Default{"pageHeader"}=q(
  <xsl:param  name="mode"/>
  <xsl:choose>
    <xsl:when  test="$mode='table'">
      <table  width="100%"  border="0">
        <tr>
          <td  height="98"  class="bgimage"
            onclick="window.location='{$homeURL}'"  cellpadding="0">
            <xsl:call-template  name="makeHTMLHeading">
              <xsl:with-param  name="class">subtitle</xsl:with-param>
              <xsl:with-param  name="text">
                <xsl:sequence  select="tei:generateSubTitle(.)"/>
              </xsl:with-param>
              <xsl:with-param  name="level">2</xsl:with-param>
            </xsl:call-template>
            <xsl:call-template  name="makeHTMLHeading">
              <xsl:with-param  name="class">title</xsl:with-param>
              <xsl:with-param  name="text">
                <xsl:sequence  select="tei:generateTitle(.)"/>
              </xsl:with-param>
              <xsl:with-param  name="level">1</xsl:with-param>
            </xsl:call-template>
          </td>
          <td  style="vertical-align:top;"/>
        </tr>
      </table>
    </xsl:when>
    <xsl:otherwise>
      <xsl:call-template  name="makeHTMLHeading">
        <xsl:with-param  name="class">subtitle</xsl:with-param>
        <xsl:with-param  name="text">
          <xsl:sequence  select="tei:generateSubTitle(.)"/>
        </xsl:with-param>
        <xsl:with-param  name="level">2</xsl:with-param>
      </xsl:call-template>
      <xsl:call-template  name="makeHTMLHeading">
        <xsl:with-param  name="class">title</xsl:with-param>
        <xsl:with-param  name="text">
          <xsl:sequence  select="tei:generateTitle(.)"/>
        </xsl:with-param>
        <xsl:with-param  name="level">1</xsl:with-param>
      </xsl:call-template>
    </xsl:otherwise>
  </xsl:choose>);

$Type{"rh-col-bottom"}="template";
$Default{"rh-col-bottom"}=q(
  <xsl:param  name="currentID"/>
  <xsl:call-template  name="mainFrame">
    <xsl:with-param  name="currentID"
      select="$currentID"/>
  </xsl:call-template>);

$Type{"rh-col-top"}="template";
$Default{"rh-col-top"}=q(
  <xsl:call-template  name="columnHeader"/>);

$Type{"searchbox"}="template";
$Default{"searchbox"}=q();

$Type{"singleFileLabel"}="template";
$Default{"singleFileLabel"}=q(For Printing);

$Type{"autoHead"}="param";
$Default{"autoHead"}=q(false);

$Type{"autoMakeHead"}="template";
$Default{"autoMakeHead"}=q(
  <xsl:param  name="display"/>
  <xsl:choose>
    <xsl:when  test="@n">
      <xsl:value-of  select="@n"/>
    </xsl:when>
    <xsl:when  test="tei:docDate">
      <xsl:apply-templates  select="tei:docDate"
        mode="plain"/>
    </xsl:when>
    <xsl:otherwise>
      <xsl:text>§</xsl:text>
    </xsl:otherwise>
  </xsl:choose>);

$Type{"headingNumberSuffix"}="template";
$Default{"headingNumberSuffix"}=q(
  <xsl:text>.</xsl:text>
  <xsl:value-of  select="$numberSpacer"/>);

$Type{"numberSpacer"}="param";
$Default{"numberSpacer"}=q(
  <xsl:text/>);

$Type{"numberBackDiv"}="template";
$Default{"numberBackDiv"}=q(
  <xsl:if  test="not($numberBackHeadings='')">
    <xsl:number  count="tei:div|tei:div1|tei:div2|tei:div3|tei:div4|tei:div5|tei:div6"
      format="A.1.1.1.1.1"  level="multiple"/>
  </xsl:if>);

$Type{"numberBackFigures"}="param";
$Default{"numberBackFigures"}=q(false);

$Type{"numberBackHeadings"}="param";
$Default{"numberBackHeadings"}=q(A.1);

$Type{"numberBackTables"}="param";
$Default{"numberBackTables"}=q(true);

$Type{"numberBodyDiv"}="template";
$Default{"numberBodyDiv"}=q(
  <xsl:if  test="$numberHeadings='true'">
    <xsl:number  count="tei:div|tei:div1|tei:div2|tei:div3|tei:div4|tei:div5|tei:div6"
      level="multiple"/>
  </xsl:if>);

$Type{"numberFigures"}="param";
$Default{"numberFigures"}=q(true);

$Type{"numberFrontDiv"}="template";
$Default{"numberFrontDiv"}=q(
  <xsl:param  name="minimal"/>
  <xsl:number  count="tei:div|tei:div1|tei:div2|tei:div3|tei:div4|tei:div5|tei:div6"
    level="multiple"/>
  <xsl:if  test="$minimal='false'">
    <xsl:value-of  select="$numberSpacer"/>
  </xsl:if>);

$Type{"numberFrontFigures"}="param";
$Default{"numberFrontFigures"}=q(false);

$Type{"numberFrontHeadings"}="param";
$Default{"numberFrontHeadings"}=q();

$Type{"numberFrontTables"}="param";
$Default{"numberFrontTables"}=q(true);

$Type{"numberHeadings"}="param";
$Default{"numberHeadings"}=q(true);

$Type{"numberHeadingsDepth"}="param";
$Default{"numberHeadingsDepth"}=q(9);

$Type{"numberTables"}="param";
$Default{"numberTables"}=q(true);

$Type{"prenumberedHeadings"}="param";
$Default{"prenumberedHeadings"}=q(false);

$Type{"numberParagraphs"}="param";
$Default{"numberParagraphs"}=q(false);

$Type{"outputTarget"}="param";
$Default{"outputTarget"}=q(html);

$Type{"REQUEST"}="param";
$Default{"REQUEST"}=q();

$Type{"STDOUT"}="param";
$Default{"STDOUT"}=q(true);

$Type{"ID"}="param";
$Default{"ID"}=q();

$Type{"requestedID"}="param";
$Default{"requestedID"}=q(
  <xsl:value-of  select="$ID"/>);

$Type{"URLPREFIX"}="param";
$Default{"URLPREFIX"}=q();

$Type{"outputName"}="param";
$Default{"outputName"}=q();

$Type{"outputDir"}="param";
$Default{"outputDir"}=q();

$Type{"outputEncoding"}="param";
$Default{"outputEncoding"}=q(UTF-8);

$Type{"outputMethod"}="param";
$Default{"outputMethod"}=q(xhtml);

$Type{"htmlVersion"}="param";
$Default{"htmlVersion"}=q(5.0);

$Type{"normalizationForm"}="param";
$Default{"normalizationForm"}=q(NFC);

$Type{"omitXMLDeclaration"}="param";
$Default{"omitXMLDeclaration"}=q(yes);

$Type{"outputSuffix"}="param";
$Default{"outputSuffix"}=q(.html);

$Type{"doctypePublic"}="param";
$Default{"doctypePublic"}=q(-//W3C//DTD XHTML 1.0 Transitional//EN);

$Type{"doctypeSystem"}="param";
$Default{"doctypeSystem"}=q(http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd);

$Type{"pageLayout"}="param";
$Default{"pageLayout"}=q(Simple);

$Type{"splitBackmatter"}="param";
$Default{"splitBackmatter"}=q(true);

$Type{"splitFrontmatter"}="param";
$Default{"splitFrontmatter"}=q(true);

$Type{"splitLevel"}="param";
$Default{"splitLevel"}=q(-1);

$Type{"standardSuffix"}="param";
$Default{"standardSuffix"}=q(
  <xsl:choose>
    <xsl:when  test="tei:teiCorpus">.html</xsl:when>
    <xsl:when  test="$STDOUT='true'"/>
    <xsl:otherwise>
      <xsl:value-of  select="$outputSuffix"/>
    </xsl:otherwise>
  </xsl:choose>);

$Type{"topNavigationPanel"}="param";
$Default{"topNavigationPanel"}=q(true);

$Type{"urlChunkPrefix"}="param";
$Default{"urlChunkPrefix"}=q(?ID=);

$Type{"useIDs"}="param";
$Default{"useIDs"}=q(true);

$Type{"autoToc"}="param";
$Default{"autoToc"}=q(true);

$Type{"class_subtoc"}="param";
$Default{"class_subtoc"}=q(subtoc);

$Type{"subTocDepth"}="param";
$Default{"subTocDepth"}=q(-1);

$Type{"tocBack"}="param";
$Default{"tocBack"}=q(true);

$Type{"tocDepth"}="param";
$Default{"tocDepth"}=q(5);

$Type{"tocFront"}="param";
$Default{"tocFront"}=q(true);

$Type{"tocElement"}="param";
$Default{"tocElement"}=q(p);

$Type{"tocContainerElement"}="param";
$Default{"tocContainerElement"}=q(div);

$Type{"refDocFooterText"}="param";
$Default{"refDocFooterText"}=q(TEI Guidelines);

$Type{"refDocFooterURL"}="param";
$Default{"refDocFooterURL"}=q(index.html);

$Type{"navInterSep"}="template";
$Default{"navInterSep"}=q(
  <xsl:text>: </xsl:text>);

$Type{"copyrightStatement"}="template";
$Default{"copyrightStatement"}=q();

$Type{"class_toc"}="param";
$Default{"class_toc"}=q(toc);

$Type{"class_ptr"}="param";
$Default{"class_ptr"}=q(ptr);

$Type{"class_ref"}="param";
$Default{"class_ref"}=q(ref);

$Type{"cssFile"}="param";
$Default{"cssFile"}=q(https://www.tei-c.org/release/xml/tei/stylesheet/tei.css);

$Type{"cssPrintFile"}="param";
$Default{"cssPrintFile"}=q(https://www.tei-c.org/release/xml/tei/stylesheet/tei-print.css);

$Type{"cssSecondaryFile"}="param";
$Default{"cssSecondaryFile"}=q();

$Type{"cssInlineFiles"}="param";
$Default{"cssInlineFiles"}=q();

$Type{"cellAlign"}="param";
$Default{"cellAlign"}=q(left);

$Type{"tableAlign"}="param";
$Default{"tableAlign"}=q(left);

$Type{"graphicsPrefix"}="param";
$Default{"graphicsPrefix"}=q();

$Type{"graphicsSuffix"}="param";
$Default{"graphicsSuffix"}=q(.png);

$Type{"standardScale"}="param";
$Default{"standardScale"}=q(1);

$Type{"headInXref"}="param";
$Default{"headInXref"}=q(true);

$Type{"dpi"}="param";
$Default{"dpi"}=q(96);

$Type{"showFigures"}="param";
$Default{"showFigures"}=q(true);

$Type{"pagebreakStyle"}="param";
$Default{"pagebreakStyle"}=q(visible);

$Type{"displayMode"}="param";
$Default{"displayMode"}=q(rnc);

$Type{"minimalCrossRef"}="param";
$Default{"minimalCrossRef"}=q(false);

$Type{"postQuote"}="param";
$Default{"postQuote"}=q(’);

$Type{"preQuote"}="param";
$Default{"preQuote"}=q(‘);

$Type{"urlMarkup"}="param";
$Default{"urlMarkup"}=q(span);

$Type{"sectionHeadHook"}="template";
$Default{"sectionHeadHook"}=q();

$Type{"attDefHook"}="template";
$Default{"attDefHook"}=q(
  <xsl:param  name="attName"/>);

$Type{"bodyHook"}="template";
$Default{"bodyHook"}=q();

$Type{"bodyEndHook"}="template";
$Default{"bodyEndHook"}=q();

$Type{"bodyJavascriptHook"}="template";
$Default{"bodyJavascriptHook"}=q();

$Type{"cssHook"}="template";
$Default{"cssHook"}=q();

$Type{"headHook"}="template";
$Default{"headHook"}=q();

$Type{"imgHook"}="template";
$Default{"imgHook"}=q();

$Type{"figureHook"}="template";
$Default{"figureHook"}=q();

$Type{"javascriptHook"}="template";
$Default{"javascriptHook"}=q();

$Type{"preAddressHook"}="template";
$Default{"preAddressHook"}=q();

$Type{"startDivHook"}="template";
$Default{"startDivHook"}=q();

$Type{"startHook"}="template";
$Default{"startHook"}=q();

$Type{"teiEndHook"}="template";
$Default{"teiEndHook"}=q();

$Type{"teiStartHook"}="template";
$Default{"teiStartHook"}=q();

$Type{"xrefHook"}="template";
$Default{"xrefHook"}=q();

$Type{"egXMLStartHook"}="template";
$Default{"egXMLStartHook"}=q();

$Type{"teixslHome"}="param";
$Default{"teixslHome"}=q(http://www.tei-c.org/Stylesheets/);

$Type{"teiP4Compat"}="param";
$Default{"teiP4Compat"}=q(false);

$Type{"generateParagraphIDs"}="param";
$Default{"generateParagraphIDs"}=q(false);

$Type{"showTitleAuthor"}="param";
$Default{"showTitleAuthor"}=q(false);

$Type{"generationComment"}="param";
$Default{"generationComment"}=q(true);

$Type{"verbose"}="param";
$Default{"verbose"}=q(false);


use CGI qw(:standard :html3);
use CGI::Carp;
use CGI::Carp qw(fatalsToBrowser);
$query = new CGI;

$today = (localtime)[3] . " " . (Jan,Feb,Mar,Apr,May,Jun,Jul,Aug,Sep,Oct,Nov,Dec)[(localtime)[4]] . " " . ((localtime)[5] + 1900);

&Response($query) ;

sub Response {
my $HOME=$query->param('TEIXSL');
my $OUTFILE=$query->param('outputFile');
print $query->header(-type=>'application/octet-stream',
		     -attachment=>$OUTFILE);
print <<END;
<xsl:stylesheet 
    xmlns:tei="http://www.tei-c.org/ns/1.0"
    xmlns="http://www.w3.org/1999/xhtml"
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    exclude-result-prefixes="tei xsl"
    version="3.0">
<!-- XSLT stylesheet to generate HTML version of TEI document.
Written by the TEI XSL generator (Sebastian Rahtz, sebastian.rahtz\@it.ox.ac.uk)
Created on $today-->
END
#foreach $key ($query->param) {
#              print "Key [$key] --- Value[";
#              @values = $query->param($key);
#              print join(", ",@values),"]\n";
#          }
print "<xsl:import href=\"";
print $HOME;
print "/tei/stylesheet/html/html.xsl\"/>\n";
foreach $key (keys %Default) {
my $Passed=$query->param($key);
my $D=$Default{$key};
$Passed =~ tr/\015//d;
if ($D eq "false") { $D=""; }
$D =~ s/^[\n\r]//;
if ($key eq 'preQuote') {}
elsif ($key eq 'postQuote') {}
elsif ($Passed ne $D) {
# print "<!--\n\DIFFERENCE in $key:|$Passed|$D|-->\n";
 print qq(<xsl:$Type{$key} name="$key">);
 print "$Passed";
 print "</xsl:$Type{$key}>\n";
}
}
print "</xsl:stylesheet>\n";

return "";
}
