xml to html (table)

Discussion in 'XML' started by foolproofplan@gmail.com, Mar 23, 2007.

  1. Guest

    I have a situation where I need to convert an xml file into two types
    of tables in html. I have never done anything like this before, so I
    have been reading up on it online. However, I am not 100 percent sure
    where to begin.

    Here is an example of an xml file I have:

    <SquishReport version="1.2" >
    <summary fatals="0" testcases="13" expected_fails="0"
    unexpected_passes="0" warnings="0" tests="180" errors="0" fails="0"
    passes="180" />
    <testresult message="Start 'suite_second'" result="START"
    time="2007-03-23T10:51:43" >Test 'suite_second' started</testresult>
    <testresult fatals="0" expected_fails="0" unexpected_passes="0"
    warnings="0" errors="0" message="Start 'tst_BooleanApp'"
    result="START_TEST_CASE" fails="0" time="2007-03-23T10:51:43"
    passes="16" >Test Case 'tst_BooleanApp' started</testresult>
    <testresult line="../shared/scripts/common.py:1218"
    message="Comparison" result="PASS" time="2007-03-23T10:51:49" >'False'
    and 'False' are equal (Member Value test of Default_true at line 52)</
    testresult>
    <testresult line="test.py:140" message="Read Only Test: Object
    property comparison of ':mw.mw->wf.mw->wf->app_spl.QFrame1.mw->wf-
    >app_spl->panel.mw->wf->app_spl->panel->tab:f/t.tab pages.mw->wf-
    >app_spl->panel->tab:f/t-
    >scroll:all.QViewportWidget1.QFrame1.UI_Check_Box5.mw->wf->app_spl-
    >panel->tab:f/t->scroll:all->check_box:read_only.enabled' passed"

    result="PASS" time="2007-03-23T10:51:54" >'false' and 'false' are
    equal (Read Only Test)</testresult>
    <testresult message="End 'tst_BooleanApp'" result="END_TEST_CASE"
    time="2007-03-23T10:52:02" >End of test case 'tst_BooleanApp'</
    testresult>
    <testresult fatals="0" expected_fails="0" unexpected_passes="0"
    warnings="0" errors="0" message="Start 'tst_CadNoteApp'"
    result="START_TEST_CASE" fails="0" time="2007-03-23T10:52:03"
    passes="6" >Test Case 'tst_CadNoteApp' started</testresult>
    <testresult line="../shared/scripts/common.py:1218"
    message="Comparison" result="PASS" time="2007-03-23T10:52:18" >'test'
    and 'test' are equal (Member Value test of Name at line 73)</
    testresult>
    <testresult line="../shared/scripts/common.py:1218"
    message="Comparison" result="PASS" time="2007-03-23T10:52:19" >'test2'
    and 'test2' are equal (Member Value test of Author at line 98)</
    testresult>
    <testresult message="End 'tst_CadNoteApp'" result="END_TEST_CASE"
    time="2007-03-23T10:52:31" >End of test case 'tst_CadNoteApp'</
    testresult>
    <testresult message="End 'suite_second'" result="END"
    time="2007-03-23T10:58:16" >End of test 'suite_second'</testresult>
    </SquishReport>

    I understand the xml file is poorly formated but this is the way test
    cases are represented within this certain program. If it needs a
    little more explanation: Every time a test suite is run, or a specific
    test within that suite, it is represented as a testresult.

    I need to make one table that will have every test suite that is run
    (every START/END_TEST_CASE) with it's name, a icon of green or red
    depending on if everything passed, # of tests run, # of tests passed.

    I also need to make a table for each of these test suites that has
    each test that resides in that suite. (every other testresult between
    each START/END_TEST_CASE)

    This tasks seems a little hard for my first try at this, especially
    with how the tests are represented in xml. All the help is
    appreciated, thanks!
    , Mar 23, 2007
    #1
    1. Advertising

  2. Simon Brooke Guest

    in message <>,
    ('') wrote:

    > I have a situation where I need to convert an xml file into two types
    > of tables in html. I have never done anything like this before, so I
    > have been reading up on it online. However, I am not 100 percent sure
    > where to begin.
    >
    > Here is an example of an xml file I have:
    >
    > <SquishReport version="1.2" >
    > <summary fatals="0" testcases="13" expected_fails="0"
    > unexpected_passes="0" warnings="0" tests="180" errors="0" fails="0"
    > passes="180" />
    > <testresult message="Start 'suite_second'" result="START"
    > time="2007-03-23T10:51:43" >Test 'suite_second' started</testresult>
    > <testresult fatals="0" expected_fails="0" unexpected_passes="0"
    > warnings="0" errors="0" message="Start 'tst_BooleanApp'"
    > result="START_TEST_CASE" fails="0" time="2007-03-23T10:51:43"
    > passes="16" >Test Case 'tst_BooleanApp' started</testresult>
    > <testresult line="../shared/scripts/common.py:1218"
    > message="Comparison" result="PASS" time="2007-03-23T10:51:49" >'False'
    > and 'False' are equal (Member Value test of Default_true at line 52)</
    > testresult>
    > <testresult line="test.py:140" message="Read Only Test: Object
    > property comparison of ':mw.mw->wf.mw->wf->app_spl.QFrame1.mw->wf-
    >>app_spl->panel.mw->wf->app_spl->panel->tab:f/t.tab pages.mw->wf-
    >>app_spl->panel->tab:f/t-
    >>scroll:all.QViewportWidget1.QFrame1.UI_Check_Box5.mw->wf->app_spl-
    >>panel->tab:f/t->scroll:all->check_box:read_only.enabled' passed"

    > result="PASS" time="2007-03-23T10:51:54" >'false' and 'false' are
    > equal (Read Only Test)</testresult>
    > <testresult message="End 'tst_BooleanApp'" result="END_TEST_CASE"
    > time="2007-03-23T10:52:02" >End of test case 'tst_BooleanApp'</
    > testresult>
    > <testresult fatals="0" expected_fails="0" unexpected_passes="0"
    > warnings="0" errors="0" message="Start 'tst_CadNoteApp'"
    > result="START_TEST_CASE" fails="0" time="2007-03-23T10:52:03"
    > passes="6" >Test Case 'tst_CadNoteApp' started</testresult>
    > <testresult line="../shared/scripts/common.py:1218"
    > message="Comparison" result="PASS" time="2007-03-23T10:52:18" >'test'
    > and 'test' are equal (Member Value test of Name at line 73)</
    > testresult>
    > <testresult line="../shared/scripts/common.py:1218"
    > message="Comparison" result="PASS" time="2007-03-23T10:52:19" >'test2'
    > and 'test2' are equal (Member Value test of Author at line 98)</
    > testresult>
    > <testresult message="End 'tst_CadNoteApp'" result="END_TEST_CASE"
    > time="2007-03-23T10:52:31" >End of test case 'tst_CadNoteApp'</
    > testresult>
    > <testresult message="End 'suite_second'" result="END"
    > time="2007-03-23T10:58:16" >End of test 'suite_second'</testresult>
    > </SquishReport>
    >
    > I understand the xml file is poorly formated but this is the way test
    > cases are represented within this certain program. If it needs a
    > little more explanation: Every time a test suite is run, or a specific
    > test within that suite, it is represented as a testresult.


    OK, no XML parser can parse that data as presented. The reason is that the
    angle bracket characters '<' and '>' are irreducibly magic in XML. So the
    first thing you need to do is to replace the right angle bracket
    characters in the above which do not delimit markup with '&gt;'. Until you
    do that, you can't do anything. If the above is an example which gives all
    the problem cases, then passing it through

    sed 's/\([ |-]\)>/\1&gt;/g'

    would solve the problem.

    Having done that, you want templates something like

    <xsl:template match="SquishReport">
    <html>
    <head>
    <title>
    Froboz
    </title>
    </head>
    <body>
    <xsl:apply-templates select="summary"/>
    <table>
    <xsl:apply-templates select="testresult"/>
    </table>
    </body>
    </html>
    </xsl:template>

    <xsl:template match="testresult">
    <tr>
    <th><xsl:value-of select="@message"/></th>
    <td><xsl:value-of select="@time"/></td>
    <td><xsl:value-of select="@result"></td>
    <td><xsl:apply-templates/></td>
    </tr>
    </xsl:template>

    Obviously, I haven't dealt with all your attributes, and I haven't dealt
    with your summary - but that should give you a framework to get started.

    >
    > I need to make one table that will have every test suite that is run
    > (every START/END_TEST_CASE) with it's name, a icon of green or red
    > depending on if everything passed, # of tests run, # of tests passed.
    >
    > I also need to make a table for each of these test suites that has
    > each test that resides in that suite. (every other testresult between
    > each START/END_TEST_CASE)


    Someone cleverer than me may be able to solve this for you; I can't. One
    cannot in principle introduce unbalanced markup in XSL, so

    <xsl:template select="testresult[@result='END_TEST_CASE']">
    </table>
    <table>
    </xsl:template>

    is not going to work. Essentially the thing which generates the XML in the
    first place needs to generate a

    <SquishReport ...>
    <summary ../>
    <testcase>
    <testresult ...></testresult>
    <testresult ...></testresult>
    <testresult ...></testresult>
    </testcase>
    <testcase>
    <testresult ...></testresult>
    <testresult ...></testresult>
    <testresult ...></testresult>
    </testcase>
    ...
    </SquishReport>

    pattern - or, at least, that would make life MUCH easier for you.

    --
    (Simon Brooke) http://www.jasmine.org.uk/~simon/

    Error 1109: There is no message for this error
    Simon Brooke, Mar 24, 2007
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. David Williams
    Replies:
    2
    Views:
    1,120
    Jacob Yang [MSFT]
    Aug 12, 2003
  2. Beffmans
    Replies:
    1
    Views:
    5,378
    John Timney \(ASP.NET MVP\)
    Jul 8, 2005
  3. Rio
    Replies:
    4
    Views:
    1,184
  4. vitay
    Replies:
    8
    Views:
    542
    Stan McCann
    Nov 9, 2006
  5. Erik Wasser
    Replies:
    5
    Views:
    449
    Peter J. Holzer
    Mar 5, 2006
Loading...

Share This Page