Solved

XML reporting

Posted on 2014-01-15
5
324 Views
Last Modified: 2014-01-30
Hi,
Scenario.
1. I will generate/update a XML file based on an activity (sort of audit)
2. When ever I require, I would like to read this XML and generate a HTML report.
3. I have an apache server installed on one of my server, If possible I would like to use this web server to generate the report based on step 1 XML.
4. If I use XSLT, then what else I need to have on the apache server (like parser etc)
5. Wish to retreive subset of data from XML, and wish to SORT those in HTML if possible.

Please help with examples. or advise a better way. (or even any less expensive product that I can use)

Thanks in advance
0
Comment
Question by:enthuguy
  • 2
  • 2
5 Comments
 
LVL 8

Expert Comment

by:Surrano
ID: 39782109
If you use XSLT simply as a stylesheet of the XML file then the transformation takes place on the client side (i.e. in the browser). Your XML should look like this: (of course names and encoding may vary)

<?xml version="1.0" encoding="ISO-8859-1" ?>
<?xml-stylesheet type="text/xsl" href="somestylesheet.xsl" ?>

<somesingletag someattr="somevalue">
...
</somesingletag>

Open in new window


If you apply the XSLT on the XML in a dynamic way, e.g. within a PHP page, then it really depends on what exactly your runtime environment is. E.g. for Ubuntu + PHP, you need the php5-xsl package (and all its requirements of course). I'm a bit too lazy to dig up a self-contained PHP example though :)

(edit: examples)
0
 
LVL 6

Expert Comment

by:Mahesh Bhutkar
ID: 39784529
There are various libraries/open source available to transform xml using xslt on different different platform.

The simplest way where you don't even have to use any library is use Javascript to transform xml document using xslt.

Here is an example which you can refer,

http://www.w3schools.com/xsl/xsl_client.asp
http://www.w3schools.com/xsl/tryit.asp?filename=cdcatalog
0
 
LVL 8

Accepted Solution

by:
Surrano earned 500 total points
ID: 39784565
Simplest is to use the <?xml-stylesheet> tag but if you need some dynamics, e.g. URL parameters, it is an option to use javascript indeed. The essence (as we use it) is:
function getURLParam(paramname) {
  var query=this.location.search.substring(1);
  if (query.length > 0){
    var params=query.split("&");
    for (var i=0 ; i<params.length ; i++){
      var pos = params[i].indexOf("=");
      var name = params[i].substring(0, pos);
      if (name==paramname) {
	var value = params[i].substring(pos + 1);
	return value;
      }
    }
  }    
  return null;
}

function procParam(paramname) {
  var param = getURLParam(paramname);
  if (param != null)
    if (isDom)
      proc.setParameter(null, paramname, param);
    else
      proc.addParameter(paramname, param);
}
 
function init() {
  var xslFile = "collect.xsl";
  var xmlFile = "collect.xml";

  if (document.implementation && document.implementation.createDocument)
    isDom = true;
  
  if (isDom) {
    xsl = document.implementation.createDocument("", "test", null);
    xml = document.implementation.createDocument("", "test", null);
  } else {
    xslt = new ActiveXObject("Msxml2.XSLTemplate");
    xsl = new ActiveXObject("Msxml2.FreeThreadedDOMDocument");
    xml = new ActiveXObject("Msxml2.FreeThreadedDOMDocument");
  }

  xsl.async = false; xsl.load(xslFile);
  xml.async = false; xml.load(xmlFile);

  if (isDom) {
    proc = new XSLTProcessor();
    proc.importStylesheet(xsl);
  } else {
    xslt.stylesheet = xsl.documentElement;
    proc = xslt.createProcessor();
    proc.input = xml;
  }

  procParam("host");
  procParam("module");
  procParam("mode");
  procParam("list");
  procParam("graph");

  if (isDom) {
    var fragment = proc.transformToFragment(xml, document);
    document.getElementById("example").appendChild(fragment);
  } else {
    proc.transform();
    document.write(proc.output);
  }
}

Open in new window


and the xsl refers to the params (host, module, mode, list, graph) like this:

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
  <xsl:output method="html"/>
  <xsl:param name="host"/>
  <xsl:param name="module"/>
  <xsl:param name="mode"/>
  <xsl:param name="list"/>
  <xsl:param name="graph" select="no"/>
...
</xsl:stylesheet> 

Open in new window

0
 
LVL 6

Expert Comment

by:Mahesh Bhutkar
ID: 39799622
Enthuguy, Any update on this?
0
 

Author Closing Comment

by:enthuguy
ID: 39822632
.Awesome!

Thanks
0

Featured Post

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
The Best Website Creation Tools 14 55
two div layout one vertical other horizontal. 5 28
tutorial for ebay api 3 35
Scroll 5 news at a time. 4 27
Not sure what the best email signature size is? Are you worried about email signature image size? Follow this best practice guide.
Find out what you should include to make the best professional email signature for your organization.
The viewer will learn how to count occurrences of each item in an array.
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

810 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question