hta实现的笨狼XSLT练习器

米米素材网

<HTML>
<HEAD>
<TITLE>笨狼XSLT练习器 _米米素材网</TITLE>
<style>
body 
{
    font-size:12;
    BACKGROUND: #DADADA;
    margin-left:20;
}

#blockXML
{

    font-family:Verdana;
    font-size:12px;    
    overflow:scroll;
    height:400;
    top:40;
    left:20;

}
input
{
    width:350;
}
#blockXSL
{
    POSITION: absolute;
    font-family:Verdana;
    font-size:12px;    
    overflow:scroll;
    height:400;
    top:40;    
}    
#showMe
{    
    font-family:Verdana;
    font-size:12px;    
    height:100;
    overflow:visible;
    top:300;
    left:20;
}    

</style>
</HEAD>

<BODY>
<INPUT type="file" id="fileXML" onchange = "showXML();"/>&nbsp;XML&nbsp;
<INPUT type="file" id="fileXSL" onchange = "showXSL();"/>&nbsp;XSL&nbsp;&nbsp;
<button  onclick = "parseXML();" >开始转换</button>
<button  onclick = "browse();" >预览结果</button>
<textArea id="blockXML"></textArea>
<textArea id="blockXSL"></textArea>
<textArea id="showMe" ></textArea>
<SCRIPT LANGUAGE="JavaScript"> 
window.resizeTo(window.screen.availWidth,window.screen.availHeight);
window.moveTo(0,0); 
blockXML.style.width = parseInt(window.screen.availWidth * 0.46);
blockXSL.style.width = blockXML.style.width ;

blockXSL.style.left =    parseInt(window.screen.availWidth * 0.46) + 30;

showMe.style.width = parseInt(window.screen.availWidth * 0.92)+ 10;

   var fso 
   fso = new ActiveXObject("Scripting.FileSystemObject");



var xmldoc, xsldoc;
xmldoc = new ActiveXObject("MSXML2.DOMDocument");
xsldoc = new ActiveXObject("MSXML2.DOMDocument");
xmldoc.async = false;
xsldoc.async = false;

 function browse()
 {
    var win=window.open();
    win.document.write(showMe.value); 
 }

function showXML()
{//在文本框内加载XML
    if(Validator(fileXML.value,"XML"))
    {        
        if(fso.FileExists(fileXML.value))
        {
            var f = fso.GetFile(fileXML.value);
            var ts = f.OpenAsTextStream(1, -2);
            var s="";
            if(!ts.AtEndOfStream)
            {
                s = ts.ReadAll();
            }
            ts.Close();            
            blockXML.value = s;
            fileXML.value ="";            
        }
    }
    else
    {
        alert("XML格式错误!");
    }
}

function showXSL()
{//在文本框内加载XSL
    if(Validator(fileXSL.value,"XSL") || Validator(fileXSL.value,"XSLT"))
    {
        if(fso.FileExists(fileXSL.value))
        {
            var f = fso.GetFile(fileXSL.value);
            var ts = f.OpenAsTextStream(1, -2);
            var s="";
            if(!ts.AtEndOfStream)
            {
                s = ts.ReadAll();
            }
            ts.Close();
            blockXSL.value = s;    
            fileXSL.value ="";
        }
    }
        else
    {
        alert("XSL/XSLT格式错误!");
    }
}

function Validator(inStr,outStr)
{//检查文件格式
    var last=inStr.match(/^(.*)(\.)(.{1,8})$/)[3];           
    last=last.toUpperCase();
    if(last==outStr)
    {    
        return true;
    }
    else
    {        
        return false;
        }

}    



function parseXML()
{//解析
    if(!blockXML.value ||!blockXSL.value)
    {
    return
    }    

        if(!xmldoc.loadXML(blockXML.value))
        {
            alert("XML未加载成功!")
        }

        if(!xsldoc.loadXML(blockXSL.value))
        {
            alert("XSL未加载成功!")
        }

    var s = xmldoc.transformNode(xsldoc);
    showMe.value = s;

}



</SCRIPT>
</BODY>
</HTML>
笨狼XSLT练习器.hta