Solved

XML reporting

Posted on 2014-01-15
5
329 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

When it comes to write a Context Sensitive Help (an online help that is obtained from a specific point in state of software to provide help with that state) ,  first we need to make the file that contains all topics, which are given exclusive IDs. …
When crafting your “Why Us” page, there are a plethora of pitfalls to avoid. Follow these five tips, and you’ll be well on your way to creating an effective page.
The viewer will learn how to count occurrences of each item in an array.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.

717 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