Saturday, April 5, 2014

Extracting Data from XML files using XSL and XPath...8

Comments in HTML file

Sometimes we might need to have comments in HTML file that we generate from the XML file. This could be needed if we require opening the HTML file and edit it. Comments can then help us understand the contents of the HTML file. But we cannot add comments using <!—and --> since that allows the XML Starlet interpreter to skip anything within that. XSL has a comment tag for that. Hence, if we need to add a comment in the file that is generated, we can use the construct:
<xsl:comment> --------------------------- </xsl:comment>
An example is given below:
In the above code snippet, we are doing something to get data for entity ‘DC10’. This is being put in some table column (indicated by <td> tag). Note the comment at the top. The output HTML will look something like this:

The ‘./DC10’ in the XSL code generated value as 536 in HTML.

Important points to remember

1. The understanding of XML structure is very important; unless you understand it well don’t start coding. Draw a hierarchy diagram of XML tags to understand the XML structure. The best way to know the XML structure is to go through the file manually in Notepad++. Besides this, there is a command that can be used:

xml el table.xml

The above command when run through in the XML starlet folder on the command prompt, will give the structure of table.xml file. The output can look somewhat like below:

I have marked the structure of one the files on which I ran the command. The ‘el’ command is XML Starlet command (just as ‘tr’ is).
2. If one understands the XML structure, data can be handled and extracted from almost any XML.
3. Basic DOS commands must be understood by the developer. It will be better if you can prepare a batch file within the XML Starlet folder. Batch file can contain code something like this:

del Transition_Flag_DC23_TPData.csv
xml tr ALL_Test_CasesDC2-3Transition.xsl  test.xml >> Transition_Flag_DC23_TPData.csv

This code deletes the old csv file. After that it runs the xml transform command on the ‘test.xml’ using the ‘ALL_Test_CasesDC2-3Transition.xsl’file producing the output in new ‘Transition_Flag_DC23_TPData.csv’ file.
4. It will also be better if the XSLT code and XML code be present in the XML Starlet folder. In that case the running of the batch file will be easy and it will operate in that folder, producing the desired output file.
5. Sometimes the XML Starlet refuses to parse the XML file stating that it contains and error. In that case you will have to edit the XML file in Notepad++, such that any tags causing the problem are either deleted or edited. In case of XML starlet erred out because of XSLT, code editing is required.

Advantages and Disadvantages of XML and XSLT
Advantages
1. XSLT applies user defined transformations to an XML document and the output can be HTML, XML, or any other structured document. So it is easy to merge XML data into presentation.
2. XPath is used by XSLT to locate elements/attribute within an XML document. So it is more convenient way to traverse an XML document rather than a traditional way, by using scripting language.
3. By separating data (XML document) from the presentation (XSLT), it is very easy to change the output format in any time easily without touching the code-behind.
4. The output is generated at a fast pace.
5. XML is platform independent.

Disadvantages
1. It is difficult to implement complicate business rules in XSLT.
2. Changing variable value in looping is difficult in XSLT.
3. Development and maintenance of code in XSLT is difficult as it is different from traditional programming languages such as C, C++ and Java.
4. Using XSLT have performance penalty in some cases as its engine (e.g. XML starlet) doesn’t optimize code by using caching technique like traditional compiler.
5. When processing XML files, XSLT must load the entire document into memory. With Xalan, this consumes roughly 10x the size of the input file (saxon has an alternative DOM implementation that uses less memory). If any of your input datasets grow beyond a couple of hundred megabytes, your XSLT processor might just flake out. This has been taken care of in the XSLT 3.0.

Important resources/links

1. http://www.xsltfunctions.com/xsl/
2. http://stackoverflow.com/ is a website where users can ask questions related to XSLT.
3. http://www.w3schools.com/xsl/
4. XSLT Cookbook is a good book to refer for XSLT coding.

Extracting Data from XML files using XSL and XPath...7

XML to HTML

An XML file normally contains data that we cannot use directly. In the previous examples I mentioned the conversion of XML to csv file. We can also convert the XML file to HTML file using HTML tags. Such a file can be directly opened in a browser.

Problem:

We have an XML file had the structure as defined in point – “Conditions for the output csv file – ‘xsl:for-each’ tag”.
The below output was desired:

Earlier what we used to do was - get data in a csv file (as described earlier), carry out certain Microsoft Excel operations on the data and produce the above. Then take a screenshot and save it in SharePoint, from where the file was viewed.
But, there is a way we can get this output, using only the XML file and XML Starlet. Of course, one has to write XSL code to convert data from XML file to convert it into HTML format.
Solution:
To tackle the problem, I had to create two intermediate XML files. First one contained only the data that we needed. As we can see, the output contains various test case execution status counts for various DCs. The DCs’ value came from the datasource_description. Counts of statuses can be taken by using ‘count’ function. Of course there were other conditions, e.g. , for Service Pack 1. The first code file can be seen below (it will be good if you can copy the below file in a XML editor for a better view)

<?xml version="1.0" encoding="UTF-8"?>
-<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0"> <xsl:output indent="yes" method="xml"/> -<xsl:template match="/"> -<AllDCs><xsl:text> </xsl:text> -<xsl:for-each select=".//View/results/datasource"> -<DCDetails> <xsl:text> </xsl:text> -<DC> -<xsl:if test="datasource_description = 'Testlink CROM'"> <xsl:value-of select="'DC 1'"/> </xsl:if> -<xsl:if test="datasource_description = 'Testlink common_services'"> <xsl:value-of select="'DC 5'"/> </xsl:if> -<xsl:if test="datasource_description = 'Testlink bpd'"> <xsl:value-of select="'DC 8'"/> </xsl:if> -<xsl:if test="datasource_description = 'Testlink spark'"> <xsl:value-of select="'DC 9'"/> </xsl:if> -<xsl:if test="datasource_description = 'Testlink uc'"> <xsl:value-of select="'CCN'"/> </xsl:if> -<xsl:if test="datasource_description = 'Testlink epma'"> <xsl:value-of select="'EPMA'"/> </xsl:if> -<xsl:if test="datasource_description = 'Testlink life'"> <xsl:value-of select="'DC 2-3'"/> </xsl:if> -<xsl:if test="datasource_description = 'Testlink Internet'"> <xsl:value-of select="'DC 10'"/> </xsl:if> -<xsl:if test="datasource_description = 'Testlink ecc'"> <xsl:value-of select="'DC 7'"/> </xsl:if> -<xsl:if test="datasource_description = 'Testlink Customer_Experience_Management'"> <xsl:value-of select="'CEI'"/> </xsl:if></DC> <xsl:text> </xsl:text> -<TTLTCs> -<xsl:choose> -<xsl:when test="datasource_description = 'Testlink CROM'"> <xsl:value-of select="count(./repository/testplan[testplan_active='1' and testplan_custom[(testplan_custom_name='tp_test_type' and (testplan_custom_value='DC System' or testplan_custom_value='Non-functional Test' or testplan_custom_value='User Acceptance Test'))] and testplan_custom[(testplan_custom_name='tp_sub_phase' and (testplan_custom_value='LUSV' or testplan_custom_value='Purchase' or testplan_custom_value='Quote' or testplan_custom_value='Application' or testplan_custom_value='App' or testplan_custom_value='Other ICP'))] and testplan_custom[(testplan_custom_name='tp_phase' and (testplan_custom_value='ICP_Ph0.001.001.000_ServicePack'))]]//testcase_id)"/> </xsl:when> -<xsl:otherwise> <xsl:value-of select="count(./repository/testplan[testplan_active='1' and testplan_custom[(testplan_custom_name='tp_phase' and (testplan_custom_value='ICP_Ph0.001.001.000_ServicePack'))] and testplan_custom[(testplan_custom_name='tp_test_type' and (testplan_custom_value='DC System' or testplan_custom_value='Non-functional Test' or testplan_custom_value='User Acceptance Test'))]]//testcase_id)"/> </xsl:otherwise> </xsl:choose> </TTLTCs> <xsl:text> </xsl:text> -<TTLBTCs> -<xsl:choose> -<xsl:when test="datasource_description = 'Testlink CROM'"> <xsl:value-of select="count(./repository/testplan[testplan_active='1' and testplan_custom[(testplan_custom_name='tp_test_type' and (testplan_custom_value='DC System' or testplan_custom_value='Non-functional Test' or testplan_custom_value='User Acceptance Test'))] and testplan_custom[(testplan_custom_name='tp_sub_phase' and (testplan_custom_value='LUSV' or testplan_custom_value='Purchase' or testplan_custom_value='Quote' or testplan_custom_value='Application' or testplan_custom_value='App' or testplan_custom_value='Other ICP'))] and testplan_custom[(testplan_custom_name='tp_phase' and (testplan_custom_value='ICP_Ph0.001.001.000_ServicePack'))]]//tcexecution_status[.='b'])"/> </xsl:when> -<xsl:otherwise> <xsl:value-of select="count(./repository/testplan[testplan_active='1' and testplan_custom[(testplan_custom_name='tp_phase' and (testplan_custom_value='ICP_Ph0.001.001.000_ServicePack'))] and testplan_custom[(testplan_custom_name='tp_test_type' and (testplan_custom_value='DC System' or testplan_custom_value='Non-functional Test' or testplan_custom_value='User Acceptance Test'))]]//tcexecution_status[.='b'])"/> </xsl:otherwise> </xsl:choose> </TTLBTCs> <xsl:text> </xsl:text> -<TTLPTCs> -<xsl:choose> -<xsl:when test="datasource_description = 'Testlink CROM'"> <xsl:value-of select="count(./repository/testplan[testplan_active='1' and testplan_custom[(testplan_custom_name='tp_test_type' and (testplan_custom_value='DC System' or testplan_custom_value='Non-functional Test' or testplan_custom_value='User Acceptance Test'))] and testplan_custom[(testplan_custom_name='tp_sub_phase' and (testplan_custom_value='LUSV' or testplan_custom_value='Purchase' or testplan_custom_value='Quote' or testplan_custom_value='Application' or testplan_custom_value='App' or testplan_custom_value='Other ICP'))] and testplan_custom[(testplan_custom_name='tp_phase' and (testplan_custom_value='ICP_Ph0.001.001.000_ServicePack'))]]//tcexecution_status[.='p'])"/> </xsl:when> -<xsl:otherwise> <xsl:value-of select="count(./repository/testplan[testplan_active='1' and testplan_custom[(testplan_custom_name='tp_phase' and (testplan_custom_value='ICP_Ph0.001.001.000_ServicePack'))] and testplan_custom[(testplan_custom_name='tp_test_type' and (testplan_custom_value='DC System' or testplan_custom_value='Non-functional Test' or testplan_custom_value='User Acceptance Test'))]]//tcexecution_status[.='p'])"/> </xsl:otherwise> </xsl:choose> </TTLPTCs> <xsl:text> </xsl:text> -<TTLFTCs> -<xsl:choose> -<xsl:when test="datasource_description = 'Testlink CROM'"> <xsl:value-of select="count(./repository/testplan[testplan_active='1' and testplan_custom[(testplan_custom_name='tp_test_type' and (testplan_custom_value='DC System' or testplan_custom_value='Non-functional Test' or testplan_custom_value='User Acceptance Test'))] and testplan_custom[(testplan_custom_name='tp_sub_phase' and (testplan_custom_value='LUSV' or testplan_custom_value='Purchase' or testplan_custom_value='Quote' or testplan_custom_value='Application' or testplan_custom_value='App' or testplan_custom_value='Other ICP'))] and testplan_custom[(testplan_custom_name='tp_phase' and (testplan_custom_value='ICP_Ph0.001.001.000_ServicePack'))]]//tcexecution_status[.='f'])"/> </xsl:when> -<xsl:otherwise> <xsl:value-of select="count(./repository/testplan[testplan_active='1' and testplan_custom[(testplan_custom_name='tp_phase' and (testplan_custom_value='ICP_Ph0.001.001.000_ServicePack'))] and testplan_custom[(testplan_custom_name='tp_test_type' and (testplan_custom_value='DC System' or testplan_custom_value='Non-functional Test' or testplan_custom_value='User Acceptance Test'))]]//tcexecution_status[.='f'])"/> </xsl:otherwise> </xsl:choose> </TTLFTCs> <xsl:text> </xsl:text> </DCDetails> <xsl:text> </xsl:text> </xsl:for-each> </AllDCs> </xsl:template>
 <!--<xsl:template match="@*|node()"> <xsl:copy> <xsl:apply-templates select="@*|node()"/> </xsl:copy> </xsl:template> <xsl:template match="//repository"/> <xsl:template match="*/text()[normalize-space()]"> <xsl:value-of select="normalize-space()"/> </xsl:template> <xsl:template match="*/text()[not(normalize-space())]" />-->
 </xsl:stylesheet>

Notice in this file the output method:
<xsl:output method="xml" indent="yes"/>
Because we are creating an intermediate XML file only containing the data that we require.
The output XML file is attached below:

<AllDCs>
<DCDetails>
<DC>DC 8</DC>
<TTLTCs>34</TTLTCs>
<TTLBTCs>0</TTLBTCs>
<TTLPTCs>33</TTLPTCs>
<TTLFTCs>1</TTLFTCs>
</DCDetails>
<DCDetails>
<DC>DC 1</DC>
<TTLTCs>11</TTLTCs>
<TTLBTCs>0</TTLBTCs>
<TTLPTCs>11</TTLPTCs>
<TTLFTCs>0</TTLFTCs>
</DCDetails>
<DCDetails>
<DC/>
<TTLTCs>0</TTLTCs>
<TTLBTCs>0</TTLBTCs>
<TTLPTCs>0</TTLPTCs>
<TTLFTCs>0</TTLFTCs>
</DCDetails>
<DCDetails>
<DC>DC 5</DC>
<TTLTCs>39</TTLTCs>
<TTLBTCs>0</TTLBTCs>
<TTLPTCs>39</TTLPTCs>
<TTLFTCs>0</TTLFTCs>
</DCDetails>
<DCDetails>
<DC/>
<TTLTCs>0</TTLTCs>
<TTLBTCs>0</TTLBTCs>
<TTLPTCs>0</TTLPTCs>
<TTLFTCs>0</TTLFTCs>
</DCDetails>
<DCDetails>
<DC/>
<TTLTCs>0</TTLTCs>
<TTLBTCs>0</TTLBTCs>
<TTLPTCs>0</TTLPTCs>
<TTLFTCs>0</TTLFTCs>
</DCDetails>
<DCDetails>
<DC/>
<TTLTCs>0</TTLTCs>
<TTLBTCs>0</TTLBTCs>
<TTLPTCs>0</TTLPTCs>
<TTLFTCs>0</TTLFTCs>
</DCDetails>
<DCDetails>
<DC>DC 9</DC>
<TTLTCs>0</TTLTCs>
<TTLBTCs>0</TTLBTCs>
<TTLPTCs>0</TTLPTCs>
<TTLFTCs>0</TTLFTCs>
</DCDetails>
<DCDetails>
<DC>CCN</DC>
<TTLTCs>11</TTLTCs>
<TTLBTCs>0</TTLBTCs>
<TTLPTCs>11</TTLPTCs>
<TTLFTCs>0</TTLFTCs>
</DCDetails>
<DCDetails>
<DC>DC 10</DC>
<TTLTCs>1388</TTLTCs>
<TTLBTCs>0</TTLBTCs>
<TTLPTCs>1371</TTLPTCs>
<TTLFTCs>0</TTLFTCs>
</DCDetails>
<DCDetails>
<DC/>
<TTLTCs>0</TTLTCs>
<TTLBTCs>0</TTLBTCs>
<TTLPTCs>0</TTLPTCs>
<TTLFTCs>0</TTLFTCs>
</DCDetails>
<DCDetails>
<DC/>
<TTLTCs>0</TTLTCs>
<TTLBTCs>0</TTLBTCs>
<TTLPTCs>0</TTLPTCs>
<TTLFTCs>0</TTLFTCs>
</DCDetails>
<DCDetails>
<DC>DC 2-3</DC>
<TTLTCs>2472</TTLTCs>
<TTLBTCs>27</TTLBTCs>
<TTLPTCs>2336</TTLPTCs>
<TTLFTCs>71</TTLFTCs>
</DCDetails>
<DCDetails>
<DC>DC 7</DC>
<TTLTCs>29</TTLTCs>
<TTLBTCs>0</TTLBTCs>
<TTLPTCs>27</TTLPTCs>
<TTLFTCs>0</TTLFTCs>
</DCDetails>
<DCDetails>
<DC/>
<TTLTCs>0</TTLTCs>
<TTLBTCs>0</TTLBTCs>
<TTLPTCs>0</TTLPTCs>
<TTLFTCs>0</TTLFTCs>
</DCDetails>
<DCDetails>
<DC>EPMA</DC>
<TTLTCs>80</TTLTCs>
<TTLBTCs>0</TTLBTCs>
<TTLPTCs>80</TTLPTCs>
<TTLFTCs>0</TTLFTCs>
</DCDetails>

Notice that the data that present in this file is DC wise. ‘DC8’ is the first DC in the original XML file; hence its record is the first record in the above XML file, followed by ‘DC1’. The final output is NOT DC wise; it is the Test Execution Status wise (top to bottom). Hence, we needed data in some new format so that the ‘statuses’ come down vertically and ‘DCs’ can go horizontally.  A fresh code was required that can arrange the data in new XML file where records were ‘status’ wise. See it here ( (it will be good if you can copy the below file in a XML editor for a better view)):

<?xml version="1.0" encoding="UTF-8"?>
-<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0"> <xsl:output indent="yes" method="xml"/> -<xsl:template match="/"> -<records> <script type="text/javascript">(((getDate() + 44)*100*59.52)/4167);</script> <xsl:text> </xsl:text> -<record> <value>TTLTCs</value> <xsl:text> </xsl:text> -<xsl:for-each select=".//DCDetails"> -<xsl:if test="DC='DC 1'"> -<DC1><xsl:value-of select="./TTLTCs"/></DC1> </xsl:if> -<xsl:if test="DC='DC 2-3'"> -<DC2-3><xsl:value-of select="./TTLTCs"/></DC2-3> </xsl:if> -<xsl:if test="DC='DC 5'"> -<DC5><xsl:value-of select="./TTLTCs"/></DC5> </xsl:if> -<xsl:if test="DC='DC 7'"> -<DC7><xsl:value-of select="./TTLTCs"/></DC7> </xsl:if> -<xsl:if test="DC='DC 8'"> -<DC8><xsl:value-of select="./TTLTCs"/></DC8> </xsl:if> -<xsl:if test="DC='DC 10'"> -<DC10><xsl:value-of select="./TTLTCs"/></DC10> </xsl:if> -<xsl:if test="DC='CCN'"> -<CCN><xsl:value-of select="./TTLTCs"/></CCN> </xsl:if> -<xsl:if test="DC='CEI'"> -<CEI><xsl:value-of select="./TTLTCs"/></CEI> </xsl:if> -<xsl:if test="DC='EPMA'"> -<EPMA><xsl:value-of select="./TTLTCs"/></EPMA> </xsl:if> <xsl:text> </xsl:text> -<OverallTTL><xsl:value-of select="sum(../DCDetails/TTLTCs)"/></OverallTTL> <xsl:text> </xsl:text> </xsl:for-each> </record> <xsl:text> </xsl:text> -<record> <value>TTLNRTCs</value> <xsl:text> </xsl:text> -<xsl:for-each select=".//DCDetails"> -<xsl:if test="DC='DC 1'"> -<DC1><xsl:value-of select="./TTLTCs - (./TTLPTCs + ./TTLFTCs + ./TTLBTCs)"/></DC1> </xsl:if> -<xsl:if test="DC='DC 2-3'"> -<DC2-3><xsl:value-of select="./TTLTCs - (./TTLPTCs + ./TTLFTCs + ./TTLBTCs)"/></DC2-3> </xsl:if> -<xsl:if test="DC='DC 5'"> -<DC5><xsl:value-of select="./TTLTCs - (./TTLPTCs + ./TTLFTCs + ./TTLBTCs)"/></DC5> </xsl:if> -<xsl:if test="DC='DC 7'"> -<DC7><xsl:value-of select="./TTLTCs - (./TTLPTCs + ./TTLFTCs + ./TTLBTCs)"/></DC7> </xsl:if> -<xsl:if test="DC='DC 8'"> -<DC8><xsl:value-of select="./TTLTCs - (./TTLPTCs + ./TTLFTCs + ./TTLBTCs)"/></DC8> </xsl:if> -<xsl:if test="DC='DC 10'"> -<DC10><xsl:value-of select="./TTLTCs - (./TTLPTCs + ./TTLFTCs + ./TTLBTCs)"/></DC10> </xsl:if> -<xsl:if test="DC='CCN'"> -<CCN><xsl:value-of select="./TTLTCs - (./TTLPTCs + ./TTLFTCs + ./TTLBTCs)"/></CCN> </xsl:if> -<xsl:if test="DC='CEI'"> -<CEI><xsl:value-of select="./TTLTCs - (./TTLPTCs + ./TTLFTCs + ./TTLBTCs)"/></CEI> </xsl:if> -<xsl:if test="DC='EPMA'"> -<EPMA><xsl:value-of select="./TTLTCs - (./TTLPTCs + ./TTLFTCs + ./TTLBTCs)"/></EPMA> </xsl:if> <xsl:text> </xsl:text> -<OverallTTL><xsl:value-of select="sum(../DCDetails/TTLTCs) - (sum(../DCDetails/TTLPTCs) + sum(../DCDetails/TTLFTCs) + sum(../DCDetails/TTLBTCs))"/></OverallTTL> <xsl:text> </xsl:text> </xsl:for-each> </record> <xsl:text> </xsl:text> -<record> <value>TTLBTCs</value> <xsl:text> </xsl:text> -<xsl:for-each select=".//DCDetails"> -<xsl:if test="DC='DC 1'"> -<DC1><xsl:value-of select="./TTLBTCs"/></DC1> </xsl:if> -<xsl:if test="DC='DC 2-3'"> -<DC2-3><xsl:value-of select="./TTLBTCs"/></DC2-3> </xsl:if> -<xsl:if test="DC='DC 5'"> -<DC5><xsl:value-of select="./TTLBTCs"/></DC5> </xsl:if> -<xsl:if test="DC='DC 7'"> -<DC7><xsl:value-of select="./TTLBTCs"/></DC7> </xsl:if> -<xsl:if test="DC='DC 8'"> -<DC8><xsl:value-of select="./TTLBTCs"/></DC8> </xsl:if> -<xsl:if test="DC='DC 10'"> -<DC10><xsl:value-of select="./TTLBTCs"/></DC10> </xsl:if> -<xsl:if test="DC='CCN'"> -<CCN><xsl:value-of select="./TTLBTCs"/></CCN> </xsl:if> -<xsl:if test="DC='CEI'"> -<CEI><xsl:value-of select="./TTLBTCs"/></CEI> </xsl:if> -<xsl:if test="DC='EPMA'"> -<EPMA><xsl:value-of select="./TTLBTCs"/></EPMA> </xsl:if> <xsl:text> </xsl:text> -<OverallTTL><xsl:value-of select="sum(../DCDetails/TTLBTCs)"/></OverallTTL> <xsl:text> </xsl:text> </xsl:for-each> </record> <xsl:text> </xsl:text> -<record> <value>TTLFTCs</value> <xsl:text> </xsl:text> -<xsl:for-each select=".//DCDetails"> -<xsl:if test="DC='DC 1'"> -<DC1><xsl:value-of select="./TTLFTCs"/></DC1> </xsl:if> -<xsl:if test="DC='DC 2-3'"> -<DC2-3><xsl:value-of select="./TTLFTCs"/></DC2-3> </xsl:if> -<xsl:if test="DC='DC 5'"> -<DC5><xsl:value-of select="./TTLFTCs"/></DC5> </xsl:if> -<xsl:if test="DC='DC 7'"> -<DC7><xsl:value-of select="./TTLFTCs"/></DC7> </xsl:if> -<xsl:if test="DC='DC 8'"> -<DC8><xsl:value-of select="./TTLFTCs"/></DC8> </xsl:if> -<xsl:if test="DC='DC 10'"> -<DC10><xsl:value-of select="./TTLFTCs"/></DC10> </xsl:if> -<xsl:if test="DC='CCN'"> -<CCN><xsl:value-of select="./TTLFTCs"/></CCN> </xsl:if> -<xsl:if test="DC='CEI'"> -<CEI><xsl:value-of select="./TTLFTCs"/></CEI> </xsl:if> -<xsl:if test="DC='EPMA'"> -<EPMA><xsl:value-of select="./TTLFTCs"/></EPMA> </xsl:if> <xsl:text> </xsl:text> -<OverallTTL><xsl:value-of select="sum(../DCDetails/TTLFTCs)"/></OverallTTL> <xsl:text> </xsl:text> </xsl:for-each> </record> <xsl:text> </xsl:text> -<record> <value>TTLPTCs</value> <xsl:text> </xsl:text> -<xsl:for-each select=".//DCDetails"> -<xsl:if test="DC='DC 1'"> -<DC1><xsl:value-of select="./TTLPTCs"/></DC1> </xsl:if> -<xsl:if test="DC='DC 2-3'"> -<DC2-3><xsl:value-of select="./TTLPTCs"/></DC2-3> </xsl:if> -<xsl:if test="DC='DC 5'"> -<DC5><xsl:value-of select="./TTLPTCs"/></DC5> </xsl:if> -<xsl:if test="DC='DC 7'"> -<DC7><xsl:value-of select="./TTLPTCs"/></DC7> </xsl:if> -<xsl:if test="DC='DC 8'"> -<DC8><xsl:value-of select="./TTLPTCs"/></DC8> </xsl:if> -<xsl:if test="DC='DC 10'"> -<DC10><xsl:value-of select="./TTLPTCs"/></DC10> </xsl:if> -<xsl:if test="DC='CCN'"> -<CCN><xsl:value-of select="./TTLPTCs"/></CCN> </xsl:if> -<xsl:if test="DC='CEI'"> -<CEI><xsl:value-of select="./TTLPTCs"/></CEI> </xsl:if> -<xsl:if test="DC='EPMA'"> -<EPMA><xsl:value-of select="./TTLPTCs"/></EPMA> </xsl:if> <xsl:text> </xsl:text> -<OverallTTL><xsl:value-of select="sum(../DCDetails/TTLPTCs)"/></OverallTTL> <xsl:text> </xsl:text> </xsl:for-each> </record> <xsl:text> </xsl:text> -<record> <value>TTLPRTCs</value> <xsl:text> </xsl:text> -<xsl:for-each select=".//DCDetails"> -<xsl:if test="DC='DC 1'"> -<DC1><xsl:value-of select="format-number((./TTLPTCs div (./TTLPTCs + ./TTLFTCs + ./TTLBTCs)), '###.#%')"/></DC1> </xsl:if> -<xsl:if test="DC='DC 2-3'"> -<DC2-3><xsl:value-of select="format-number((./TTLPTCs div (./TTLPTCs + ./TTLFTCs + ./TTLBTCs)), '###.#%')"/></DC2-3> </xsl:if> -<xsl:if test="DC='DC 5'"> -<DC5><xsl:value-of select="format-number((./TTLPTCs div (./TTLPTCs + ./TTLFTCs + ./TTLBTCs)), '###.#%')"/></DC5> </xsl:if> -<xsl:if test="DC='DC 7'"> -<DC7><xsl:value-of select="format-number((./TTLPTCs div (./TTLPTCs + ./TTLFTCs + ./TTLBTCs)), '###.#%')"/></DC7> </xsl:if> -<xsl:if test="DC='DC 8'"> -<DC8><xsl:value-of select="format-number((./TTLPTCs div (./TTLPTCs + ./TTLFTCs + ./TTLBTCs)), '###.#%')"/></DC8> </xsl:if> -<xsl:if test="DC='DC 10'"> -<DC10><xsl:value-of select="format-number((./TTLPTCs div (./TTLPTCs + ./TTLFTCs + ./TTLBTCs)), '###.#%')"/></DC10> </xsl:if> -<xsl:if test="DC='CCN'"> -<CCN><xsl:value-of select="format-number((./TTLPTCs div (./TTLPTCs + ./TTLFTCs + ./TTLBTCs)), '###.#%')"/></CCN> </xsl:if> -<xsl:if test="DC='CEI'"> -<CEI><xsl:value-of select="format-number((./TTLPTCs div (./TTLPTCs + ./TTLFTCs + ./TTLBTCs)), '###.#%')"/></CEI> </xsl:if> -<xsl:if test="DC='EPMA'"> -<EPMA><xsl:value-of select="format-number((./TTLPTCs div (./TTLPTCs + ./TTLFTCs + ./TTLBTCs)), '###.#%')"/></EPMA> </xsl:if> <xsl:text> </xsl:text> -<OverallTTL><xsl:value-of select="format-number((sum(../DCDetails/TTLPTCs) div (sum(../DCDetails/TTLPTCs) + sum(../DCDetails/TTLFTCs) + sum(../DCDetails/TTLBTCs))), '###.#%')"/></OverallTTL> <xsl:text> </xsl:text> </xsl:for-each> </record> <xsl:text> </xsl:text> -<record> <value>TTLPlan</value> <xsl:text> </xsl:text> -<xsl:for-each select=".//DCDetails"> -<xsl:if test="DC='DC 1'"> -<DC1><xsl:value-of select="'--'"/></DC1> </xsl:if> -<xsl:if test="DC='DC 2-3'"> -<DC2-3><xsl:value-of select="'--'"/></DC2-3> </xsl:if> -<xsl:if test="DC='DC 5'"> -<DC5><xsl:value-of select="'--'"/></DC5> </xsl:if> -<xsl:if test="DC='DC 7'"> -<DC7><xsl:value-of select="'--'"/></DC7> </xsl:if> -<xsl:if test="DC='DC 8'"> -<DC8><xsl:value-of select="'--'"/></DC8> </xsl:if> -<xsl:if test="DC='DC 10'"> -<DC10><xsl:value-of select="'--'"/></DC10> </xsl:if> -<xsl:if test="DC='CCN'"> -<CCN><xsl:value-of select="'--'"/></CCN> </xsl:if> -<xsl:if test="DC='CEI'"> -<CEI><xsl:value-of select="'--'"/></CEI> </xsl:if> -<xsl:if test="DC='EPMA'"> -<EPMA><xsl:value-of select="'--'"/></EPMA> </xsl:if> <xsl:text> </xsl:text> <OverallTTL> </OverallTTL> <xsl:text> </xsl:text> </xsl:for-each> </record> <xsl:text> </xsl:text> -<record> <value>TTLOETCs</value> <xsl:text> </xsl:text> -<xsl:for-each select=".//DCDetails"> -<xsl:if test="DC='DC 1'"> -<DC1><xsl:value-of select="format-number(((./TTLPTCs + ./TTLFTCs) div ./TTLTCs), '###.#%')"/></DC1> </xsl:if> -<xsl:if test="DC='DC 2-3'"> -<DC2-3><xsl:value-of select="format-number(((./TTLPTCs + ./TTLFTCs) div ./TTLTCs), '###.#%')"/></DC2-3> </xsl:if> -<xsl:if test="DC='DC 5'"> -<DC5><xsl:value-of select="format-number(((./TTLPTCs + ./TTLFTCs) div ./TTLTCs), '###.#%')"/></DC5> </xsl:if> -<xsl:if test="DC='DC 7'"> -<DC7><xsl:value-of select="format-number(((./TTLPTCs + ./TTLFTCs) div ./TTLTCs), '###.#%')"/></DC7> </xsl:if> -<xsl:if test="DC='DC 8'"> -<DC8><xsl:value-of select="format-number(((./TTLPTCs + ./TTLFTCs) div ./TTLTCs), '###.#%')"/></DC8> </xsl:if> -<xsl:if test="DC='DC 10'"> -<DC10><xsl:value-of select="format-number(((./TTLPTCs + ./TTLFTCs) div ./TTLTCs), '###.#%')"/></DC10> </xsl:if> -<xsl:if test="DC='CCN'"> -<CCN><xsl:value-of select="format-number(((./TTLPTCs + ./TTLFTCs) div ./TTLTCs), '###.#%')"/></CCN> </xsl:if> -<xsl:if test="DC='CEI'"> -<CEI><xsl:value-of select="format-number(((./TTLPTCs + ./TTLFTCs) div ./TTLTCs), '###.#%')"/></CEI> </xsl:if> -<xsl:if test="DC='EPMA'"> -<EPMA><xsl:value-of select="format-number(((./TTLPTCs + ./TTLFTCs) div ./TTLTCs), '###.#%')"/></EPMA> </xsl:if> <xsl:text> </xsl:text> -<OverallTTL><xsl:value-of select="format-number(((sum(../DCDetails/TTLPTCs) + sum(../DCDetails/TTLFTCs)) div sum(../DCDetails/TTLTCs)), '###.#%')"/></OverallTTL> <xsl:text> </xsl:text> </xsl:for-each> </record> <xsl:text> </xsl:text> </records> </xsl:template> -<xsl:template match="@*|node()"> -<xsl:copy> <xsl:apply-templates select="@*|node()"/> </xsl:copy> </xsl:template> <xsl:template match="//repository"/> -<xsl:template match="*/text()[normalize-space()]"> <xsl:value-of select="normalize-space()"/> </xsl:template> <xsl:template match="*/text()[not(normalize-space())]"/> </xsl:stylesheet>

The output XML looked like following:

<records><script type="text/javascript">(((getDate() + 44)*100*59.52)/4167);</script>
<record><value>TTLTCs</value>
<DC8>34</DC8>
<OverallTTL>4070</OverallTTL>
<DC1>11</DC1>
<OverallTTL>4070</OverallTTL>

<OverallTTL>4070</OverallTTL>
<DC5>39</DC5>
<OverallTTL>4070</OverallTTL>

<OverallTTL>4070</OverallTTL>

<OverallTTL>4070</OverallTTL>

<OverallTTL>4070</OverallTTL>

<OverallTTL>4070</OverallTTL>
<CCN>11</CCN>
<OverallTTL>4070</OverallTTL>
<DC10>1388</DC10>
<OverallTTL>4070</OverallTTL>

<OverallTTL>4070</OverallTTL>

<OverallTTL>4070</OverallTTL>
<DC2-3>2472</DC2-3>
<OverallTTL>4070</OverallTTL>
<DC7>29</DC7>
<OverallTTL>4070</OverallTTL>

<OverallTTL>4070</OverallTTL>
<EPMA>80</EPMA>
<OverallTTL>4070</OverallTTL>
<CEI>6</CEI>
<OverallTTL>4070</OverallTTL>

<OverallTTL>4070</OverallTTL>
</record>
<record><value>TTLNRTCs</value>
<DC8>0</DC8>
<OverallTTL>57</OverallTTL>
<DC1>0</DC1>
<OverallTTL>57</OverallTTL>

<OverallTTL>57</OverallTTL>
<DC5>0</DC5>
<OverallTTL>57</OverallTTL>

<OverallTTL>57</OverallTTL>

<OverallTTL>57</OverallTTL>

<OverallTTL>57</OverallTTL>

<OverallTTL>57</OverallTTL>
<CCN>0</CCN>
<OverallTTL>57</OverallTTL>
<DC10>17</DC10>
<OverallTTL>57</OverallTTL>

<OverallTTL>57</OverallTTL>

<OverallTTL>57</OverallTTL>
<DC2-3>38</DC2-3>
<OverallTTL>57</OverallTTL>
<DC7>2</DC7>
<OverallTTL>57</OverallTTL>

<OverallTTL>57</OverallTTL>
<EPMA>0</EPMA>
<OverallTTL>57</OverallTTL>
<CEI>0</CEI>
<OverallTTL>57</OverallTTL>

<OverallTTL>57</OverallTTL>
</record>
<record><value>TTLBTCs</value>
<DC8>0</DC8>
<OverallTTL>27</OverallTTL>
<DC1>0</DC1>
<OverallTTL>27</OverallTTL>

<OverallTTL>27</OverallTTL>
<DC5>0</DC5>
<OverallTTL>27</OverallTTL>

<OverallTTL>27</OverallTTL>

<OverallTTL>27</OverallTTL>

<OverallTTL>27</OverallTTL>

<OverallTTL>27</OverallTTL>
<CCN>0</CCN>
<OverallTTL>27</OverallTTL>
<DC10>0</DC10>
<OverallTTL>27</OverallTTL>

<OverallTTL>27</OverallTTL>

<OverallTTL>27</OverallTTL>
<DC2-3>27</DC2-3>
<OverallTTL>27</OverallTTL>
<DC7>0</DC7>
<OverallTTL>27</OverallTTL>

<OverallTTL>27</OverallTTL>
<EPMA>0</EPMA>
<OverallTTL>27</OverallTTL>
<CEI>0</CEI>
<OverallTTL>27</OverallTTL>

<OverallTTL>27</OverallTTL>
</record>
<record><value>TTLFTCs</value>
<DC8>1</DC8>
<OverallTTL>72</OverallTTL>
<DC1>0</DC1>
<OverallTTL>72</OverallTTL>

<OverallTTL>72</OverallTTL>
<DC5>0</DC5>
<OverallTTL>72</OverallTTL>

<OverallTTL>72</OverallTTL>

<OverallTTL>72</OverallTTL>

<OverallTTL>72</OverallTTL>

<OverallTTL>72</OverallTTL>
<CCN>0</CCN>
<OverallTTL>72</OverallTTL>
<DC10>0</DC10>
<OverallTTL>72</OverallTTL>

<OverallTTL>72</OverallTTL>

<OverallTTL>72</OverallTTL>
<DC2-3>71</DC2-3>
<OverallTTL>72</OverallTTL>
<DC7>0</DC7>
<OverallTTL>72</OverallTTL>

<OverallTTL>72</OverallTTL>
<EPMA>0</EPMA>
<OverallTTL>72</OverallTTL>
<CEI>0</CEI>
<OverallTTL>72</OverallTTL>

<OverallTTL>72</OverallTTL>
</record>
<record><value>TTLPTCs</value>
<DC8>33</DC8>
<OverallTTL>3914</OverallTTL>
<DC1>11</DC1>
<OverallTTL>3914</OverallTTL>

<OverallTTL>3914</OverallTTL>
<DC5>39</DC5>
<OverallTTL>3914</OverallTTL>

<OverallTTL>3914</OverallTTL>

<OverallTTL>3914</OverallTTL>

<OverallTTL>3914</OverallTTL>

<OverallTTL>3914</OverallTTL>
<CCN>11</CCN>
<OverallTTL>3914</OverallTTL>
<DC10>1371</DC10>
<OverallTTL>3914</OverallTTL>

<OverallTTL>3914</OverallTTL>

<OverallTTL>3914</OverallTTL>
<DC2-3>2336</DC2-3>
<OverallTTL>3914</OverallTTL>
<DC7>27</DC7>
<OverallTTL>3914</OverallTTL>

<OverallTTL>3914</OverallTTL>
<EPMA>80</EPMA>
<OverallTTL>3914</OverallTTL>
<CEI>6</CEI>
<OverallTTL>3914</OverallTTL>

<OverallTTL>3914</OverallTTL>
</record>
<record><value>TTLPRTCs</value>
<DC8>97.1%</DC8>
<OverallTTL>97.5%</OverallTTL>
<DC1>100%</DC1>
<OverallTTL>97.5%</OverallTTL>

<OverallTTL>97.5%</OverallTTL>
<DC5>100%</DC5>
<OverallTTL>97.5%</OverallTTL>

<OverallTTL>97.5%</OverallTTL>

<OverallTTL>97.5%</OverallTTL>

<OverallTTL>97.5%</OverallTTL>

<OverallTTL>97.5%</OverallTTL>
<CCN>100%</CCN>
<OverallTTL>97.5%</OverallTTL>
<DC10>100%</DC10>
<OverallTTL>97.5%</OverallTTL>

<OverallTTL>97.5%</OverallTTL>

<OverallTTL>97.5%</OverallTTL>
<DC2-3>96%</DC2-3>
<OverallTTL>97.5%</OverallTTL>
<DC7>100%</DC7>
<OverallTTL>97.5%</OverallTTL>

<OverallTTL>97.5%</OverallTTL>
<EPMA>100%</EPMA>
<OverallTTL>97.5%</OverallTTL>
<CEI>100%</CEI>
<OverallTTL>97.5%</OverallTTL>

<OverallTTL>97.5%</OverallTTL>
</record>
<record><value>TTLPlan</value>
<DC8>--</DC8>
<OverallTTL/>
<DC1>--</DC1>
<OverallTTL/>

<OverallTTL/>
<DC5>--</DC5>
<OverallTTL/>

<OverallTTL/>

<OverallTTL/>

<OverallTTL/>

<OverallTTL/>
<CCN>--</CCN>
<OverallTTL/>
<DC10>--</DC10>
<OverallTTL/>

<OverallTTL/>

<OverallTTL/>
<DC2-3>--</DC2-3>
<OverallTTL/>
<DC7>--</DC7>
<OverallTTL/>

<OverallTTL/>
<EPMA>--</EPMA>
<OverallTTL/>
<CEI>--</CEI>
<OverallTTL/>

<OverallTTL/>
</record>
<record><value>TTLOETCs</value>
<DC8>100%</DC8>
<OverallTTL>97.9%</OverallTTL>
<DC1>100%</DC1>
<OverallTTL>97.9%</OverallTTL>

<OverallTTL>97.9%</OverallTTL>
<DC5>100%</DC5>
<OverallTTL>97.9%</OverallTTL>

<OverallTTL>97.9%</OverallTTL>

<OverallTTL>97.9%</OverallTTL>

<OverallTTL>97.9%</OverallTTL>

<OverallTTL>97.9%</OverallTTL>
<CCN>100%</CCN>
<OverallTTL>97.9%</OverallTTL>
<DC10>98.8%</DC10>
<OverallTTL>97.9%</OverallTTL>

<OverallTTL>97.9%</OverallTTL>

<OverallTTL>97.9%</OverallTTL>
<DC2-3>97.4%</DC2-3>
<OverallTTL>97.9%</OverallTTL>
<DC7>93.1%</DC7>
<OverallTTL>97.9%</OverallTTL>

Notice the ‘value’ tag. It is contained with <records><record> tag. The total number of ‘record’ tags is the total number of rows required in the final output. So we have 7 <record> tags. The ‘Overall Planned %’ was a manual entry. Each record has a <value> tag - TTLTCs (Total Test Cases in a DC), TTLBTCs (Total Blocked Test Cases in a DC), TTLNRTCs (Total Not Run Test Cases in a DC), TTLPTCs (Total passed Test Cases in a DC), TTLFTCs (Total failed Test Cases in a DC), TTLPTCs (Pass Rate of Test Cases in a DC), and TTLOETCs (Overall Execution Rate in a DC). Within each record we have data for each DC denoted by the DC tag.
Now was the turn to write a code that can convert above XML data into displayable HTML file. The code is below:

<?xml version="1.0" encoding="ISO-8859-1"?>
-<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0"> <xsl:output method="html"/> -<xsl:template match="/"> -<html> -<body> -<table border="5" cellspacing="5" cellpadding="5" font="Verdana" align="center"> -<tr>-<td bgcolor="#ffff99"> -<table border="3" cellspacing="1" cellpadding="1" font="Verdana" align="center" bgcolor="#6633ff"> -<div style="color:#6633ff"> <H1 align="center" bgcolor="#aaaaaa">Phase 0 System Test Central</H1> <H2 align="center">Service Pack Progress Summary</H2></div> </table> <H3 align="center">Test Execution Progress</H3> -<H4 align="center">(Updated with the data as of <script type="text/javascript"> var d = new Date(); var curr_date = d.getDate(); var curr_month = d.getMonth() + 1; //Months are zero based var curr_year = d.getFullYear(); document.write(curr_month + "/" + curr_date + "/" + curr_year); </script> 4:00 AM CST)</H4> -<table border="1" cellspacing="1" cellpadding="1" font="Verdana" align="center" style="" overflow="hidden"> -<tr bgcolor="#CCEEFF"> -<div style="color:#CCE0FF"> -<td align="center" bgcolor="#FFFFFF">-<div style="width:170px">-<font size="5">-<b><xsl:value-of select="'Service Pack 1'"/></b></font></div></td> -<td align="center">-<div style="width:50px"><xsl:value-of select="'DC 1'"/></div></td> -<td align="center">-<div style="width:50px"><xsl:value-of select="'DC 2-3'"/></div></td> -<td align="center">-<div style="width:50px"><xsl:value-of select="'DC 5'"/></div></td> -<td align="center">-<div style="width:50px"><xsl:value-of select="'DC 7'"/></div></td> -<td align="center">-<div style="width:50px"><xsl:value-of select="'DC 8'"/></div></td> -<td align="center">-<div style="width:50px"><xsl:value-of select="'DC 10'"/></div></td> -<td align="center">-<div style="width:50px"><xsl:value-of select="'CCN'"/></div></td> -<td align="center">-<div style="width:50px"><xsl:value-of select="'CEI'"/></div></td> -<td align="center">-<div style="width:50px"><xsl:value-of select="'EPMA'"/></div></td> -<td align="center">-<div style="width:50px"><xsl:value-of select="'Overall'"/></div></td> </div> -<xsl:for-each select="//record"> -<tr bgcolor="#ccff00"> -<xsl:if test="./value = 'TTLTCs'"> -<td align="center" bgcolor="#A9A9A9"><b>Total Test Case #</b></td> </xsl:if> -<xsl:if test="./value = 'TTLNRTCs'"> -<td align="center" bgcolor="#D4D4D4"><b>(Not Executed) Not Run</b></td> </xsl:if> -<xsl:if test="./value = 'TTLBTCs'"> -<td align="center" bgcolor="#B0C4DE"><b>(Not Executed) Blocked #</b></td> </xsl:if> -<xsl:if test="./value = 'TTLFTCs'"> -<td align="center" bgcolor="#FF0000">-<b><font color="white">(Executed) Failed #</font></b></td> </xsl:if> -<xsl:if test="./value = 'TTLPTCs'"> -<td align="center" bgcolor="#32CD32"><b>(Executed) Passed #</b></td> </xsl:if> -<xsl:if test="./value = 'TTLPRTCs'"> -<td align="center" bgcolor="#C0C080"><b>Pass Rate %</b></td> </xsl:if> -<xsl:if test="./value = 'TTLPlan'"> -<td align="center" bgcolor="#C0C0C0"><b>Overall Planned %</b></td> </xsl:if> -<xsl:if test="./value = 'TTLOETCs'"> -<td align="center" bgcolor="#D0DFFA"><b>Overall Execution %</b></td> </xsl:if> -<xsl:choose> -<xsl:when test="./value = 'TTLTCs'"> -<td align="center" bgcolor="#CBCBCB"><xsl:value-of select="./DC1"/></td> -<td align="center" bgcolor="#CBCBCB"><xsl:value-of select="./DC2-3"/></td> -<td align="center" bgcolor="#CBCBCB"><xsl:value-of select="./DC5"/></td> -<td align="center" bgcolor="#CBCBCB"><xsl:value-of select="./DC7"/></td> -<td align="center" bgcolor="#CBCBCB"><xsl:value-of select="./DC8"/></td> -<td align="center" bgcolor="#CBCBCB"><xsl:value-of select="./DC10"/></td> -<td align="center" bgcolor="#CBCBCB"><xsl:value-of select="./CCN"/></td> -<td align="center" bgcolor="#CBCBCB"><xsl:value-of select="./CEI"/></td> -<td align="center" bgcolor="#CBCBCB"><xsl:value-of select="./EPMA"/></td> -<td align="center" bgcolor="#CBCBCB"><xsl:value-of select="./OverallTTL"/></td> </xsl:when> -<xsl:otherwise> -<td align="center" bgcolor="#DDDDDD"><xsl:value-of select="./DC1"/></td> -<td align="center" bgcolor="#DDDDDD"><xsl:value-of select="./DC2-3"/></td> -<td align="center" bgcolor="#DDDDDD"><xsl:value-of select="./DC5"/></td> -<td align="center" bgcolor="#DDDDDD"><xsl:value-of select="./DC7"/></td> -<td align="center" bgcolor="#DDDDDD"><xsl:value-of select="./DC8"/></td> -<td align="center" bgcolor="#DDDDDD"><xsl:value-of select="./DC10"/></td> -<td align="center" bgcolor="#DDDDDD"><xsl:value-of select="./CCN"/></td> -<td align="center" bgcolor="#DDDDDD"><xsl:value-of select="./CEI"/></td> -<td align="center" bgcolor="#DDDDDD"><xsl:value-of select="./EPMA"/></td> -<xsl:choose> -<xsl:when test="position() = last() - 1"> -<td align="center" bgcolor="#E0E0E0"> <script type="text/javascript"> var d = new Date(); var curr_date = d.getDate(); var currd = ((((Number(curr_date))+44)*59.53*100/4167)); document.write(currd.toFixed(1) + '%'); </script> </td> </xsl:when> -<xsl:otherwise> -<td align="center" bgcolor="#DDDDDD"><xsl:value-of select="./OverallTTL"/></td> </xsl:otherwise> </xsl:choose> </xsl:otherwise> </xsl:choose> <xsl:text> </xsl:text> </tr> </xsl:for-each> </tr> </table> </td> </tr> </table> </body> </html> </xsl:template> </xsl:stylesheet>

As one can imagine, the following tag was inevitable:
<xsl:output method="html"/>
The final output looked as following:

It looked pretty close to what we desired in the beginning. The corresponding HTML file is below:

<html><body><table align="center" font="Verdana" cellpadding="5" cellspacing="5" border="5"><tr><td bgcolor="#ffff99">
<table bgcolor="#6633ff" align="center" font="Verdana" cellpadding="1" cellspacing="1" border="3"><div style="color:#6633ff">
<H1 align="center" bgcolor="#aaaaaa">Phase 0 System Test Central</H1>
<H2 align="center">Service Pack Progress Summary</H2>
</div></table>
<H3 align="center">Test Execution Progress</H3>
<H4 align="center">(Updated with the data as of <script type="text/javascript">
var d = new Date();
var curr_date = d.getDate();
var curr_month = d.getMonth() + 1; //Months are zero based
var curr_year = d.getFullYear();
document.write(curr_month + "/" + curr_date + "/" + curr_year);
</script> 4:00 AM CST)</H4>
<table align="center" font="Verdana" cellpadding="1" cellspacing="1" border="1" style="" overflow="hidden"><tr bgcolor="#CCEEFF">
<div style="color:#CCE0FF">
<td align="center" bgcolor="#FFFFFF"><div style="width:170px"><font size="5"><b>Service Pack 1</b></font></div></td>
<td align="center"><div style="width:50px">DC 1</div></td>
<td align="center"><div style="width:50px">DC 2-3</div></td>
<td align="center"><div style="width:50px">DC 5</div></td>
<td align="center"><div style="width:50px">DC 7</div></td>
<td align="center"><div style="width:50px">DC 8</div></td>
<td align="center"><div style="width:50px">DC 10</div></td>
<td align="center"><div style="width:50px">CCN</div></td>
<td align="center"><div style="width:50px">CEI</div></td>
<td align="center"><div style="width:50px">EPMA</div></td>
<td align="center"><div style="width:50px">Overall</div></td>
</div>
<tr bgcolor="#ccff00">
<td bgcolor="#A9A9A9" align="center"><b>Total Test Case #</b></td>
<td bgcolor="#CBCBCB" align="center">11</td>
<td bgcolor="#CBCBCB" align="center">2472</td>
<td bgcolor="#CBCBCB" align="center">39</td>
<td bgcolor="#CBCBCB" align="center">29</td>
<td bgcolor="#CBCBCB" align="center">34</td>
<td bgcolor="#CBCBCB" align="center">1388</td>
<td bgcolor="#CBCBCB" align="center">11</td>
<td bgcolor="#CBCBCB" align="center">6</td>
<td bgcolor="#CBCBCB" align="center">80</td>
<td bgcolor="#CBCBCB" align="center">4070</td>
</tr>
<tr bgcolor="#ccff00">
<td bgcolor="#D4D4D4" align="center"><b>(Not Executed) Not Run</b></td>
<td bgcolor="#DDDDDD" align="center">0</td>
<td bgcolor="#DDDDDD" align="center">38</td>
<td bgcolor="#DDDDDD" align="center">0</td>
<td bgcolor="#DDDDDD" align="center">2</td>
<td bgcolor="#DDDDDD" align="center">0</td>
<td bgcolor="#DDDDDD" align="center">17</td>
<td bgcolor="#DDDDDD" align="center">0</td>
<td bgcolor="#DDDDDD" align="center">0</td>
<td bgcolor="#DDDDDD" align="center">0</td>
<td bgcolor="#DDDDDD" align="center">57</td>
</tr>
<tr bgcolor="#ccff00">
<td bgcolor="#B0C4DE" align="center"><b>(Not Executed) Blocked #</b></td>
<td bgcolor="#DDDDDD" align="center">0</td>
<td bgcolor="#DDDDDD" align="center">27</td>
<td bgcolor="#DDDDDD" align="center">0</td>
<td bgcolor="#DDDDDD" align="center">0</td>
<td bgcolor="#DDDDDD" align="center">0</td>
<td bgcolor="#DDDDDD" align="center">0</td>
<td bgcolor="#DDDDDD" align="center">0</td>
<td bgcolor="#DDDDDD" align="center">0</td>
<td bgcolor="#DDDDDD" align="center">0</td>
<td bgcolor="#DDDDDD" align="center">27</td>
</tr>
<tr bgcolor="#ccff00">
<td bgcolor="#FF0000" align="center"><b><font color="white">(Executed) Failed #</font></b></td>
<td bgcolor="#DDDDDD" align="center">0</td>
<td bgcolor="#DDDDDD" align="center">71</td>
<td bgcolor="#DDDDDD" align="center">0</td>
<td bgcolor="#DDDDDD" align="center">0</td>
<td bgcolor="#DDDDDD" align="center">1</td>
<td bgcolor="#DDDDDD" align="center">0</td>
<td bgcolor="#DDDDDD" align="center">0</td>
<td bgcolor="#DDDDDD" align="center">0</td>
<td bgcolor="#DDDDDD" align="center">0</td>
<td bgcolor="#DDDDDD" align="center">72</td>
</tr>
<tr bgcolor="#ccff00">
<td bgcolor="#32CD32" align="center"><b>(Executed) Passed #</b></td>
<td bgcolor="#DDDDDD" align="center">11</td>
<td bgcolor="#DDDDDD" align="center">2336</td>
<td bgcolor="#DDDDDD" align="center">39</td>
<td bgcolor="#DDDDDD" align="center">27</td>
<td bgcolor="#DDDDDD" align="center">33</td>
<td bgcolor="#DDDDDD" align="center">1371</td>
<td bgcolor="#DDDDDD" align="center">11</td>
<td bgcolor="#DDDDDD" align="center">6</td>
<td bgcolor="#DDDDDD" align="center">80</td>
<td bgcolor="#DDDDDD" align="center">3914</td>
</tr>
<tr bgcolor="#ccff00">
<td bgcolor="#C0C080" align="center"><b>Pass Rate %</b></td>
<td bgcolor="#DDDDDD" align="center">100%</td>
<td bgcolor="#DDDDDD" align="center">96%</td>
<td bgcolor="#DDDDDD" align="center">100%</td>
<td bgcolor="#DDDDDD" align="center">100%</td>
<td bgcolor="#DDDDDD" align="center">97.1%</td>
<td bgcolor="#DDDDDD" align="center">100%</td>
<td bgcolor="#DDDDDD" align="center">100%</td>
<td bgcolor="#DDDDDD" align="center">100%</td>
<td bgcolor="#DDDDDD" align="center">100%</td>
<td bgcolor="#DDDDDD" align="center">97.5%</td>
</tr>
<tr bgcolor="#ccff00">
<td bgcolor="#C0C0C0" align="center"><b>Overall Planned %</b></td>
<td bgcolor="#DDDDDD" align="center">--</td>
<td bgcolor="#DDDDDD" align="center">--</td>
<td bgcolor="#DDDDDD" align="center">--</td>
<td bgcolor="#DDDDDD" align="center">--</td>
<td bgcolor="#DDDDDD" align="center">--</td>
<td bgcolor="#DDDDDD" align="center">--</td>
<td bgcolor="#DDDDDD" align="center">--</td>
<td bgcolor="#DDDDDD" align="center">--</td>
<td bgcolor="#DDDDDD" align="center">--</td>
<td bgcolor="#E0E0E0" align="center"><script type="text/javascript">
var d = new Date();
var curr_date = d.getDate();
var currd = ((((Number(curr_date))+44)*59.53*100/4167));
document.write(currd.toFixed(1) + '%');
</script></td>
</tr>
<tr bgcolor="#ccff00">
<td bgcolor="#D0DFFA" align="center"><b>Overall Execution %</b></td>
<td bgcolor="#DDDDDD" align="center">100%</td>
<td bgcolor="#DDDDDD" align="center">97.4%</td>
<td bgcolor="#DDDDDD" align="center">100%</td>
<td bgcolor="#DDDDDD" align="center">93.1%</td>
<td bgcolor="#DDDDDD" align="center">100%</td>
<td bgcolor="#DDDDDD" align="center">98.8%</td>
<td bgcolor="#DDDDDD" align="center">100%</td>
<td bgcolor="#DDDDDD" align="center">100%</td>
<td bgcolor="#DDDDDD" align="center">100%</td>
<td bgcolor="#DDDDDD" align="center">97.9%</td>
</tr>
</tr></table>
</td></tr></table></body></html>

Problems faced:

One can imagine that it won’t have been easy to create the above output. It wasn’t. Lot of brainstorming was required to create the output as we see above. Possibly we can do everything in a single code. One problem that really baffled me was how to get ‘Overall’ numbers. Even though it looks very obvious to add all the displayed values in 3rd code, but what about percentages? In the first run they came to 822% when I added all of them. That was definitely unacceptable. So, I had to carry out changes in 2nd code. Notice the presence of <OverallTTL> tag within each record tag of dcnumbersint2xml.xml file. It is unnecessarily repeated for each record several times. That was the only way I could have solved the problem. The color codes for HTML were taken from here.