// -----------------------------------------------------------------
// -----------------------------------------------------------------
/*
**
** Copyleft (c) 2006 by Stefan Unterstein [http://www.unterstein.net/]
**
*/
// -----------------------------------------------------------------
// -----------------------------------------------------------------

// -----------------------------------------------------------------
/*@cc_on @*/  // conditional compiling since IE4's JScript3 e.g. /*@if (@_jscript)  IFIE  @else @*/  ELSE  /*@end @*/
// -----------------------------------------------------------------

// -----------------------------------------------------------------
// MSXML 3/4/5/6 ActiveXObject ProgIDs Initialization (or Emulation)
// -----------------------------------------------------------------

var AXO = {
    // -----------------------------------------------------------------
    // get latest PID, or NULL for non-IE
    // -----------------------------------------------------------------
    getPID : function (oPID) {
        /*@if (@_jscript)
            for (var ProgID in oPID) {
                try {
                    var AXObj = new ActiveXObject(ProgID);
                    return ProgID;
                } catch (noop) {
                } //End: try
            } //End: for
            throw "[xslt.js] inActiveX ?: no MSXML ActiveXObject ProgID(s) found, thus no XML-file(s) loadable.";
          @else @*/ return null;
        /*@end @*/
    }, //End: function
    // -----------------------------------------------------------------
    // set individual PID-Ref, default RefToken to internal token, or init all PIDs with internal tokens
    // -----------------------------------------------------------------
    setPID : function (pidRefToken,pidObjTypeStr) {
        if (pidRefToken)
        this[pidRefToken]=this.getPID(this.objPID[pidObjTypeStr||pidRefToken]);
        else for (pidRefToken in this.objPID) this.setPID(pidRefToken);
    }, //End: function
    // -----------------------------------------------------------------
    // PID-Strings as object/array-selectors
    // -----------------------------------------------------------------
    objPID : {
        DOMDocument : { "MSXML2.DOMDocument.6.0":6 , "MSXML2.DOMDocument.5.0":5 , "MSXML2.DOMDocument.4.0":4 , "MSXML2.DOMDocument.3.0":3 , "MSXML2.DOMDocument":2 , "MSXML.DOMDocument":1 },
        XSLTemplate : { "MSXML2.XSLTemplate.6.0":6 , "MSXML2.XSLTemplate.5.0":5 , "MSXML2.XSLTemplate.4.0":4 , "MSXML2.XSLTemplate.3.0":3 , "MSXML2.XSLTemplate":2 },
        FTDOMDocument  : { "MSXML2.FreeThreadedDOMDocument.6.0":6 , "MSXML2.FreeThreadedDOMDocument.5.0":5 , "MSXML2.FreeThreadedDOMDocument.4.0":4 , "MSXML2.FreeThreadedDOMDocument.3.0":3 , "MSXML2.FreeThreadedDOMDocument":2 , "MSXML.FreeThreadedDOMDocument":1 },
        XMLHttpRequest : { "MSXML2.XMLHTTP.6.0":6 , "MSXML2.XMLHTTP.5.0":5 , "MSXML2.XMLHTTP.4.0":4 , "MSXML2.XMLHTTP.3.0":3 , "MSXML2.XMLHTTP":2 , "Microsoft.XMLHTTP":1  }
    } //End: object
    // -----------------------------------------------------------------
} //End: object

try {
    AXO.setPID('DOMDoc_PID','DOMDocument');
    AXO.setPID('XSLTmp_PID','XSLTemplate');
    AXO.setPID('FTDOMD_PID','FTDOMDocument');
    AXO.setPID('HttpRq_PID','XMLHttpRequest');
} catch (noop) { alert(noop); } // one error-message is enough if inActiveX

// -----------------------------------------------------------------
// -----------------------------------------------------------------
/*@if (@_jscript)
// -----------------------------------------------------------------

if (window.Node==null) {        //  IE4,IE5,IE6
    var Node = {
    ELEMENT_NODE:1,
    ATTRIBUTE_NODE:2,
    TEXT_NODE:3,                //  nodeName=#text
    CDATA_SECTION_NODE:4,       //  nodeName=#cdata-section
    ENTITY_REFERENCE_NODE:5,
    ENTITY_NODE:6,
    PROCESSING_INSTRUCTION_NODE:7,
    COMMENT_NODE:8,             //  nodeName=#comment
    DOCUMENT_NODE:9,            //  nodeName=#document
    DOCUMENT_TYPE_NODE:10,
    DOCUMENT_FRAGMENT_NODE:11,  //  nodeName=#document-fragment
    NOTATION_NODE:12
    } // var
}     // if

if (!window.XMLHttpRequest) {
     window.XMLHttpRequest = function(){
        return new ActiveXObject(AXO.HttpRq_PID);
        }; //End: function
        //Usage: var xREQ = new XMLHttpRequest();
} //End: if

if (!window.XMLSerializer) {
     window.XMLSerializer = function(){ this.SELF = this; return this; };
    XMLSerializer.prototype.serializeToStream = function(oNode,outStream,charSet) {}
    XMLSerializer.prototype.serializeToString = function(oNode) {
        if (oNode==null) return '@@void|null@@';
        try {
        return {
             0 : function (o) { return o.xml||this[o.nodeType||typeof(o)](o); },
             1 : function (o) { return o.outerHTML; },
             2 : function (o) { return o.nodeName+'=\"'+o.nodeValue+'\"'; },
             3 : function (o) { return o.nodeValue; },
             4 : function (o) { return '<![CDATA['+o.nodeValue+']]>'; },
             5 : function (o) { return ; },
             6 : function (o) { return ; },
             7 : function (o) { return '<?'+o.nodeName+' '+o.nodeValue+'?>'; },
             8 : function (o) { return '<!--'+o.nodeValue+'-->'; },
             9 : function (o) { return o.documentElement.outerHTML; },
            10 : function (o) { return ; },
            11 : function (o) { return ; },
            12 : function (o) { return ; },
            "object" :    function (o) { return '@@object@@\r\n'+o; },
            "string" :    function (o) { return '@@string@@\r\n'+o; },
            "number" :    function (o) { return '@@number@@\r\n'+o; },
            "boolean" :   function (o) { return '@@boolean@@\r\n'+o; },
            "function" :  function (o) { return '@@function@@\r\n'+o; },
            "undefined" : function (o) { return '@@undefined@@\r\n'; }
            }[0](oNode);
        } catch(e) { return '[XMLSerializer] '+(e.description||e.message); }
    }; //End: method
    //Usage: var xSER = new XMLSerializer();
} //End: if

if (!window.DOMParser) {
     window.DOMParser = function(){
        this.prototype = new ActiveXObject(AXO.DOMDoc_PID);
		try { this.prototype.setProperty("NewParser", true); } catch(e) {}
        this.SELF = this; return this;
        }; //End: function
    DOMParser.prototype.parseFromBuffer = function(aBuf,bufferLength,contentType) {};
    DOMParser.prototype.parseFromStream = function(sInp,contentLength,contentType) {};
    DOMParser.prototype.parseFromString = function(sStr,contentType) {
        try { return this.prototype.loadXML(sStr); } catch(e) { throw '[DOMParser] '+(e.description||e.message); }
    }; //End: method
    //Usage: var DOMp = new DOMParser();
} //End: if

if (!window.XSLTProcessor) {
     window.XSLTProcessor = function(){
        this.tXSL = new ActiveXObject(AXO.XSLTmp_PID);
        this.oXSL = new ActiveXObject(AXO.FTDOMD_PID);
        try { // default false MSXML 6.0
			this.tXSL.setProperty("AllowDocumentFunction", true); 
			this.oXSL.setProperty("AllowDocumentFunction", true); 
		} catch(e) {}
        try { // default false MSXML 6.0
			this.tXSL.setProperty("AllowXsltScript", true); 
			this.oXSL.setProperty("AllowXsltScript", true); 
		} catch(e) {}	
        try { // default true  MSXML 6.0
			this.tXSL.setProperty("ProhibitDTD", false); 
			this.oXSL.setProperty("ProhibitDTD", false); 
		} catch(e) {}	
        this.pXSL = new Object();
        this.SELF = this; return this;
        }; //End: function
    XSLTProcessor.prototype.importStylesheet = function(stylesNode) {
        try {
            // xsl with internal DTD subset not convertible to free threaded dom ?
            // because <!DOCTYPE xsl:stylesheet [subset]> prevents proper (re-)parsing ?
            //
            // this.oXSL.load(stylesNode);
            // this.oXSL.write(stylesNode.xml);
            // stylesNode.save(this.oXSL.XMLDocument);
            //
            this.oXSL.loadXML(stylesNode.xml);
            this.tXSL.stylesheet = this.oXSL;
            this.pXSL = this.tXSL.createProcessor();
        } catch(e) { throw '[XSLTPimportSty] '+(e.description||e.message); }
    }; //End: method
    XSLTProcessor.prototype.transformToDocument = function(sourceNode) {
        try {
            this.pXSL.input = sourceNode;
            this.pXSL.output = new ActiveXObject(AXO.DOMDoc_PID);
            this.pXSL.transform();    return this.pXSL.output;
        } catch(e) { throw '[XSLTP2Document] '+(e.description||e.message); }
    }; //End: method
    XSLTProcessor.prototype.transformToFragment = function(sourceNode,ownerDocNode) {
        try {
            this.pXSL.input = sourceNode;
            this.pXSL.output = document.createDocumentFragment();  // NOOP!
            this.pXSL.transform();    return this.pXSL.output;
        } catch(e) { throw '[XSLTP2Fragment] '+(e.description||e.message); }
    }; //End: method
    //Usage: var XSLp = new XSLTProcessor();
} //End: if

// -----------------------------------------------------------------
  @end @*/
// -----------------------------------------------------------------
// -----------------------------------------------------------------


function XSLTransfactory(fXML, evToDoXML, fXSL, evToDoXSL, Task) {
    // -----------------------------------------------------------------
    var  FACT = this;
    this.SELF = this;
    this.Report = ['@@[XSLTransfactory] report'];
    this.updateReport = function(s) {
        if (s instanceof Array)    this.Report=this.Report.concat(s);
        else if ((typeof(s)=='string')||(s instanceof String)) this.Report[this.Report.length]=s; }
    this.returnReport = function()  { return this.Report.join('\r\n')+'\r\n@@\r\n'; }
    this.removeReport = function()  { this.Report=['@@[XSLTransfactory]  report']; }
    // -----------------------------------------------------------------
    this.fXML = fXML||false;
    this.evToDoXML = evToDoXML||null;
    this.fXSL = fXSL||false;
    this.evToDoXSL = evToDoXSL||null;
    this.Task = Task||'@@none on init@@';
    // -----------------------------------------------------------------
    // this.pXML = (DOMParser) ? new DOMParser() : new Object() ;
    this.pXSL = (XSLTProcessor)  ? new XSLTProcessor()  : new Object() ;
    this.pSER = (XMLSerializer)  ? new XMLSerializer()  : new Object() ;
    this.qXML = (XMLHttpRequest) ? new XMLHttpRequest() : new Object() ;
    this.qXSL = (XMLHttpRequest) ? new XMLHttpRequest() : new Object() ; // one should be enough !?
    // -----------------------------------------------------------------
    this.hXML = new String('[headerXML] @@no request\/response\/header result@@');
    this.hXSL = new String('[headerXSL] @@no request\/response\/header result@@');
    this.oXML = /*@if (@_jscript) new ActiveXObject(AXO.DOMDoc_PID); @else @*/ document.implementation.createDocument('', '', null); /*@end @*/
    this.oXSL = /*@if (@_jscript) new ActiveXObject(AXO.DOMDoc_PID); @else @*/ document.implementation.createDocument('', '', null); /*@end @*/
	/*@if (@_jscript) 
		this.updateReport('[onlyMSXML] ActiveXObject \"'+AXO.DOMDoc_PID+'\"'); 
		this.updateReport('[onlyMSXML] ActiveXObject \"'+AXO.XSLTmp_PID+'\"'); 
		this.updateReport('[onlyMSXML] ActiveXObject \"'+AXO.FTDOMD_PID+'\"'); 
		this.updateReport('[onlyMSXML] ActiveXObject \"'+AXO.HttpRq_PID+'\"'); 
	  @end @*/
    // -----------------------------------------------------------------
    this.getSourceXML = function()  { return this.pSER.serializeToString(this.oXML); }
    this.getSourceXSL = function()  { return this.pSER.serializeToString(this.oXSL); }
    this.getSourceStr = function(o) { return this.pSER.serializeToString(o); }
    // -----------------------------------------------------------------
    this.readyStatesXML  = { 0:[null],1:[null],2:[null],3:[null],4:[null] };
    this.readyStatesXSL  = { 0:[null],1:[null],2:[null],3:[null],4:[null] };
    this.readyState4XML  = [];
    this.readyState4XSL  = [];
    void(this.readyStatesXML[0].push(function(ev){ FACT.updateReport('[statusXML] rS=0 : UNINITIALIZED'); }));
    void(this.readyStatesXML[1].push(function(ev){ FACT.updateReport('[statusXML] rS=1 : LOADING'); }));
    void(this.readyStatesXML[2].push(function(ev){ FACT.updateReport('[statusXML] rS=2 : LOADED'); }));
    void(this.readyStatesXML[3].push(function(ev){ FACT.updateReport('[statusXML] rS=3 : INTERACTIVE'); }));
    void(this.readyStatesXML[4].push(function(ev){ FACT.updateReport('[statusXML] rS=4 : COMPLETED'); }));
    void(this.readyStatesXSL[0].push(function(ev){ FACT.updateReport('[statusXSL] rS=0 : UNINITIALIZED'); }));
    void(this.readyStatesXSL[1].push(function(ev){ FACT.updateReport('[statusXSL] rS=1 : LOADING'); }));
    void(this.readyStatesXSL[2].push(function(ev){ FACT.updateReport('[statusXSL] rS=2 : LOADED'); }));
    void(this.readyStatesXSL[3].push(function(ev){ FACT.updateReport('[statusXSL] rS=3 : INTERACTIVE'); }));
    void(this.readyStatesXSL[4].push(function(ev){ FACT.updateReport('[statusXSL] rS=4 : COMPLETED'); }));
    // -----------------------------------------------------------------
    this.rDoc = /*@if (@_jscript) new ActiveXObject(AXO.DOMDoc_PID); @else @*/ document.implementation.createDocument('', '', null); /*@end @*/
    this.rDFr = document.createDocumentFragment();
    this.rSrc = new String('[resultSrc] @@no xml-serialization result@@');
    // -----------------------------------------------------------------
    // -----------------------------------------------------------------

    this.factoryTask(); // here we go for predefined tasks, but maybe none is specified

    // -----------------------------------------------------------------
    // -----------------------------------------------------------------
    return this;
} //End: function XSLTransfactory


XSLTransfactory.prototype.factoryTask = function(Task) {
    var  FACT=this.SELF;
    this.updateReport('[TaskToken] '+(Task||this.Task));
    switch (Task||this.Task)
       {
        case 'load' :
            if (this.fXML) { this.fnLoadXML(); }
            if (this.fXSL) { this.fnLoadXSL(); }
        break;
        case 'open' :
            if (this.fXML) { this.fnOpenXML(); }
            if (this.fXSL) { this.fnOpenXSL(); }
            //
            // NOOP if qXML is the one and only instance of XMLHttpRequest
            /*
            if (this.fXML&&this.fXSL) {
                void(this.readyState4XML.push(function(ev){if(FACT.qXML.status==200)FACT.fnOpenXSL();}));
                this.fnOpenXML();
            } else if (this.fXML) { this.fnOpenXML();
            } else if (this.fXSL) { this.fnOpenXSL();
            }
            */
        break;
        case 'load+pi' :
            if (this.fXML&&this.fXSL) {
                void(this.readyState4XML.push(function(ev){FACT.setXMLPI2XSL();}));
                this.fnLoadXML();
            } else if (this.fXML) {
                void(this.readyState4XML.push(function(ev){FACT.fXSL=FACT.getXMLPI4XSL(); if (!FACT.isFragmentID()) FACT.fnLoadXSL(); }));
                this.fnLoadXML();
            }
        break;
        case 'load+transform' :
            if (this.fXML&&this.fXSL) {
                void(this.readyState4XML.push(function(ev){FACT.fnLoadXSL();}));
                void(this.readyState4XSL.push(function(ev){FACT.fnFormXML();}));
                this.fnLoadXML();
            }
        break;
        case 'open+transform' :
            if (this.fXML&&this.fXSL) {
                void(this.readyState4XML.push(function(ev){if(FACT.qXML.status==200)FACT.fnOpenXSL();}));
                void(this.readyState4XSL.push(function(ev){if(FACT.qXSL.status==200)FACT.fnFormXML();}));
                this.fnOpenXML();
            }
        break;
        case '@@none on init@@' : break;
        default : this.updateReport('[TaskNoOps] unknown TaskToken'); break;
       } //End: switch
}

XSLTransfactory.prototype.fnSetXProps = function (o,fnEv) { fnEv=fnEv||null;
    // all
    o.async=true;  // must be "false" with o.setProperty("NewParser", true);
    //
    /*@if (@_jscript)
        o.validateOnParse=false;
        o.resolveExternals=true;
        o.preserveWhiteSpace=true;
        try { o.setProperty("SelectionLanguage", "XPath"); } catch(e) { this.updateReport('[onlyMSXML] setProperty \"SelectionLanguage\" : NOT AVAILABLE'); }
        try { o.setProperty("AllowDocumentFunction", true); } catch(e) { this.updateReport('[onlyMSXML] setProperty \"AllowDocumentFunction\" : NOT AVAILABLE'); } 
        try { o.setProperty("AllowXsltScript", true); } catch(e) { this.updateReport('[onlyMSXML] setProperty \"AllowXsltScript\" : NOT AVAILABLE'); }
        try { o.setProperty("ProhibitDTD", false); } catch(e) { this.updateReport('[onlyMSXML] setProperty \"ProhibitDTD\" : NOT AVAILABLE'); }
      @else @*/ o.readyState=0;
    /*@end @*/
    //
    /*@if (@_jscript) o.onreadystatechange=function(ev){ var s=fnEv[o.readyState]; for (var f=0; f<s.length; f++) if (typeof(s[f])=='function') s[f](ev); }
      @else @*/ o.addEventListener('load', function(ev){ ev.currentTarget.readyState=4; var s=fnEv[4]; for (var f=0; f<s.length; f++) if (typeof(s[f])=='function') s[f](ev); }, false);
    /*@end @*/
}

XSLTransfactory.prototype.fnLoadXML = function(fURL) {
    var  FACT=this.SELF;
    void(this.readyStatesXML[4].push(function(ev){ FACT.updateReport('[loadedXML] '+(fURL||FACT.fXML)); }));
    void(this.readyStatesXML[4].push(function(ev){ FACT.updateReport('[available] '+((FACT.oXML.documentElement)?'<'+FACT.oXML.documentElement.nodeName+'>':'@@null@@')); }));
    this.readyStatesXML[4]=this.readyStatesXML[4].concat(this.readyState4XML);
    void(this.readyStatesXML[4].push(function(ev){ void((FACT.evToDoXML&&(typeof(FACT.evToDoXML)=='function'))&&FACT.evToDoXML(ev)); }));
    this.fnSetXProps(this.oXML,this.readyStatesXML);
    try { this.oXML.load(fURL||this.fXML); } catch(e) { this.updateReport('[onloadXML] '+(e.description||e.message)); }
}

XSLTransfactory.prototype.fnLoadXSL = function(fURL) {
    var  FACT=this.SELF;
    void(this.readyStatesXSL[4].push(function(ev){ FACT.updateReport('[loadedXSL] '+(fURL||FACT.fXSL)); }));
    void(this.readyStatesXSL[4].push(function(ev){ FACT.updateReport('[available] '+((FACT.oXSL.documentElement)?'<'+FACT.oXSL.documentElement.nodeName+'>':'@@null@@')); }));
    this.readyStatesXSL[4]=this.readyStatesXSL[4].concat(this.readyState4XSL);
    void(this.readyStatesXSL[4].push(function(ev){ void((FACT.evToDoXSL&&(typeof(FACT.evToDoXSL)=='function'))&&FACT.evToDoXSL(ev)); }));
    this.fnSetXProps(this.oXSL,this.readyStatesXSL);
    try { this.oXSL.load(fURL||this.fXSL); } catch(e) { this.updateReport('[onloadXSL] '+(e.description||e.message)); }
}

XSLTransfactory.prototype.fnOpenXML = function(fURL) {
    var  FACT=this.SELF;
    void(this.readyStatesXML[4].push(function(ev){ FACT.updateReport('[openedXML] '+(fURL||FACT.fXML)); }));
    void(this.readyStatesXML[4].push(function(ev){ if (FACT.qXML.status==200) { FACT.hXML=FACT.qXML.getAllResponseHeaders(); } else { FACT.updateReport(FACT.hXML+''); } }));
    void(this.readyStatesXML[4].push(function(ev){ FACT.updateReport('[statusXML] '+FACT.qXML.status+' : '+FACT.qXML.statusText); }));
    void(this.readyStatesXML[4].push(function(ev){ if (FACT.qXML.status==200) { FACT.oXML=FACT.qXML.responseXML; } }));
    void(this.readyStatesXML[4].push(function(ev){ FACT.updateReport('[available] '+((FACT.oXML.documentElement)?'<'+FACT.oXML.documentElement.nodeName+'>':'@@null@@')); }));
    void(this.readyStatesXML[4].push(function(ev){ if (FACT.qXML.status==200) { void((FACT.evToDoXML&&(typeof(FACT.evToDoXML)=='function'))&&FACT.evToDoXML(ev)); } }));
    this.readyStatesXML[4]=this.readyStatesXML[4].concat(this.readyState4XML);
    this.qXML.open('GET',fURL||this.fXML,true);
    this.qXML.onreadystatechange=function(ev){ var s=FACT.readyStatesXML[FACT.qXML.readyState]; for (var f=0; f<s.length; f++) if (typeof(s[f])=='function') s[f](ev); }
    this.qXML.send(null);
}

XSLTransfactory.prototype.fnOpenXSL = function(fURL) {
    var  FACT=this.SELF;
    void(this.readyStatesXSL[4].push(function(ev){ FACT.updateReport('[openedXSL] '+(fURL||FACT.fXSL)); }));
    void(this.readyStatesXSL[4].push(function(ev){ if (FACT.qXSL.status==200) { FACT.hXSL=FACT.qXSL.getAllResponseHeaders(); } else { FACT.updateReport(FACT.hXSL+''); } }));
    void(this.readyStatesXSL[4].push(function(ev){ FACT.updateReport('[statusXSL] '+FACT.qXSL.status+' : '+FACT.qXSL.statusText); }));
    void(this.readyStatesXSL[4].push(function(ev){ if (FACT.qXSL.status==200) { FACT.oXSL=FACT.qXSL.responseXML; } }));
    void(this.readyStatesXSL[4].push(function(ev){ FACT.updateReport('[available] '+((FACT.oXSL.documentElement)?'<'+FACT.oXSL.documentElement.nodeName+'>':'@@null@@')); }));
    void(this.readyStatesXSL[4].push(function(ev){ if (FACT.qXSL.status==200) { void((FACT.evToDoXSL&&(typeof(FACT.evToDoXSL)=='function'))&&FACT.evToDoXSL(ev)); } }));
    this.readyStatesXSL[4]=this.readyStatesXSL[4].concat(this.readyState4XSL);
    this.qXSL.open('GET',fURL||this.fXSL,true);
    this.qXSL.onreadystatechange=function(ev){ var s=FACT.readyStatesXSL[FACT.qXSL.readyState]; for (var f=0; f<s.length; f++) if (typeof(s[f])=='function') s[f](ev); }
    this.qXSL.send(null);
}

XSLTransfactory.prototype.fnFormXML = function() {
    /*@if (@_jscript) // <!DOCTYPE> in resulting DOMDocument causes unaccessible inner nodes
        var outputXSL;
        this.oXSL.setProperty("SelectionLanguage", "XPath");
        this.oXSL.setProperty("SelectionNamespaces", "xmlns:xsl='http://www.w3.org/1999/XSL/Transform'");
        if ((outputXSL=this.oXSL.documentElement.selectSingleNode('child::xsl:output[@doctype-public]'))!=null) { this.updateReport('[refineXSL] IE: removed xsl:output\'s doctype-public=\"'+outputXSL.getAttribute('doctype-public')+'\"'); outputXSL.removeAttribute('doctype-public'); }
        if ((outputXSL=this.oXSL.documentElement.selectSingleNode('child::xsl:output[@doctype-system]'))!=null) { this.updateReport('[refineXSL] IE: removed xsl:output\'s doctype-system=\"'+outputXSL.getAttribute('doctype-system')+'\"'); outputXSL.removeAttribute('doctype-system'); }
      @end @*/
    try {
    /*@if (@_jscript) // nothing
      @else @*/ this.pXSL.importStylesheet(this.oXSL);
    /*@end @*/  } catch(e) { this.updateReport('[importXSL] '+(e.description||e.message)); }
    finally { this.updateReport('[importXSL] IE:noop, Moz:importStylesheet'); }
    try {
    /*@if (@_jscript) this.oXML.transformNodeToObject(this.oXSL,this.rDoc);
      @else @*/ this.rDoc = this.pXSL.transformToDocument(this.oXML);
    /*@end @*/  } catch(e) { this.updateReport('[resultDoc] '+(e.description||e.message)); }
    finally { this.updateReport('[resultDoc] IE:transformNodeToObject, Moz:transformToDocument');
              this.updateReport('[available] '+((this.rDoc.documentElement)?'<'+this.rDoc.documentElement.nodeName+'>':'@@null|text@@')); }
    try {
    /*@if (@_jscript) this.rSrc = this.oXML.transformNode(this.oXSL);
      @else @*/ this.rSrc = this.pSER.serializeToString(this.rDoc);
    /*@end @*/  } catch(e) { this.updateReport('[resultSrc] '+(e.description||e.message)); }
    finally { this.updateReport('[resultSrc] IE:transformNode, Moz:serializeToString');
              this.updateReport('[available] '+this.rSrc.length+' chars'); }
    try {
    /*@if (@_jscript) this.rDFr.appendChild(document.createTextNode('@@[clientIE]\r\nno document-fragment result (howto \"fragment\" a document ?)\r\n@@'));
      @else @*/ this.rDFr = this.pXSL.transformToFragment(this.oXML, this.rDoc);
    /*@end @*/  } catch(e) { this.updateReport('[resultDFr] '+(e.description||e.message)); }
    finally { this.updateReport('[resultDFr] IE:noop, Moz:transformToFragment'); }
    //
    /*@if (@_jscript) // nothing
      @else @*/ if (this.pXSL.reset) this.pXSL.reset(); //  not implemented in Moz 1.2
    /*@end @*/
}


XSLTransfactory.prototype.setXMLPI2XSL = function(hrefXSLPI,rePI) {
    var B4Obj = this.oXML.doctype||this.oXML.documentElement;
    while (B4Obj.previousSibling/*beware: enless loop possible with &&(B4Obj.previousSibling.nodeType==Node.PROCESSING_INSTRUCTION_NODE)*/) { void(this.oXML.removeChild(B4Obj.previousSibling)); }
    var nodeXSLPI = this.oXML.createProcessingInstruction('xml-stylesheet', 'alternate=\"no\" type=\"'+/*@if (@_jscript) 'text\/xsl' @else @*/'text\/xml'/*@end @*/+'\" href=\"'+(hrefXSLPI||this.fXSL)+'\"');
    this.oXML.insertBefore(nodeXSLPI, B4Obj); this.rDoc=this.oXML; this.rSrc=this.getSourceXML();
    this.updateReport('[xmlpi2XSL] set '+this.getSourceStr(nodeXSLPI)+' from '+hrefXSLPI);
    if (rePI) return nodeXSLPI;
}

XSLTransfactory.prototype.getXMLPI4XSL = function(sourceDoc) {
    var nodeXSLPI, hrefXSLPI;
    sourceDoc=sourceDoc||this.oXML;
	var mimetypes="(contains(.,'text\/xsl') or contains(.,'text\/xml') or contains(.,'application\/xslt+xml'))";
    var alternate={
        yes : " and    (contains(.,\"alternate='yes'\") or contains(.,'alternate=\"yes\"'))",
        no  : " and not(contains(.,\"alternate='yes'\") or contains(.,'alternate=\"yes\"'))"
        }; // [((alt)?'yes':'no')];
    /*@if (@_jscript)
        if (sourceDoc.getProperty("SelectionLanguage")!="XPath") sourceDoc.setProperty("SelectionLanguage", "XPath");
        nodeXSLPI = sourceDoc.selectSingleNode("processing-instruction('xml-stylesheet')["+mimetypes+alternate.no+"]") ||
                sourceDoc.selectSingleNode("processing-instruction('xml-stylesheet')["+mimetypes+alternate.yes+"]");
      @else @*/
        // yet to do
        nodeXSLPI = this.setXMLPI2XSL('#test',true); // test
    /*@end @*/
    //
    // nodeXSLPI = sourceDoc.getElementsByTagName('xml-stylesheet');
    // for (var pi=0; pi<nodeXSLPI.length && !hrefXSLPI; pi++) {
    //     if ((nodeXSLPI[pi].nodeType==Node.PROCESSING_INSTRUCTION_NODE)&&((nodeXSLPI[pi].nodeValue.indexOf('text\/xsl')!=-1)||(nodeXSLPI[pi].nodeValue.indexOf('text\/xml')!=-1))) {
    //       hrefXSLPI=pi.nodeValue.match(/href=['"](.+?)['"]/i).pop(); } }
    //
    hrefXSLPI = (nodeXSLPI) ? nodeXSLPI.nodeValue.match(/href=['"](.+?)['"]/i).pop() : '' ;
    this.updateReport('[xmlpi4XSL] got '+(hrefXSLPI||'@@none@@')+' from '+((nodeXSLPI)?this.getSourceStr(nodeXSLPI):'<?null?>'));
    return hrefXSLPI;
}

XSLTransfactory.prototype.isFragmentID = function() {
    if (this.fXSL&&(this.fXSL.charAt(0)=='#'))
    return true;
    else return false;
}


XSLTransfactory.prototype.putResult2ID = function(tOut) {
    var tLoc, tDoc; 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(this.rSrc)); break;
        case 'div': /*@if (@_jscript) tLoc.innerHTML=this.rSrc; @else @*/ tLoc.appendChild(this.rDFr); /*@end @*/ break;
        case 'object' :
            // if (this.rDoc.documentElement)
            // tLoc.contentDocument.replaceChild(tLoc.contentDocument.importNode(this.rDoc.documentElement,true),tLoc.contentDocument.documentElement);
            // else
            tLoc.contentDocument.documentElement.appendChild(tLoc.contentDocument.importNode(this.rDFr,true));
        break;
        case '': break;
        default: break;
        } //End: switch
    } else {
        tLoc=window.open('',tOut);
        tDoc=tLoc.document;
        tDoc.open('text\/html');
        tDoc.write('<html xmlns=\"http:\/\/www.w3.org\/1999\/xhtml\"><head><title>XSLTransfactory \u00B7 Transform Result<\/title><\/head><body><\/body><\/html>');
        tDoc.close();
        try { while (true) {
        // -----------------------------------------------------------------
        /*@if (@_jscript)
        // -----------------------------------------------------------------
        //
        // IE: <html />, <a0:html />, <any:html /> ...
        if ((this.rDoc.doctype&&this.rDoc.doctype.baseName.toLowerCase()=='html')||(this.rDoc.documentElement&&this.rDoc.documentElement.baseName.toLowerCase()=='html'))
            {
            tDoc.open('text\/html'); tDoc.write(this.rSrc); tDoc.close();
            break;
            }
        if (this.rSrc.charAt(0)=='<')
            {
            tDoc.open('text\/xml');  tDoc.write(this.rSrc); tDoc.close();
            } else {
            tDoc.body.innerHTML='<pre>'+this.rSrc+'<\/pre>';
            }
        // -----------------------------------------------------------------
          @else @*/
        // -----------------------------------------------------------------
        //
        // Moz: <html />, <a0:html />, <any:html /> ...
        if ((this.rDoc instanceof HTMLDocument)||(this.rDoc.documentElement&&(this.rDoc.documentElement instanceof HTMLHtmlElement)))
            {
            tDoc.open('text\/html');
            // with (tDoc.documentElement) { while (hasChildNodes()) { void(removeChild(lastChild)); } };
            // tDoc.documentElement.appendChild(tDoc.importNode(this.rDFr,true));
            tDoc.replaceChild(tDoc.importNode(this.rDoc.documentElement,true),tDoc.documentElement);
            tDoc.close();
            break;
            }
        //
        // Moz: <transformiix:result xmlns:transformiix="http://www.mozilla.org/TransforMiix" />
        if (this.rDoc.documentElement&&(this.rDoc.documentElement.nodeName=='transformiix:result')) // &&(this.rDoc.documentElement.getAttribute('xmlns:transformiix')=='http:\/\/www.mozilla.org\/TransforMiix')) // &&(this.rDoc.documentElement.namespaceURI=='http:\/\/www.mozilla.org\/TransforMiix')&&this.rDoc.documentElement.hasAttributeNS('http:\/\/www.w3.org\/2000\/xmlns\/','transformiix')&&(this.rDoc.documentElement.getAttributeNS('http:\/\/www.w3.org\/2000\/xmlns\/','transformiix')=='http:\/\/www.mozilla.org\/TransforMiix'))
            {
            tDoc.body.appendChild(tDoc.createElement('pre'));
            // tDoc.body.firstChild.appendChild(tDoc.createTextNode(tDoc.importNode(this.rDFr,true)));
            tDoc.body.firstChild.appendChild(tDoc.importNode(this.rDFr,true));
            break;
            }
        //
        // Moz: any unknown xml
        if ((this.rDoc instanceof XMLDocument)&&(this.rDoc.doctype||this.rDoc.documentElement))
            {
            tDoc.open('application\/xml');
            tDoc.replaceChild(tDoc.importNode(this.rDoc.documentElement,true),tDoc.documentElement);
            tDoc.close();
            break;
            } else {
            tDoc.body.innerHTML='<pre>@@result typeof \"'+typeof(this.rDoc)+'\"\r\n'+this.rDoc+'\r\n@@<\/pre>';
            }
        // -----------------------------------------------------------------
        /*@end @*/
        // -----------------------------------------------------------------
        break; } } catch(e) { this.updateReport('[resultOut] '+(e.description||e.message)); }
        finally { tDoc.close(); }
    }
}

//XSLTransfactory.prototype.fTEMPLATE = function() {
/*@if (@_jscript) // IFIE
  @else @*/ // ELSE
/*@end @*/
//}

// -----------------------------------------------------------------
// "emulation" of an older function
// -----------------------------------------------------------------

function jsTFX(fXML, fXSL, tOut) {
    var xFac=new XSLTransfactory();
        xFac.evToDoXML=function(ev){xFac.fnLoadXSL(fXSL);};
        xFac.evToDoXSL=function(ev){xFac.fnFormXML(); xFac.putResult2ID(tOut);};
        xFac.fnLoadXML(fXML);
}

// -----------------------------------------------------------------
// EOF xslt.js
// -----------------------------------------------------------------