// some basic browser detection
var _XMLT_IS_IE = (navigator.userAgent.toLowerCase().indexOf("msie") > -1)?true:false;
var _XMLT_IS_MOZ = (document.implementation && document.implementation.createDocument)?true:false;
if (_XMLT_IS_IE) _XMLT_IS_MOZ = false;
var _xmlt_iNsCounter = 0;
var _XMLT_IEPREFIX4XSLPARAM = "";
if (_XMLT_IS_MOZ)
{
Xmlt.getDomDocument = function(sUri, sName)
{
var oDoc = document.implementation.createDocument(sUri, sName, null);
oDoc.addEventListener("load", _xmlt__XMLDocument_onload, false);
return oDoc;
};
Xmlt.getXmlHttpRequest = function()
{
return new XMLHttpRequest();
};
function _xmlt__XMLDocument_onload()
{
_xmlt_loadHandler(this);
};
function _xmlt_loadHandler(oDoc)
{
if (!oDoc.documentElement || oDoc.documentElement.tagName == "parsererror")
oDoc.parseError = -1;
_xmlt_setReadyState(oDoc, 4);
};
function _xmlt_setReadyState(oDoc, iReadyState)
{
if (oDoc.onreadystatechange != null && typeof oDoc.onreadystatechange == "function")
oDoc.onreadystatechange();
};
XMLDocument.prototype._xmlt_clearDOM = function()
{
while(this.hasChildNodes())
this.removeChild(this.firstChild);
}
XMLDocument.prototype._xmlt_copyDOM = function(oDoc)
{
this._xmlt_clearDOM();
if(oDoc.nodeType == Node.DOCUMENT_NODE || oDoc.nodeType == Node.DOCUMENT_FRAGMENT_NODE)
{
var oNodes = oDoc.childNodes;
for(i=0;i/g, ">");
});
HTMLElement.prototype.__defineGetter__("innerText", function ()
{
return _xmlt_normalizeText(this.innerHTML.replace(/<[^>]+>/g,""));
});
Document.prototype.onreadystatechange = null;
Document.prototype.parseError = 0;
var _XMLT_SYNC_NON_IMPLEMENTED = false;
try{
XMLDocument.prototype.async = true;
_XMLT_SYNC_NON_IMPLEMENTED = true;
}catch(e){/*trap*/}
XMLDocument.prototype._xmlt_load = XMLDocument.prototype.load;
XMLDocument.prototype.load = function(sURI)
{
var oDoc = document.implementation.createDocument("", "", null);
oDoc._xmlt_copyDOM(this);
this.parseError = 0;
_xmlt_setReadyState(this, 1);
try
{
if(this.async == false && _XMLT_SYNC_NON_IMPLEMENTED)
{
var tmp = new XMLHttpRequest();
tmp.open("GET", sURI, false);
tmp.overrideMimeType("text/xml");
tmp.send(null);
_xmlt_setReadyState(this, 2);
this._xmlt_copyDOM(tmp.responseXML);
_xmlt_setReadyState(this, 3);
}
else
this._xmlt_load(sURI);
} catch (objException){
this.parseError = -1;
}
finally {
_xmlt_loadHandler(this);
}
return oDoc;
};
Element.prototype.transformNodeToObject = function(xslDoc, oResult)
{
var oDoc = document.implementation.createDocument("", "", null);
oDoc._xmlt_copyDOM(this);
oDoc.transformNodeToObject(xslDoc, oResult);
}
Document.prototype.transformNodeToObject = function(xslDoc, oResult)
{
var xsltProcessor = null;
try
{
xsltProcessor = new XSLTProcessor();
if(xsltProcessor.reset)
{
xsltProcessor.importStylesheet(xslDoc);
var newFragment = xsltProcessor.transformToFragment(this, oResult);
oResult._xmlt_copyDOM(newFragment);
} else {
xsltProcessor.transformDocument(this, xslDoc, oResult, null);
}
} catch(e) {
if(xslDoc && oResult)
throw "Xmlt_TransformNodeToObjectException: Failed to transform document. (original exception: "+e+")";
else if(!xslDoc)
throw "Xmlt_TransformNodeToObjectException: No Stylesheet Document was provided. (original exception: "+e+")";
else if(!oResult)
throw "Xmlt_TransformNodeToObjectException: No Result Document was provided. (original exception: "+e+")";
else if(xsltProcessor == null)
throw "Xmlt_XSLTProcessorNotAvailableException: Could not instantiate an XSLTProcessor object. (original exception: "+e+")";
else
throw e;
}
};
Element.prototype.transformNode = function(xslDoc)
{
var oDoc = document.implementation.createDocument("", "", null);
oDoc._xmlt_copyDOM(this);
return oDoc.transformNode(xslDoc);
}
Document.prototype.transformNode = function(xslDoc)
{
var out = document.implementation.createDocument("", "", null);
this.transformNodeToObject(xslDoc, out);
var str = null;
try
{
var serializer = new XMLSerializer();
str = serializer.serializeToString(out);
}
catch(e)
{
throw "Xmlt_TransformNodeException: Failed to serialize result document. (original exception: "+e+")";
}
return str;
};
Array.prototype.item = function(i)
{
return this[i];
};
Array.prototype.expr = "";
XMLDocument.prototype.setProperty = function(x,y){};
XMLDocument.prototype.selectNodes = function(sExpr, contextNode)
{
var oResult = this.evaluate(sExpr,
(contextNode?contextNode:this),
this.createNSResolver(this.documentElement),
XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null);
var nodeList = new Array(oResult.snapshotLength);
nodeList.expr = sExpr;
for(i=0;i 0)
return nodeList[0];
else
return null;
};
Element.prototype.selectSingleNode = function(sExpr)
{
var doc = this.ownerDocument;
if(doc.selectSingleNode)
return doc.selectSingleNode(sExpr, this);
else
throw "XmltXPathOperationException: Method selectSingleNode is only supported by XML Nodes. (original exception: "+e+")";
};
} else if (_XMLT_IS_IE){
if(!window.Node)
{
var Node = {
ELEMENT_NODE: 1,
ATTRIBUTE_NODE: 2,
TEXT_NODE: 3,
CDATA_SECTION_NODE: 4,
ENTITY_REFERENCE_NODE: 5,
ENTITY_NODE: 6,
PROCESSING_INSTRUCTION_NODE: 7,
COMMENT_NODE: 8,
DOCUMENT_NODE: 9,
DOCUMENT_TYPE_NODE: 10,
DOCUMENT_FRAGMENT_NODE: 11,
NOTATION_NODE: 12
}
}
_XMLT_IEPREFIX4XSLPARAM = "xsl:";
var _XMLT_DOM_PROGID = "";
var _XMLT_XMLHTTP_PROGID = "";
function pickRecentProgID(idList)
{
var bFound = false;
for (var i=0; i < idList.length && !bFound; i++)
{
try
{
var oDoc = new ActiveXObject(idList[i]);
o2Store = idList[i];
bFound = true;
} catch (objException){}
}
if (!bFound)
throw "Xmlt_Exception: Could not retreive a valid progID of Class: " + idList[idList.length-1]+". (original exception: "+e+")";
idList = null;
return o2Store;
};
_XMLT_DOM_PROGID = pickRecentProgID(["Msxml2.DOMDocument.4.0", "Msxml2.DOMDocument.3.0", "MSXML2.DOMDocument", "MSXML.DOMDocument", "Microsoft.XmlDom"]);
_XMLT_XMLHTTP_PROGID = pickRecentProgID(["Msxml2.XMLHTTP.4.0", "MSXML2.XMLHTTP.3.0", "MSXML2.XMLHTTP", "Microsoft.XMLHTTP"]);
pickRecentProgID = null;
Xmlt.getDomDocument = function(sUri, sName) {
var oDoc = new ActiveXObject(_XMLT_DOM_PROGID);
if (sName){
if (sUri){
oDoc.loadXML("");
// don't use the same prefix again
++_xmlt_iNsCounter;
} else
oDoc.loadXML("<" + sName + "/>");
}
return oDoc;
};
Xmlt.getXmlHttpRequest = function()
{
return new ActiveXObject(_XMLT_XMLHTTP_PROGID);
};
}
function Xmlt(){}
Xmlt.setXslParameter = function(oXslDoc, sParamQName, sParamValue)
{
try
{
var params = oXslDoc.getElementsByTagName(_XMLT_IEPREFIX4XSLPARAM+"param");
var iLength = params.length;
var bFound = false;
var param;
if(sParamValue)
{
for(i=0; i < iLength && !bFound;i++)
{
// match a param name attribute with the name given as argument
if(params[i].getAttribute("name") == sParamQName)
{
param = params[i];
// clean up the parameter
while(param.firstChild)
param.removeChild(param.firstChild);
if(!sParamValue || sParamValue == null)
{
// do nothing; we've cleaned up the parameter anyway
}
// if String
else if(typeof sParamValue == "string")
{
param.setAttribute("select", sParamValue);
bFound = true;
}
// if node
else if(sParamValue.nodeName)
{
param.removeAttribute("select");
param.appendChild(sParamValue.cloneNode(true));
bFound = true;
}
// if NodeList
else if (sParamValue.item(0)
&& sParamValue.item(0).nodeType)
{
for(j=0;j < sParamValue.length;j++)
if(sParamValue.item(j).nodeType) // check if this is a Node
param.appendChild(sParamValue.item(j).cloneNode(true));
bFound = true;
}
// if Array or IE's IXMLDOMNodeList
else
throw "XmltTypeMissMatchException in method: Xmlt.setXslParameter. (original exception: "+e+")";
}
}
}
return bFound;
}
catch(e)
{
throw e;
return false;
}
}