I found a nice generic stylesheet on the Web and adapted it a little bit for that purpose. Here the modified xsl file, the css file, a sample web.xml.
See the sample output if your browser supports XML/XSL transformation.
Attach the xsl to the xml by adding this line to the xml file :
<?xml version="1.0" encoding="UTF-8"?> <?xml-stylesheet type="text/xsl" href="tree-view.xsl"?> ...
<META http-equiv="Content-Type" content="text/html; charset=ISO8859-1">
<%@ LANGUAGE="JScript" %>
<%
Response.buffer = true;
var xmlfile;
var oXML;
var oXSL;
var oXSLTemplate;
var oXSLProcessor;
var SrcXSL;
var SrcXML;
// get the PARAM=??? (assumes you have used GET request method!)...
// assume something like http://.../docxml.asp?xmlfile=myxml.xml
xmlfile = '' + Request.QueryString('xmlfile');
// get the source file (XML and XSL) paths
SrcXML = Server.MapPath(xmlfile);
SrcXSL = Server.MapPath('xmldoc/tree-view2.xsl');
// create documents for the XML and XSL...
oXML = Server.CreateObject('Msxml2.DOMDocument');
oXSL = Server.CreateObject('Msxml2.FreeThreadedDOMDocument');
// load the XML and XSL into your documents...
// we don't want to waste time validating the file
oXSL.load(SrcXSL);
oXML.validateOnParse = false ;
oXML.async = false ;
oXML.resolveExternals = false ;
oXML.load(SrcXML);
// create the XSL template and processor...
oXSLTemplate = Server.CreateObject('Msxml2.XSLTemplate');
oXSLTemplate.stylesheet = oXSL;
oXSLProcessor = oXSLTemplate.createProcessor;
// place the ?xmlfile=xxx value into the XSL processor...
oXSLProcessor.addParameter('xmlfile',xmlfile,'');
// tell the XSL processor of the XML you want to have transformed...
oXSLProcessor.input = oXML;
try {
oXSLProcessor.transform ;
Response.write(oXSLProcessor.output);
}
catch (e) {
Response.write
('The file ' +e.url + ' is not valid. Reason: ' + e.reason );
}
%>Written and compiled by Réal Gagnon ©1998-2012
[ home ]