1 / 20

Creating Reports from XML

Creating Reports from XML. CS8630 – Fall 2005 By Lori Tribble. Executive Summary. LJT Consulting manages a Source Forge project and needs the ability to create tracking reports on specific fields. Source Forge does not provide the necessary functionality to create the necessary reports.

Download Presentation

Creating Reports from XML

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Creating Reports from XML CS8630 – Fall 2005 By Lori Tribble

  2. Executive Summary LJT Consulting manages a Source Forge project and needs the ability to create tracking reports on specific fields. Source Forge does not provide the necessary functionality to create the necessary reports. Source Forge provides an XML backup ability for their tracking system and therefore, the request was made to use the XML database that is captured (manually) from the internet to create the necessary reports. The reports should allow for various query options that include the ‘resolution’ field and the option for displaying ‘details’ field. The solution needs to be something simple and easy to setup.

  3. Source Forge Tracking Example

  4. Backing up Source Forge

  5. Example XML Output <project_export> <artifacts> <artifact> <field name="artifact_id">468081</field> <field user_id="242241" name="submitted_by">mgaller</field> <field user_id="100" name="assigned_to">nobody</field> <field name="priority">5</field> <field name="status">Open</field> <field name="resolution">None</field> <field name="summary">Updated VTS.EXE (2.28 patch)</field> <field name="artifact_type">Patches</field> <field name="category">None</field> <field name="artifact_group_id">None</field> <field name="details">Sample Details.</field> </artifact> </artifacts> </project_export>

  6. Technologies Used • XML • XSL • XPath • Java Script • HTML

  7. Example Flow of Project

  8. XML Reformat Change use of attribute to be an element <field name="artifact_id">468081</field to <artifact_id>468081</artifact_id> Using the following XSL code: <xsl:template match=“field”> <xsl:variable name=“myname”><xsl:value-of select=“@name” /></xsl:variable> <xsl:element name=“{$myname}”> <xsl:variable name=“textval”><xsl:value-of select=“text()” /></xsl:variable> <xsl:if test=“$textval!=‘’”> <xsl:value-of select=“text()” /> </xsl:if> <xsl:apply-templates select=“*” /> </xsl:element> </xsl:template>

  9. Resulting XML <project_export> <artifacts> <artifact> <artifact_id>468081</artifact_id> <submitted_by>mgaller</submitted_by> <assigned_to>nobody</assigned_to> <priority>5</priority> <status>Open</status> <resolution>None</resolution> <summary>Updated VTS.EXE (2.28 patch)</summary> <artifact_type>Patches</artifact_type> <category>None</category> <artifact_group_id>None</artifact_group_id> <details>Sample Details </details> </artifact> </artifacts> </project_export>

  10. HTML Form

  11. Sample Java Script function test(form) { var select_res = form.resolution.options[form.resolution.selectedIndex].value; var select_status = form.status.options[form.status.selectedIndex].value; var select_group = form.group.options[form.group.selectedIndex].value; var select_sortby = form.sortby.options[form.sortby.selectedIndex].value; var select_details = form.details.options[form.details.selectedIndex].value; var list = "<config_params>"; list += "<resolution>"+select_res+"</resolution>"; list += "<status>"+select_status+"</status>"; list += "<group>"+select_group+"</group>"; list += "<sortby>"+select_sortby+"</sortby>"; list += "<showdetails>"+select_details+"</showdetails>"; list += "</config_params>"; WriteToFile(list); } function WriteToFile(sText) { var fso = new ActiveXObject("Scripting.FileSystemObject"); var s = fso.CreateTextFile("c:\\ksuclasses\\cs8630\\xmlproject\\wrkingproject\\config.xml", true); s.WriteLine(sText); s.Close(); }

  12. Configuration XML Created <config_params> <resolution>Fixed</resolution> <status>Open</status> <group>v3.x</group> <sortby>artifact_id</sortby> <showdetails>no</showdetails> </config_params>

  13. How to load the Config.xml in XSL <xsl:variable name="config" select="document('config.xml')"/> <xsl:variable name="config_details" select="$config/config_params/showdetails/text()"/> <xsl:variable name="config_status" select="$config/config_params/status/text()"/> <xsl:variable name="config_resolution" select="$config/config_params/resolution/text()"/> <xsl:variable name="config_group" select="$config/config_params/group/text()"/> <xsl:variable name="config_sortby" select="$config/config_params/sortby/text()"/>

  14. Sample Query Statement in XSL <xsl:for-each select="artifact[artifact_type/text()='Bugs' and (status[text()=$config_status] or $config_status='all') and ($config_resolution='all' or resolution[text()=$config_resolution]) and ($config_group='all' or artifact_group_id[text()=$config_group])]"> <xsl:sort select="*[local-name() = string($config_sortby)]/text()" data-type="number" order="descending"/> <tr> <xsl:call-template name="displayfields"> <xsl:with-param name="showdetails"><xsl:value-of select="$config_details"/></xsl:with-param> </xsl:call-template> </tr> </xsl:for-each>

  15. Totals in XSL <tr><td>Total:</td><td> <xsl:value-of select="count(artifact[artifact_type/text()='Bugs' and (status[text()=$config_status] or $config_status='all') and ($config_resolution='all' or resolution[text()=$config_resolution]) and ($config_group='all' or artifact_group_id[text()=$config_group])])"/> </td></tr>

  16. Resulting Report

  17. Main Issues Encountered • Original XML not formatted for queries. • Passing parameters into XSL from IE

  18. Resulting Steps • Step 1: Log into source forge as the project administrator • Step 2: Save the XML backup to the local disk • Step 3: Launch the HTML application written to create reports • Step 4: Load the original XML into IE using the form • Step 5: Enter the parameters for the query report and save them to disk, again using the form. • Step 6: Run the report.

  19. Conclusion The resulting project was a success and provides a simple mechanism for the project manager to create the reports needed to simplify his management duties.

  20. References • Pressman, Roger S. (2005). Software Engineering: A Practitioner’s Approach - 6th ed.. New York: McGraw Hill. • Kay, Michael. (2005) XSL Transformations (XSLT) Version 2.0. www.w3.org/TR/2005/CR-xslt20-20051103/#creating-new-nodes. • Clark, James. (1999) XSL Transformations (XSLT) Version 1.0. www.w3.org/TR/xslt. • Clark, James. (1999) XML Path Language (XPath) Version 1.0. www.w3.org/TR/xpath • Unknown. (2005) Forms and Scripts. www.htmlcodetutorial.com/forms/index_famsupp_7.html. • Premshree. (2005) XML and JavaScript. www.codeproject.com/jscript/xmljs.asp. • Schach, David; Lapp, Joe; Robie, Jonathan. Querying and Transforming XML. www.w3.org/TandS/QL/QL98/pp/query-transform.html. • XQuery 1.0: An XML Query Language. W3C Working Draft 15 September 2005. www.w3.org/TR/xquery/.

More Related