/*
 *
 *  DOM/EcmaScript Interfaces to TeXML-Documents
 *  insert <xhtml:script/> just after TeXML-root-node or <xhtml:title>
 *
 */

const uaLoString  = new String(window.navigator.userAgent.toLowerCase());
const uaStrMSIE   = (uaLoString.indexOf('msie') != -1);
const uaStrGecko  = (uaLoString.indexOf('gecko') != -1);
const uaStrOpera  = (uaLoString.indexOf('opera') != -1);
const uaStrKMel   = (uaLoString.indexOf('k-meleon') != -1);
const uaStrKonq   = (uaLoString.indexOf('konqueror') != -1);
const uaStrKHTML  = (uaLoString.indexOf('khtml') != -1);
const uaStrSafari = (uaLoString.indexOf('safari') != -1);

const isMSIE     = !!(document.all && !window.opera);
const isOpera    = !!window.opera;

// -----------------------------------------------------------------

function DOMImplements(iDoc) {
    this.iDoc = iDoc;
    if (this.iDoc.nodeType&&this.iDoc.nodeType==9) 
	{
    this.isDOM1   = !!(this.iDoc.getElementById && this.iDoc.createElement);
    this.isDOMi   = !!(this.iDoc.implementation && this.iDoc.implementation.hasFeature);
    this.isXML1   = !!(this.isDOMi && this.iDoc.implementation.hasFeature('XML','1.0'));
    this.isDOM2   = !!(this.isDOMi && (this.iDoc.implementation.hasFeature('Core','2.0') || this.iDoc.implementation.hasFeature('DOM','2.0')));
    this.isXML2   = !!(this.isDOM2 && this.iDoc.implementation.hasFeature('XML','2.0'));
    this.isCSS2   = !!(this.isDOM2 && this.iDoc.implementation.hasFeature('CSS2','2.0'));
    this.isTrav2  = !!(this.isDOM2 && this.iDoc.implementation.hasFeature('Traversal','2.0') && this.iDoc.createNodeIterator && this.iDoc.createTreeWalker);
    this.isRange2 = !!(this.isDOM2 && this.iDoc.implementation.hasFeature('Range','2.0') && this.iDoc.createRange);
    this.isEvent2 = !!(this.isDOM2 && this.iDoc.implementation.hasFeature('Events','2.0') && this.iDoc.addEventListener);
    this.isXPath3 = !!(this.isDOM2 && this.iDoc.implementation.hasFeature('XPath','3.0'));
    this.iStr = [
		/*@if (@_jscript) "[node "+iDoc.nodeTypeString||iDoc+"]", @else @*/ iDoc.toString(), /*@end @*/
        "implementation.hasFeature('Core','1.0') = "+this.isDOM1,
        "implementation.hasFeature('XML','1.0') = "+this.isXML1,
        "implementation.hasFeature('Core','2.0') = "+this.isDOM2,
        "implementation.hasFeature('XML','2.0') = "+this.isXML2,
        "implementation.hasFeature('CSS2','2.0') = "+this.isCSS2,
        "implementation.hasFeature('Traversal','2.0') = "+this.isTrav2,
        "implementation.hasFeature('Range','2.0') = "+this.isRange2,
        "implementation.hasFeature('Events','2.0') = "+this.isEvent2,
        "implementation.hasFeature('XPath','3.0') = "+this.isXPath3
        ].join('\n');
	} else {
	this.iStr = new String('@@no DOMDocument@@');
	}
	return this;
}

// -----------------------------------------------------------------


//
//  begin exec at the earliest after TeXML-root-node = documentElement
//

const hasTeXMLdtd  = (document.doctype && document.doctype.nodeName == 'TeXML');
const hasTeXMLroot = (document.documentElement && document.documentElement.nodeName == 'TeXML');

if (hasTeXMLroot)
    {
    if (document.documentElement.hasAttributeNS('http:\/\/www.w3.org\/1999\/xhtml','onload'))
       window.onload=TeXMLoad;   // NOOP ?: document.documentElement.addEventListener('load', TeXMLoad, true);
    if (document.documentElement.hasAttributeNS('http:\/\/www.w3.org\/1999\/xhtml','onunload'))
       window.onunload=TeXMLoad; // NOOP ?: document.documentElement.addEventListener('unload', TeXMLoad, true);
    //
    // if stylesheet-query URI?ss=stylesheet
    //
    void(createPIxmlss(getQuery('ss',false))); // insert before DOCTYPE or TeXML-root-node
    }

//
//  end exec
//

function iniTeXML() { linkINIT(); makeTOC(); }
function exiTeXML() { }  //  reserved
function virTeXML() { }  //  reserved

virTeXML.prototype.isBrowser = this.window != null;
virTeXML.prototype.isJScript = this.ScriptEngine != null;  // Microsoft's JScript
virTeXML.prototype.isWSH     = this.WScript != null;       // MS's Windows Script Host (cscript.exe)
virTeXML.prototype.isRhino   = this.importPackage != null; // Mozilla's Rhino (java.exe js.jar)
virTeXML.prototype.isMozJSSH = this.load != null;          // Mozilla's SpiderMonkey (jsshell.exe)

function TeXMLoad(ev) {
    eval(document.documentElement.getAttributeNS('http:\/\/www.w3.org\/1999\/xhtml','on'+ev.type));
}

function LaTeX() {
    this.documentclass  = document.getElementById('documentclass');
    this.document       = document.getElementById('document');
    this.title          = document.getElementById('title');
    this.author         = document.getElementById('author');
    this.date           = document.getElementById('date');
    this.maketitle      = document.getElementById('maketitle');
    return this;
}

//  1st version: file.xml?nn='nn';Name='Value';etc='pp'   RegExp(queryName+'=\'(.+?)\'')
//  2nd version: file.xml?nn=nn&Name=Value&etc=pp         RegExp(queryName+'=(.+?)(?:&|$)')
//  getQuery('Name','Default');   returns Value

function getQuery(queryName, defaultValue) {
    var pattern = new RegExp('[?&]'+queryName+'=(.+?)(?:&|$)');
    return (pattern.test(window.location.search)) ? RegExp.$1 : defaultValue ;
} // END:fn
function createPIxmlss(ss) {
    if (ss && document.createProcessingInstruction) {
    var insB4Obj = (hasTeXMLdtd) ? document.doctype : document.documentElement ;
        switch (ss.slice(ss.lastIndexOf('.'))) {  // (ss.match(/(?:\.css|\.xsl)$/))
        case '.css':
            var piCSS = document.createProcessingInstruction('xml-stylesheet', 'alternate=\"no\" type=\"text\/css\" href=\"' + ss + '\"');
            document.insertBefore(piCSS, insB4Obj); return piCSS;
            break;
        case '.xsl':
            var piXSL = document.createProcessingInstruction('xml-stylesheet', 'alternate=\"no\" type=\"text\/' + ((isMSIE) ? 'xsl' : 'xml') + '\" href=\"' + ss + '\"');
            document.insertBefore(piXSL, insB4Obj); return piXSL;
            break;
        default: alert('cannot identify .css\/.xsl filename: \"'+ss+'\"'); break;
        }
    }
} // END:fn
function setElementXLinkAttrNS(el, url) {
    el.setAttributeNS('http:\/\/www.w3.org\/2000\/xmlns\/','xmlns:xlink'  ,'http:\/\/www.w3.org\/1999\/xlink');
    el.setAttributeNS('http:\/\/www.w3.org\/1999\/xlink'  ,'xlink:type'   ,'simple');
    el.setAttributeNS('http:\/\/www.w3.org\/1999\/xlink'  ,'xlink:show'   ,'replace');
    el.setAttributeNS('http:\/\/www.w3.org\/1999\/xlink'  ,'xlink:actuate','onRequest');
    el.setAttributeNS('http:\/\/www.w3.org\/1999\/xlink'  ,'xlink:href'   ,url);
} // END:fn


function createXMLDoctype(strQNameRootTag, strPublicId, strSystemIdURI) {
    return document.implementation.createDocumentType(strQNameRootTag, strPublicId, strSystemIdURI);
    }
function createXMLDocument(strNamespaceURI, strRootTagName) {
    return document.implementation.createDocument(strNamespaceURI, strRootTagName, null);
    }
//  var TFmiiXroot = createXMLDocument('http:\/\/www.mozilla.org\/TransforMiix', 'transformiix:result');
//  var XSLTssroot = createXMLDocument('http:\/\/www.w3.org\/1999\/XSL\/Transform', 'xsl:stylesheet');
//  var xHTMLroot  = createXMLDocument('http:\/\/www.w3.org\/1999\/xhtml', 'html');
//  var TeXMLroot  = createXMLDocument('http:\/\/www.unterstein.net\/ML\/TeXML', 'TeXML');


// -----------------------------------------------------------------
// date time &c
// -----------------------------------------------------------------

var baseDate = new Date();
var baseDays = Math.floor(baseDate.valueOf()/86400000); 
var modiDate = new Date(document.lastModified);
var modiDays = baseDays-(Math.floor(modiDate.valueOf()/86400000)); 

var base2Day = { "y":baseDate.getUTCFullYear(),"m":baseDate.getUTCMonth()+1,"d":baseDate.getUTCDate() }
	base2Day.YY  = ''+base2Day.y;
	base2Day.MM  = ((base2Day.m<10)?'0':'')+base2Day.m;
	base2Day.DD  = ((base2Day.d<10)?'0':'')+base2Day.d;
	base2Day.ISO = base2Day.YY+'-'+base2Day.MM+'-'+base2Day.DD;

function getDays2Date(tDate) { // Arg: Object Date
	return Math.abs(baseDays-(Math.floor(oDate.valueOf()/86400000)));
} // END:fn
function getDaysSince(strYYYY,strMM,strDD) { // StrOfMonths: [0]1-12 
	return Math.abs(baseDays-(Math.floor(Date.UTC(parseInt(strYYYY,10),parseInt(strMM,10)-1,parseInt(strDD,10))/86400000)));
} // END:fn
function getDaysAsAMD(numOfDays) { // AMD = ??a??m??d = anni menses dies = years months days
	var tempus;
	var result = new String('');
	if (numOfDays>=365) { tempus=Math.floor(numOfDays/365); numOfDays-=tempus*365; if (tempus<10) result+='0'; result+=tempus+'a'; }
	if (numOfDays>=30)  { tempus=Math.floor(numOfDays/30);  numOfDays-=tempus*30;  if (tempus<10) result+='0'; result+=tempus+'m'; }
	return result+((numOfDays)?((numOfDays<10)?'0':'')+numOfDays+'d':'');
}

DaysOfMonthInYear = function(MM,YY){ return (MM==2) ? (((!(YY%4) && (YY%100)) || !(YY%400)) ? 29 : 28) : [0,31,28,31,30,31,30,31,31,30,31,30,31][MM] ; }

function FromDate2Date(fDate,tDate) { // Args: Object Date
	return getDaysAsAMD(Math.abs((Math.floor(tDate.valueOf()/86400000))-(Math.floor(fDate.valueOf()/86400000))));
}
function FromToNumDate(fY,fM,fD,tY,tM,tD) { // NumOfMonths: 1-12  
	var rY=tY-fY; var rM=tM-fM; var rD=tD-fD;
	if (rD<0) { rD+=DaysOfMonthInYear(fM,fY); rM--; }
	if (rM<0) { rM+=12; rY--; }
//	if (rY<0) { }
//	return ((rY)?rY+"a":"")+((rM)?rM+"m":"")+((rD)?rD+"d":"");
	return ((rY)?((rY<10)?"0":"")+rY+"a":"")+((rM)?((rM<10)?"0":"")+rM+"m":"")+((rD)?((rD<10)?"0":"")+rD+"d":"");
}

var modi2Day = FromToNumDate(modiDate.getUTCFullYear(),modiDate.getUTCMonth()+1,modiDate.getUTCDate(),baseDate.getUTCFullYear(),baseDate.getUTCMonth()+1,baseDate.getUTCDate());
    //? = getDaysAsAMD(modiDays);
    //? = FromDate2Date(modiDate,baseDate);
    //? = FromToNumDate(modiDate.getUTCFullYear(),modiDate.getUTCMonth()+1,modiDate.getUTCDate(),baseDate.getUTCFullYear(),baseDate.getUTCMonth()+1,baseDate.getUTCDate());

// -----------------------------------------------------------------
// -----------------------------------------------------------------

var targetSrc = {};
	targetSrc.nl       = new String(/*@if (@_jscript) '\r\n' @else @*/ '\n' /*@end @*/); 
	targetSrc.xmlpi    = new String('<?xml version=\"1.0\"?>');
	targetSrc.xmlcdata = [
		targetSrc.xmlpi,
		'<adhoc:documentElement xmlns:adhoc=\"urn:xmlns:adhoc" xml:space=\"preserve\">',
		'<![CDATA[@@no result@@]]>',
		'<\/adhoc:documentElement>'
		].join(targetSrc.nl);
	targetSrc.xhtml11dtd  = new String('<!DOCTYPE html PUBLIC \"-\/\/W3C\/\/DTD XHTML 1.1\/\/EN\" \"http:\/\/www.w3.org\/TR\/xhtml11\/DTD\/xhtml11.dtd\">');
	targetSrc.xhtml11root = [
		targetSrc.xmlpi,
		targetSrc.xhtml11dtd,
		'<html xmlns=\"http:\/\/www.w3.org\/1999\/xhtml\">',
		'<\/html>'
		].join(targetSrc.nl);
	targetSrc.xhtml11body = [
		targetSrc.xmlpi,
		targetSrc.xhtml11dtd,
		'<html xmlns=\"http:\/\/www.w3.org\/1999\/xhtml\">',
		'<head>',
		'<title>ML \u00B7 Result<\/title>',
		'<\/head>',
		'<body>',
		'<\/body>',
		'<\/html>'
		].join(targetSrc.nl);
	targetSrc.xhtml11pre = [
		targetSrc.xmlpi,
		targetSrc.xhtml11dtd,
		'<html xmlns=\"http:\/\/www.w3.org\/1999\/xhtml\">',
		'<head>',
		'<title>ML \u00B7 Result<\/title>',
		'<\/head>',
		'<body>',
		'<pre id=\"resultPre\">@@no result@@<\/pre>',
		'<\/body>',
		'<\/html>'
		].join(targetSrc.nl);
	targetSrc.texmldtd   = new String('<!DOCTYPE TeXML PUBLIC \"-\/\/StUs\/\/DTD TeXML\/\/EN\" \"http:\/\/www.unterstein.net\/ML\/TeXML.dtd\">');
	targetSrc.texmlcdata = [
		targetSrc.xmlpi,
		targetSrc.texmldtd,
		'<TeXML xmlns=\"http:\/\/www.unterstein.net\/ML\/TeXML\" xml:space=\"preserve\">',
		'<![CDATA[@@no result@@]]>',
		'<\/TeXML>'
		].join(targetSrc.nl);

function target4ID(oOut,tOut) {
	var tLoc; tOut=tOut||'two';
	if (tLoc=document.getElementById(tOut))
	{
		with (tLoc) { while (hasChildNodes()) { void(removeChild(lastChild)); } };
		switch (tLoc.tagName.toLowerCase())
		{
		case 'pre': tLoc.appendChild(document.createTextNode(oOut)); break;
		case 'div': /*@if (@_jscript) tLoc.innerHTML=this.rStr; @else @*/ tLoc.appendChild(oOut); /*@end @*/ break;
		case 'object' : 
			if (oOut.documentElement)
			tLoc.contentDocument.replaceChild(tLoc.contentDocument.importNode(oOut.documentElement,true),tLoc.contentDocument.documentElement);
			else tLoc.contentDocument.documentElement.appendChild(tLoc.contentDocument.importNode(oOut,true)); 
			break;
		case '': break;
		default: break;
		} // END:switch
	} else {
    var tWin=window.open('about:blank', tOut);
	var tDoc=tWin.document;
        tDoc.open('text\/html');
        tDoc.write(targetSrc.xhtml11body);
        tDoc.close();
		switch (typeof(oOut)) {
		case 'string': 
			tDoc.body.style.fontWeight='bold';
			tDoc.body.style.backgroundColor='silver';
			tDoc.body.style.cursor='wait';
			tDoc.body.appendChild(tDoc.createElement('pre'));
			tDoc.body.firstChild.appendChild(tDoc.createTextNode(oOut));
			tDoc.body.style.cursor='auto';
			break;
		case 'object': 
			if (oOut.documentElement)
			tDoc.replaceChild(tDoc.importNode(oOut.documentElement,true),tDoc.documentElement);
			else tDoc.documentElement.appendChild(tDoc.importNode(oOut,true)); 
			break;
		default: break;
		} // END:switch
	} // END:else
	return tLoc||tDoc;
} // END:fn

// -----------------------------------------------------------------
// Link-Initialisation
// -----------------------------------------------------------------

function linkINIT() {  // nodes/ids must be read/known, so exec with root's xhtml:onload or after ids
    //
    var LINK;
    //
    // insert Disclaimer href-Link (farbe=bgColor/fgColor/linkColor/vlinkColor)
    //
    if (LINK=document.getElementById('claim')) {
        // LINK.href='http:\/\/www.disclaimer.de\/disclaimer.htm';
        // LINK.title='external disclaimer'; LINK.target='two';
        LINK.setAttribute('href','http:\/\/www.disclaimer.de\/disclaimer.htm');
        LINK.setAttribute('title','external disclaimer'); LINK.setAttribute('target','two');
        LINK.firstChild.nodeValue='disclaimer';
        }
    //
    // insert Impressum/Admin-C href-Link
    //
    if (LINK=document.getElementById('admin')) {
        // LINK.href='\/admin.html';
        // LINK.title='site\'s admin-contact';
        LINK.setAttribute('href','\/admin.html');
        LINK.setAttribute('title','site\'s admin-contact');
        LINK.firstChild.nodeValue='impressum';
        }
    //
    // insert Transformer href-Link
    //
    if (LINK=document.getElementById('tform')) {
        // LINK.href='javascript:OpenTarget2(transformTeXMLtoTeX(document.documentElement));';
        // LINK.title='DOM\/JavaScript-Transformer (not XSLT)';
        LINK.setAttribute('href','javascript:OpenTarget2(transformTeXMLtoTeX(document.documentElement));');
        LINK.setAttribute('title','DOM\/JavaScript-Transformer (not XSLT)');
        LINK.firstChild.nodeValue='transformer';
        }
    //
    // insert ObjectWalker href-Link
    //
    if (LINK=document.getElementById('oview')) {
        // LINK.href='javascript:ObjectView(document);';
        // LINK.title='DOM\/JavaScript-ObjectViewer';
        LINK.setAttribute('href','javascript:ObjectView(document);');
        LINK.setAttribute('title','DOM\/JavaScript-ObjectViewer');
        LINK.firstChild.nodeValue='doc-objects';
        }
    //
    // insert Revision/Modified Textnode
    //
    if (LINK=document.getElementById('rvbar')) {
        LINK.firstChild.nodeValue='Revision '+document.lastModified+((modi2Day)?' ~ '+modi2Day:'');
        }
    //
    // insert GNU-Copyleft href-Link and title-Tooltip
    //
    if (LINK=document.getElementById('GNUfdl')) {
        // LINK.href='http:\/\/www.gnu.org\/licenses\/fdl.html';
        // LINK.title='GNU Free Documentation License'; LINK.target='two';
        LINK.setAttribute('href','http:\/\/www.gnu.org\/licenses\/fdl.html');
        LINK.setAttribute('title','GNU Free Documentation License'); LINK.setAttribute('target','two');
        }
    //
    // insert CC-Copyleft href-Link and title-Tooltip
    //
    if (LINK=document.getElementById('CCncsa')) {
        // LINK.href='http:\/\/creativecommons.org\/licenses\/by-nc-sa\/2.0\/';
        // LINK.title='Creative Commons NonCommercial-ShareAlike License'; LINK.target='two';
        LINK.setAttribute('href','http:\/\/creativecommons.org\/licenses\/by-nc-sa\/2.5\/');
        LINK.setAttribute('title','Creative Commons NonCommercial-ShareAlike License'); LINK.setAttribute('target','two');
        }
    //
}


// -----------------------------------------------------------------
// Table of Contents (TeXML cf LaTeX-\tableofcontents *.toc-file)
// -----------------------------------------------------------------

function makeTOC() {
if ((TOCid=document.getElementById('toc'))==null) return;
    function getsetAttr(o, strAttrName, strFallbackValue) {
        return (o.hasAttribute(strAttrName)) ? o.getAttribute(strAttrName) : (o.setAttribute(strAttrName,strFallbackValue), strFallbackValue) ;
    }
    function makeTOCline(ofObj,sectionLevel,idRef) {   //  <cmd name="contentsline" args="{type}"><arg xlink:* >text</arg><arg/></cmd>
    var TOCln = document.createElement('cmd');
        TOCln.setAttribute('name','contentsline');
        TOCln.setAttribute('args',sectionLevel);
        TOCln.appendChild(ofObj.getElementsByTagName('arg')[0].cloneNode(true));
        with (TOCln.firstChild) {
            setAttributeNS('http:\/\/www.w3.org\/1999\/xlink','xlink:type','simple');
            setAttributeNS('http:\/\/www.w3.org\/1999\/xlink','xlink:show','replace');
            setAttributeNS('http:\/\/www.w3.org\/1999\/xlink','xlink:actuate','onRequest');
            setAttributeNS('http:\/\/www.w3.org\/1999\/xlink','xlink:href','#'+idRef);
        } // with
        TOCln.appendChild(document.createElement('arg')); // empty <arg/> = LaTeX contentsline pageno
        return TOCln;
    }
var SecEL = document.getElementsByTagName('cmd');
var TOCdf = document.createDocumentFragment();
var TOCxx = document.createElement('x'); // <x wrap="toc" type="xml"> contentsgroup </x>
    TOCxx.setAttribute('wrap','toc');
    TOCxx.setAttribute('role','xml');
var GrpEL = document.createElement('grp'); // <grp bg="\begingroup" eg="\endgroup"> contentsline(s) </grp>
    GrpEL.setAttribute('bg','\\begingroup');
    GrpEL.setAttribute('eg','\\endgroup');

    TOCdf.appendChild(document.createTextNode('\n'));
    TOCdf.appendChild(TOCxx);
    TOCxx.appendChild(GrpEL);
    GrpEL.appendChild(document.createTextNode('\n'));

var sectionLevel = new String('');
var sectionIdRef = new String('');

    for (var i=0; i<SecEL.length; i++) {
    switch (SecEL[i].getAttribute('name'))
    {
    case 'part' :
    case 'chapter' :
    case 'section' :
    case 'subsection' :
    case 'subsubsection' :
    // case 'paragraph' :
    // case 'subparagraph' :
        sectionLevel = '{'+SecEL[i].getAttribute('name')+'}';
        sectionIdRef = getsetAttr(SecEL[i],'id',SecEL[i].getAttribute('name')+'ID'+i);
        GrpEL.appendChild(makeTOCline(SecEL[i],sectionLevel,sectionIdRef));
        GrpEL.appendChild(document.createTextNode('\n'));
    break;
    case 'addcontentsline' :
        if (SecEL[i].getAttribute('args').substring(0,5)=='{toc}')
        {
        sectionLevel = SecEL[i].getAttribute('args').substring(5);
        sectionIdRef = getsetAttr(SecEL[i],'id','AddContentsLn'+i);
        GrpEL.appendChild(makeTOCline(SecEL[i],sectionLevel,sectionIdRef));
        GrpEL.appendChild(document.createTextNode('\n'));
        }
    break;
    default : /* nop */ break;
    } // switch
    } // for
    TOCid.parentNode.insertBefore(TOCdf, TOCid.nextSibling);
}


// -----------------------------------------------------------------
// DOM-Document Object-Viewer
// -----------------------------------------------------------------

var normalRegEx = new RegExp().compile('\\s{2,}|\\n','g');
var normalValue = function(o) { o.normalize(); var result = new String(o.nodeValue); result=result.replace(normalRegEx,' '); return result; }

function ObjectWalk(o,tab) {
var str = new String(tab+o.nodeName+' '+o.toString()+((o.hasAttributes&&o.hasAttributes())?' hasAttributes:'+o.attributes.length:'')+((o.hasChildNodes&&o.hasChildNodes())?' hasChildNodes:'+o.childNodes.length:'')+'\n');
    switch (o.nodeType)
       {
        case Node.ELEMENT_NODE :           
			if (o.hasAttributes()) {
				for (var ai=0; ai < o.attributes.length; ai++)
				{
				var a = o.attributes.item(ai);
				str += tab+'|:  '+a.toString()+' '+a.name+'=\"'+a.value+'\"\n';  //··
				}
			}
			break;
        case Node.ATTRIBUTE_NODE :         break;
        case Node.TEXT_NODE :              
            str += tab+'#['+o.length+']\n';
			break;
        case Node.CDATA_SECTION_NODE :     
            str += tab+'#['+o.length+']\n';
			break;
        case Node.ENTITY_REFERENCE_NODE :  break;
        case Node.ENTITY_NODE :
            str += tab+'|\u00B7  [publicId] '+o.publicId+'\n';
            str += tab+'|\u00B7  [systemId] '+o.systemId+'\n';
            str += tab+'|\u00B7  [notation] Name '+((o.notationName) ? o.notationName+' (unparsed)' : 'null (parsed)')+'\n';
            break;
        case Node.PROCESSING_INSTRUCTION_NODE :
            str += tab+'|\u00B7  [target] '+o.target+'\n';
            str += tab+'|\u00B7  [data]   '+o.data+'\n';
            break;
        case Node.COMMENT_NODE :
            str += tab+'#['+o.length+']\n';
			break;
        case Node.DOCUMENT_NODE :          break;
        case Node.DOCUMENT_TYPE_NODE :
            str += tab+'|\u00B7  [publicId] '+o.publicId+'\n';
            str += tab+'|\u00B7  [systemId] '+o.systemId+'\n';
            str += tab+'|\u00B7  [internal] Subset '+((o.internalSubset) ? '(skipped source ...)' : '(none)')+'\n';
            if (o.entities) {
                for (var ei=0; ei < o.entities.length; ei++)
                {
                var e = o.entities.item(ei);
                str += tab+'|\u00B7  '+e.name+' '+e.toString()+' \"'+e.value+'\"\n';  //··
            }   }
            if (o.notations) {
                for (var ni=0; ni < o.notations.length; ni++)
                {
                var n = o.notations.item(ni);
                str += tab+'|\u00B7  '+n.name+' '+n.toString()+' \"'+n.value+'\"\n';  //··
            }   }
            break;
        case Node.DOCUMENT_FRAGMENT_NODE : break;
        case Node.NOTATION_NODE :
            str += tab+'|\u00B7  [publicId] '+o.publicId+'\n';
            str += tab+'|\u00B7  [systemId] '+o.systemId+'\n';
            break;
        default : break;
       }
    //  for (var ci=o.firstChild; ci!=null; ci=ci.nextSibling) str += ObjectWalk(ci,tab+'|       ');
    for (var ci=0; ci < o.childNodes.length; ci++)
    {
    str += ObjectWalk(o.childNodes[ci],tab+'|       ');
    }
    return str+tab+o.nodeName+' [END]\n';
}
function ObjectView(o) {
    var rOut=window.open('about:blank', 'two');
        rOut.document.open('text\/html');
        rOut.document.write(targetSrc.xhtml11pre);
        rOut.document.close();
        rOut.document.title='ML \u00B7 DOM\/Script Object Walk \u0026 View';
        rOut.document.body.style.backgroundColor='silver';
    var rPre=rOut.document.getElementById('resultPre');
        rPre.style.fontWeight='bold';
        rPre.firstChild.nodeValue=ObjectWalk(o,'');
}

// -----------------------------------------------------------------
// EOFn
// -----------------------------------------------------------------


// -----------------------------------------------------------------
// under construction: TeXMLTransformer to text/plain TeX  (currently discarded)
// added entitags 2004-01-10  entity-reference-node for IE, nmtoken RegExp 2004-02-20
// -----------------------------------------------------------------


/*   **********************************************************
 *   JS-Object-Literals generated/transformed from entitagX.xml
 *   XML v1
 *   XSLTransformed by
 *   Transformiix
 *   http://www.mozilla.org/projects/xslt/
 */

const ent = {  //  351  Object-Literals for Entitags-Transformation

aacute:"\\'a", Aacute:"\\'A", acirc:"\\^a", Acirc:"\\^A", agrave:"\\`a",
Agrave:"\\`A", aring:"{\\aa}", Aring:"{\\AA}", atilde:"\\~a", Atilde:"\\~A",
auml:"\\\"a", Auml:"\\\"A", aelig:"{\\ae}", AElig:"{\\AE}", ccedil:"\\c{c}",
Ccedil:"\\c{C}", eth:"{\\dh}", ETH:"{\\DH}", eacute:"\\'e", Eacute:"\\'E",
ecirc:"\\^e", Ecirc:"\\^E", egrave:"\\`e", Egrave:"\\`E", euml:"\\\"e",
Euml:"\\\"E", iacute:"\\'{\\i}", Iacute:"\\'I", icirc:"\\^{\\i}", Icirc:"\\^I",
igrave:"\\`{\\i}", Igrave:"\\`I", iuml:"\\\"{\\i}", Iuml:"\\\"I", ntilde:"\\~n",
Ntilde:"\\~N", oacute:"\\'o", Oacute:"\\'O", ocirc:"\\^o", Ocirc:"\\^O",
ograve:"\\`o", Ograve:"\\`O", oslash:"{\\o}", Oslash:"{\\O}", otilde:"\\~o",
Otilde:"\\~O", ouml:"\\\"o", Ouml:"\\\"O", szlig:"{\\ss}", thorn:"{\\th}",
THORN:"{\\TH}", uacute:"\\'u", Uacute:"\\'U", ucirc:"\\^u", Ucirc:"\\^U",
ugrave:"\\`u", Ugrave:"\\`U", uuml:"\\\"u", Uuml:"\\\"U", yacute:"\\'y",
Yacute:"\\'Y", yuml:"\\\"y", abreve:"\\u{a}", Abreve:"\\u{A}", amacr:"\\=a",
Amacr:"\\=A", aogon:"\\k{a}", Aogon:"\\k{A}", cacute:"\\'c", Cacute:"\\'C",
ccaron:"\\v{c}", Ccaron:"\\v{C}", ccirc:"\\^c", Ccirc:"\\^C", cdot:"\\.c",
Cdot:"\\.C", dcaron:"\\v{d}", Dcaron:"\\v{D}", dstrok:"{\\dj}", Dstrok:"{\\DJ}",
ecaron:"\\v{e}", Ecaron:"\\v{E}", edot:"\\.e", Edot:"\\.E", emacr:"\\=e",
Emacr:"\\=E", eogon:"\\k{e}", Eogon:"\\k{E}", gacute:"\\'g", gbreve:"\\u{g}",
Gbreve:"\\u{G}", Gcedil:"\\c{G}", gcirc:"\\^g", Gcirc:"\\^G", gdot:"\\.g",
Gdot:"\\.G", hcirc:"\\^h", Hcirc:"\\^H", hstrok:"\u0127", Hstrok:"\u0126",
Idot:"\\.I", Imacr:"\\=I", imacr:"\\={\\i}", ijlig:"\\symbol{188}",
IJlig:"\\symbol{156}", inodot:"{\\i}", iogon:"\\k{i}", Iogon:"\\k{I}",
itilde:"\\~{\\i}", Itilde:"\\~I", jcirc:"\\^{\\j}", Jcirc:"\\^J",
kcedil:"\\c{k}", Kcedil:"\\c{K}", kgreen:"\u0138", lacute:"\\'l", Lacute:"\\'L",
lcaron:"\\v{l}", Lcaron:"\\v{L}", lcedil:"\\c{l}", Lcedil:"\\c{L}",
lmidot:"\u0140", Lmidot:"\u013F", longs:"{\\textlongs}", lstrok:"{\\l}", Lstrok:"{\\L}", nacute:"\\'n",
Nacute:"\\'N", eng:"{\\ng}", ENG:"{\\NG}", napos:"\u0149", ncaron:"\\v{n}",
Ncaron:"\\v{N}", ncedil:"\\c{n}", Ncedil:"\\c{N}", odblac:"\\H{o}",
Odblac:"\\H{O}", Omacr:"\\=O", omacr:"\\=o", oelig:"{\\oe}", OElig:"{\\OE}",
racute:"\\'r", Racute:"\\'R", rcaron:"\\v{r}", Rcaron:"\\v{R}", rcedil:"\\c{r}",
Rcedil:"\\c{R}", sacute:"\\'s", Sacute:"\\'S", scaron:"\\v{s}", Scaron:"\\v{S}",
scedil:"\\c{s}", Scedil:"\\c{S}", scirc:"\\^s", Scirc:"\\^S", tcaron:"\\v{t}",
Tcaron:"\\v{T}", tcedil:"\\c{t}", Tcedil:"\\c{T}", tstrok:"\u0167",
Tstrok:"\u0166", ubreve:"\\u{u}", Ubreve:"\\u{U}", udblac:"\\H{u}",
Udblac:"\\H{U}", umacr:"\\=u", Umacr:"\\=U", uogon:"\\k{u}", Uogon:"\\k{U}",
uring:"\\r{u}", Uring:"\\r{U}", utilde:"\\~u", Utilde:"\\~U", wcirc:"\\^w",
Wcirc:"\\^W", ycirc:"\\^y", Ycirc:"\\^Y", Yuml:"\\\"Y", zacute:"\\'z",
Zacute:"\\'Z", zcaron:"\\v{z}", Zcaron:"\\v{Z}", zdot:"\\.z", Zdot:"\\.Z",
half:"\\nicefrac{1}{2}", frac12:"\\nicefrac{1}{2}", frac14:"\\nicefrac{1}{4}",
frac34:"\\nicefrac{3}{4}", frac18:"\\nicefrac{1}{8}", frac38:"\\nicefrac{3}{8}",
frac58:"\\nicefrac{5}{8}", frac78:"\\nicefrac{7}{8}",
sup1:"{\\textonesuperior}", sup2:"{\\texttwosuperior}",
sup3:"{\\textthreesuperior}", plus:"\u002B", plusmn:"{\\textplusminus}",
lt:"{\\textless}", equals:"\u003D", gt:"{\\textgreater}",
divide:"{\\textdivide}", times:"{\\textmultiply}", curren:"{\\textcurrency}",
pound:"{\\pounds}", dollar:"{\\textdollar}", cent:"{\\textcent}",
yen:"{\\textyen}", num:"\\#", percnt:"\\%", amp:"\\&", ast:"\u002A",
commat:"\u0040", lsqb:"\u005B", bsol:"{\\textbackslash}", rsqb:"\u005D",
lcub:"\\{", horbar:"{\\textemdash}", verbar:"\u007C", rcub:"\\}",
micro:"{\\textmu}", ohm:"{\\textohm}", deg:"{\\textdegree}",
ordm:"{\\textordmasculine}", ordf:"{\\textordfeminine}", sect:"{\\textsection}",
para:"{\\textparagraph}", middot:"{\\textperiodcentered}",
larr:"{\\textleftpointingarrow}", rarr:"{\\textrightpointingarrow}",
uarr:"{\\textarrowup}", darr:"{\\textarrowdown}", copy:"{\\textcopyright}",
reg:"{\\textregistered}", trade:"{\\texttrademark}", brvbar:"{\\textbrokenbar}",
not:"{\\textlogicalnot}", sung:"\u2669", excl:"\u0021",
iexcl:"{\\textexclamdown}", quot:"{\\textquotedbl}", apos:"{\\textquotesingle}",
lpar:"\u0028", rpar:"\u0029", comma:"\u002C", lowbar:"\\_", hyphen:"\u002D",
period:"\u002E", sol:"\u002F", colon:"\u003A", semi:"\u003B", quest:"\u003F",
iquest:"{\\textquestiondown}", laquo:"{\\guillemotleft}",
raquo:"{\\guillemotright}", lsquo:"{\\textquoteleft}",
rsquo:"{\\textquoteright}", ldquo:"``", rdquo:"''", nbsp:"~", shy:"\\-",
emsp:"{\\kern1em}", ensp:"{\\enspace}", emsp13:"{\\kern.33em}",
emsp14:"{\\kern.25em}", numsp:"\u2007", puncsp:"{\\kern1pt}", thinsp:"\\,",
hairsp:"{\\kern.1em}", mdash:"---", ndash:"--", dash:"\u2010",
blank:"{\\textvisiblespace}", hellip:"{\\dots}", nldr:"\u2025",
frac13:"\\nicefrac{1}{3}", frac23:"\\nicefrac{2}{3}", frac15:"\\nicefrac{1}{5}",
frac25:"\\nicefrac{2}{5}", frac35:"\\nicefrac{3}{5}", frac45:"\\nicefrac{4}{5}",
frac16:"\\nicefrac{1}{6}", frac56:"\\nicefrac{5}{6}", incare:"\\nicefrac{c}{o}",
block:"\u2588", uhblk:"\u2580", lhblk:"\u2584", blk14:"\u2591", blk12:"\u2592",
blk34:"\u2593", marker:"\u25AE", cir:"\u25CB", squ:"\u25A1", rect:"\u25AD",
utri:"\u25B5", dtri:"\u25BF", star:"\u22C6", bull:"{\\textbullet}",
squf:"\u25AA", utrif:"\u25B4", dtrif:"\u25BE", ltrif:"\u25C2", rtrif:"\u25B8",
clubs:"\u2663", diams:"\u2666", hearts:"\u2665", spades:"\u2660", malt:"\u2720",
dagger:"{\\textdagger}", Dagger:"{\\textdaggerdbl}", check:"\u2713",
cross:"\u2717", sharp:"\u266F", flat:"\u266D", male:"\u2642", female:"\u2640",
phone:"\u260E", telrec:"\u2315", copysr:"\u2117", caret:"\\symbol{094}",
lsquor:"{\\quotesinglbase}", ldquor:"{\\quotedblbase}", fflig:"\uFB00",
filig:"\uFB01", ffilig:"\uFB03", ffllig:"\uFB04", fllig:"\uFB02", mldr:"\u2026",
rdquor:"{\\textquotedblleft}", rsquor:"{\\textquoteleft}", vellip:"\u22EE",
hybull:"\u2043", loz:"\u25CA", lozf:"\u2726", ltri:"\u25C3", rtri:"\u25B9",
starf:"\u2605", natur:"\u266E", rx:"{\\textrecipe}", sext:"\u2736",
target:"\u2316", dlcrop:"\u230D", drcrop:"\u230C", ulcrop:"\u230F",
urcrop:"\u230E", circ:"{\\textasciicircum}", tilde:"{\\textasciitilde}",
sbquo:"{\\quotesinglbase}", bdquo:"{\\quotedblbase}",
lsaquo:"{\\guilsinglleft}", rsaquo:"{\\guilsinglright}", euro:"{\\texteuro}" };


function TeXML2TeX(oTeXML) {  // returns String

const pfx = (oTeXML.prefix && oTeXML.namespaceURI=='http:\/\/www.unterstein.net\/ML\/TeXML') ? oTeXML.prefix+':' : '' ;

var t_match = {1:[],2:[],3:[],4:[],5:[],6:[],7:[],8:[],9:[],10:[],11:[],12:[]};  //  nodeType-Object/Array
    t_match[1][pfx+'TeXML'] = applyTemplates;
    t_match[1][pfx+'ANY']   = applyTemplates;
    t_match[1][pfx+'TeX']   = applyTemplates;
    t_match[1][pfx+'cmd']   = templateCMD;
    t_match[1][pfx+'env']   = templateENV;
    t_match[1][pfx+'opt']   = templateOPT;
    t_match[1][pfx+'arg']   = templateARG;
    t_match[1][pfx+'grp']   = templateGRP;
    t_match[1][pfx+'act']   = function(o) { return templateAttr(o,'on',''); }
    t_match[1][pfx+'par']   = function(o) { return applyTemplates(o)+'\n'; }
    t_match[1][pfx+'x']     = function(o) { return applyTemplates(o)+'\n'; }
    t_match[7]['TeX']       = function(o) { return o.nodeValue; }      //  processing_instruction_node
    t_match[3]['#text']          = function(o) { return o.nodeValue; } //  text_node
    t_match[4]['#cdata-section'] = function(o) { return o.nodeValue; } //  cdata_section_node
    t_match[1]['xhtml:a']        = templateA;
    t_match[1]['xhtml:img']      = function(o) { return '\\hyperimg{'+templateAttr(o,'src','')+'}'; }
    t_match[1]['xhtml:thead']    = templateTgroup;
    t_match[1]['xhtml:tfoot']    = templateTgroup;
    t_match[1]['xhtml:tbody']    = templateTgroup;
    t_match[1]['xhtml:tr']       = function(o) { o.normalize(); return applyTemplates(o)+' \\\\'; }
    t_match[1]['xhtml:td']       = templateTDTH;
    t_match[1]['xhtml:th']       = templateTDTH;
    //  isanENTITAG(o) creates t_match[1] entries on-the-fly and prefix-aware
    //  isanENTIREF(o) creates t_match[5] entries on-the-fly (for IE to resolve enitiy-references and nodes in entities)

    function templateCMD(o) {  //  if not(args)+empty(cmd)+following(textnode): command<space>text  
        return [ 
        '\\'+templateAttr(o,'name','')+templateAttr(o,'args',(((!o.hasChildNodes())&&o.nextSibling&&(o.nextSibling.nodeType==Node.TEXT_NODE))?' ':'')) ,
        applyTemplates(o) 
        ].join('');
    }
    function templateENV(o) {
        var envname = new String(templateAttr(o,'bg','{')+templateAttr(o,'name','')+templateAttr(o,'eg','}'));
		return [
        templateAttr(o,'bc','\\begin')+envname+templateAttr(o,'args','') ,
        applyTemplates(o) ,
        templateAttr(o,'ec','\\end')+envname 
        ].join('');
    }
    function templateOPT(o) {
        return [
        templateAttr(o,'bg','[') ,
        applyTemplates(o) ,
        templateAttr(o,'eg',']')
        ].join('');
    }
    function templateARG(o) {
        return [
        templateAttr(o,'bg','{') ,
        applyTemplates(o) ,
        templateAttr(o,'eg','}')
        ].join('');
    }
    function templateGRP(o) {
        return [
        templateAttr(o,'bg','{')+templateAttrNMTOKENS(o,'name') ,
        applyTemplates(o) ,
        templateAttr(o,'eg','}')
        ].join('');
    }
    function templateA(o) {
        var results = new String('');
        var idlabel = templateAttr(o,'id',false);
        var hrefstr = templateAttr(o,'href',false);
        var idhyper = (o.hasChildNodes() && !hrefstr && idlabel);
        //  forematter
        if (idlabel && hrefstr)
        {
         results += '\\label{'+idlabel+'}';
        }
        //  childNodes
        if (hrefstr)
        {
         if (hrefstr.charAt(0) == '#')
             results += '\\hyperlink{'+hrefstr.slice(1)+'}{'+applyTemplates(o)+'}';
         else
             results += '\\href{'+hrefstr+'}{'+applyTemplates(o)+'}';
        }
        else  //  not hrefstr
        {
         if (idhyper)
             results += '\\hypertarget{'+idlabel+'}{'+applyTemplates(o)+'}';
         else
             results += '\\label{'+idlabel+'}';
        }
        //
        return results;
    }
    function templateTgroup(o) {
        var results = new String('');
        var oTgroup = new Object();
        //  childNodes
        //  if (o.localName == 'thead') return results;
        //  if (o.localName == 'tfoot') return results;
        if (o.localName == 'tbody')
            {
            var pfx = (isMSIE && o.prefix && o.namespaceURI=='http:\/\/www.w3.org\/1999\/xhtml') ? o.prefix+':' : '' ;
            oTgroup = o.parentNode.getElementsByTagName(pfx+'thead');
            for (var i=0; i<oTgroup.length; i++) results += applyTemplates(oTgroup[i]);
            oTgroup = o.parentNode.getElementsByTagName(pfx+'tbody');
            for (var i=0; i<oTgroup.length; i++) results += applyTemplates(oTgroup[i]);
            oTgroup = o.parentNode.getElementsByTagName(pfx+'tfoot');
            for (var i=0; i<oTgroup.length; i++) results += applyTemplates(oTgroup[i]);
            }
        //
        return results;
    }
    function templateTDTH(o) {
        var results = new String('');
        var colspan = (o.hasAttribute('colspan')&&o.getAttributeNode('colspan').specified) ? '\\multicolumn{'+o.getAttribute('colspan')+'}{'+templateAttr(o,'align','c').charAt(0)+'}{' : '' ;
        //  forematter
        if (colspan!='') results += colspan;
        if (o.localName == 'th') results += '\\bfseries ';
        //  childNodes
        results += applyTemplates(o);
        //  backmatter
        if (colspan!='') results += '}';
        if (o.nextSibling && (o.nextSibling instanceof HTMLTableCellElement || o.nextSibling.nextSibling)) results += ' & ';
        //
        return results;
    }
    function templateENTITAG(o) {
        //
        return templateAttr(o,'texcode',ent[o.localName]);
    }


    function templateAttr(o, strAttrName, strDefaultValue) {
        return (o.hasAttribute(strAttrName)) ? o.getAttribute(strAttrName) : strDefaultValue ;
    }
    const nmtoken = new RegExp().compile('\\s*\\b(\\S+)\\b\\s*','g');
    function templateAttrNMTOKENS(o, strAttrName) {
        var results = (o.hasAttribute(strAttrName)) ? o.getAttribute(strAttrName).replace(nmtoken,'\\$1') : '' ;
        return ((results!='') && o.hasChildNodes() && (o.firstChild.nodeType==Node.TEXT_NODE)) ? results+' ' : results ;  //  commands space contents
    }
    function templateAttrXLink(o, strAttrName, strDefaultValue) {
        return (o.hasAttributeNS('http:\/\/www.w3.org\/1999\/xlink',strAttrName)) ? o.getAttributeNS('http:\/\/www.w3.org\/1999\/xlink',strAttrName) : strDefaultValue ;
    }

    function isTeXML(o) {
        switch (o.nodeType) {
        case Node.ELEMENT_NODE :
            return (isELofTeXML(o)) ? !isEXCLUSIVE(o,'xml') : isanENTITAG(o) ;
            break;                                                    //  1
        case Node.ATTRIBUTE_NODE :              return false; break;  //  2
        case Node.TEXT_NODE :
            return  (!(o.parentNode instanceof HTMLTableRowElement));
            break;                                                    //  3  nodeName=#text
        case Node.CDATA_SECTION_NODE :          return true;  break;  //  4  nodeName=#cdata-section
        case Node.ENTITY_REFERENCE_NODE :
            return isanENTIREF(o);
            break;                                                    //  5
        case Node.ENTITY_NODE :                 return false; break;  //  6
        case Node.PROCESSING_INSTRUCTION_NODE : 
			return isPIofTeXML(o); 
			break;  												  //  7
        case Node.COMMENT_NODE :                return false; break;  //  8  nodeName=#comment
        case Node.DOCUMENT_NODE :               return false; break;  //  9  nodeName=#document
        case Node.DOCUMENT_TYPE_NODE :          return false; break;  // 10
        case Node.DOCUMENT_FRAGMENT_NODE :      return false; break;  // 11  nodeName=#document-fragment
        case Node.NOTATION_NODE :               return false; break;  // 12
        default :                               return false; break;
        }   //  switch
    }       //  function
    function isEXCLUSIVE(o,token) {
        return ((templateAttr(o,'type','')==token) || (templateAttr(o,'role','')==token) || (templateAttr(o,'mode','')==token));
    }
    function isELofTeXML(o) {
        return (o.nodeName in t_match[Node.ELEMENT_NODE]);
    }
    function isPIofTeXML(o) {
        return (o.nodeName in t_match[Node.PROCESSING_INSTRUCTION_NODE]);
    }
    function isanENTITAG(o) {  //  (o.nodeName in t_match[Node.ELEMENT_NODE]) is already false -- if possible creates t_match entry on-the-fly as side-effect
        return (o.namespaceURI=='urn:entitags:entity-as-empty-element-tag' && o.localName in ent) ? (t_match[Node.ELEMENT_NODE][o.nodeName]=templateENTITAG,true) : false ;
    }
    function isanENTIREF(o) {  //  always true, but as side-effect creates t_match[Node.ENTITY_REFERENCE_NODE] entry on-the-fly
        return (o.nodeName in t_match[Node.ENTITY_REFERENCE_NODE]) ? true : (t_match[Node.ENTITY_REFERENCE_NODE][o.nodeName]=applyTemplates,true) ;
    }

    function applyTemplates(o) {
        var results = new String('');
        for (var c=o.firstChild; c!=null; c=c.nextSibling)
        {
        if (isTeXML(c)) results += t_match[c.nodeType][c.nodeName](c);
        }
        return results;
    }

    function templateROOT(o) {
        var results = new String('');
        results = (isTeXML(o)) ? t_match[o.nodeType][o.nodeName](o) : '%%  not a TeXML-object or of role\/type=\"xml\": '+o.nodeName+' '+o.toString()+'  %%' ;
        return results;
    }

    return templateROOT(oTeXML);  // returns String

}  //  TeXML2TeX Transformer

// OpenTarget2(transformDOMTeXMLtoTeX(document.documentElement));
// OpenTarget2(transformNodeTeXML2TeX(document.documentElement));
// OpenTarget2(TeXML2TeXfromNode(document.documentElement));
// OpenTarget2(TeXMLTransformDOMNodeToTeX(document.documentElement));
// OpenTarget2(TeXtransfromTeXML(document.documentElement));

const TFpreface = new String('\n%%'+
                             '\n%%  Transformed (maybe w\/o some nodes) by'+
                             '\n%%    an experimental non-XSLT DOM\/JavaScript*'+
                             '\n%%    cf http:\/\/www.unterstein.net\/ML\/TeXML.js*'+
                             '\n%%    cf http:\/\/www.unterstein.net\/ML\/TeXML2TeX.js'+
                             '\n%%    [variant includes MSIE6+, MSXML 3.x\/4.x, WSH 5.6]'+
                             '\n%%    cf http:\/\/www.unterstein.net\/TeXML.html#localfiles'+
                             '\n%%    \n');

function transformTeXMLtoTeX(oTeXML) { return TFpreface+TeXML2TeX(oTeXML); }

function OpenTarget2(rStr) {
    var rOut=window.open('about:blank', 'two');
        rOut.document.open('text\/html');
        rOut.document.write(targetSrc.xhtml11pre);
        rOut.document.close();
        rOut.document.title='ML \u00B7 DOM\/Script Transformer Result';
    var rPre=rOut.document.getElementById('resultPre');
        rPre.style.font='normal 9pt\/13pt \'andale mono\', \'bitstream vera sans mono\', \'lucida console\', \'lucida sans typewriter\', \'ocr a extended\', \'courier new\', courier, monospace';
        rPre.firstChild.nodeValue=rStr;
}




/*

    function templateNN(o) {
        var results = new String('');
        //  forematter
        results += ;
        //  childNodes
        results += applyTemplates(o);
        //  backmatter
        results += ;
        //
        return results;
    }

 */

// -----------------------------------------------------------------
// EOF TeXML.js
// -----------------------------------------------------------------