Solved

XML reporting

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Find out what you should include to make the best professional email signature for your organization.
Finding original email is quite difficult due to their duplicates. From this article, you will come to know why multiple duplicates of same emails appear and how to delete duplicate emails from Outlook securely and instantly while vital emails remai…
In this tutorial viewers will learn how to embed Flash content in a webpage using HTML5. Ensure your DOCTYPE declaration is set to HTML5: "<!DOCTYPE html>": Use the <object> tag to embed Flash content.: To specify that the object is Flash content, d…
Learn how to create flexible layouts using relative units in CSS.  New relative units added in CSS3 include vw(viewports width), vh(viewports height), vmin(minimum of viewports height and width), and vmax (maximum of viewports height and width).

896 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

20 Experts available now in Live!

Get 1:1 Help Now