////////////  xmlUtil.js  a collection of utilities...

 var xmlDoc ; //

/*
function initAll(){
 xFile= 'cdCatalog.xml';   // change accordingly
 xsFile= 'cdCatalog.xsl';
 //info.innerHTML = 'initDone!'
}
*/


////////// LOAD XML CODE...
// from w3 schools, XML DOM Load Function
function loadXMLDoc(fname){
try //Internet Explorer
  {  xmlDoc=new ActiveXObject("Microsoft.XMLDOM"); }
catch(e)
  {
  try //Firefox, Mozilla, Opera, etc.
    {     xmlDoc=document.implementation.createDocument("","",null); }
  catch(e) {alert(e.message)}
  }
try
  {
  xmlDoc.async=false;
  xmlDoc.load(fname);
  return(xmlDoc);
  }
catch(e) {alert(e.message)}
return(null);
}

//////////////////////////////////


function appChild(elm, doc){
 res = document.getElementById(elm);
 res.innerHTML='';
 res.appendChild(doc);

}

function applyXSLFilter(dest)   // todo: change this to changeFilter (replace childElement)
{
xml=loadXMLDoc(xFile);
xsl=loadXMLDoc(xsFile);
// code for IE
if (window.ActiveXObject)
  {
  ex=xml.transformNode(xsl);
  document.getElementById("example").innerHTML=ex;
  }
// code for Mozilla, Firefox, Opera, etc.
else if (document.implementation
&& document.implementation.createDocument)
  {
  xsltProcessor=new XSLTProcessor();
  xsltProcessor.importStylesheet(xsl);
  resultDocument = xsltProcessor.transformToFragment(xml,document);
  appChild(dest, resultDocument);
  }
}

function applyXSL(dest, xDoc, xFilter)
{
xml=loadXMLDoc(xDoc);
xsl=loadXMLDoc(xFilter);
// code for IE
if (window.ActiveXObject)
  {
  ex=xml.transformNode(xsl);
  document.getElementById("example").innerHTML=ex;
  }
// code for Mozilla, Firefox, Opera, etc.
else if (document.implementation
&& document.implementation.createDocument)
  {
  xsltProcessor=new XSLTProcessor();
  xsltProcessor.importStylesheet(xsl);
  resDoc = xsltProcessor.transformToFragment(xml,document);
  appChild(dest, resDoc);
  }
}



function applyXSL2Node(dest, xNode, xFilter)
{
xsl=loadXMLDoc(xFilter);
// code for IE
if (window.ActiveXObject)
  {
  ex=xNode.transformNode(xsl);
  document.getElementById("example").innerHTML=ex;
  }
// code for Mozilla, Firefox, Opera, etc.
else if (document.implementation
&& document.implementation.createDocument)
  {
  xsltProcessor=new XSLTProcessor();
  xsltProcessor.importStylesheet(xsl);
  resDoc = xsltProcessor.transformToFragment(xNode,document);
  appChild(dest, resDoc);
  }
}
/////////////////////////////////////////////////////////////////////////////////////////////
/////////////////
//  init sequence

//window.onload=initAll;
