Solved

XML reporting

Posted on 2014-01-15
5
313 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

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

Suggested Solutions

Many times as a report developer I've been asked to display normalized data such as three rows with values Jack, Joe, and Bob as a single comma-separated string such as 'Jack, Joe, Bob', and vice versa.  Here's how to do it. 
Not sure what the best email signature size is? Are you worried about email signature image size? Follow this best practice guide.
The viewer will learn how to dynamically set the form action using jQuery.
HTML5 has deprecated a few of the older ways of showing media as well as offering up a new way to create games and animations. Audio, video, and canvas are just a few of the adjustments made between XHTML and HTML5. As we learned in our last micr…

757 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

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now