none
Extract the data from XML to HTML table RRS feed

  • Question

  • <?xml version="1.0"?>
    <WebTestResultDetails>
      <Iteration>
        <Comment Text="EOL Main Page" />
        <Page Url="http://localhost/EOLDEV/docs/Public.aspx" ResponseTime="134">
          <DependentRequests>
            <DependentRequest Url="http://localhost/EOLDEV/content/scripts/SysWizard/js?v=fhHeZMuCVfBUWg5Y8_lLd4KAXvZiNGinY-QYijNtLXM1.js" />
    

    This is the resulting XML file that I converted from the .webtestresult file after I finished my web performance testing.

    I would like to extract the data like "Page Url", "Response Time" to a table in HTML form.

    How do I extract the data?

    Wednesday, November 19, 2014 7:12 AM

All replies

  • This is from the MSXML primer. It should do what you want.

    The following example shows a simple but complete XML document transformed by an XSLT style sheet. The source XML document, hello.xml, contains a "Hello, World!" greeting from "An XSLT Programmer".

    XML (hello.xml)

    Xml  CopyCode image<//img>Copy Code
    <?xml version="1.0"?>
    <?xml-stylesheet type="text/xsl" href="hello.xsl"?>
    <hello-world>   <greeter>An XSLT Programmer</greeter>   <greeting>Hello, World!</greeting></hello-world>
    

    The source document contains the <?xml-stylesheet ...?> processing instruction to link it to the XSLT style sheet, hello.xsl. The XSLT file contains instructions for transforming the source document into an HTML document.

    XSLT (hello.xsl)

    Xml  <//img>Copy Code
    <?xml version="1.0"?>
    <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
      <xsl:template match="/hello-world">
        <HTML>
          <HEAD>
            <TITLE></TITLE>
          </HEAD>
          <BODY>
            <H1>
              <xsl:value-of select="greeting"/>
            </H1>
            <xsl:apply-templates select="greeter"/>
          </BODY>
        </HTML>
      </xsl:template>
      <xsl:template match="greeter">
        <DIV>from <I><xsl:value-of select="."/></I></DIV>
      </xsl:template>
    </xsl:stylesheet>
    

    The effect of the transformation is to display the "Hello, World!" message on a Web page, followed by the signature of the greeter. This XSLT style sheet illustrates the basic features required of every XSLT style sheet:

    • An XSLT style sheet typically starts with the <?xml version="1.0"?> processing instruction, declaring it as an XML file.

    • The root element is <xsl:stylesheet>. The version attribute specifies the version of the XSLT specification. The xmlns:xsl attribute allows you to define a namespace alias (xsl) for use with every XSLT element in the document (e.g., <xsl:value-of> instead of simply <value-of>).

    • The content of this root element consists of a set of template rules declared within the <xsl:template> elements. These rules specify how various elements in the source XML document are to be transformed into result elements.

    The example above contains two simple template-rules. Together, they transform the contents in the source XML document into an HTML page. More complex XSLT style sheets contain either more template rules or template rules that are more complex.


    David Candy

    Wednesday, November 19, 2014 9:38 AM
  • <Page Url="http://localhost/EOLDEV/docs/Public.aspx" ResponseTime="134">
    

    Thanks for the help, but how about this?

    The Page Url and the ResponseTime are both within the same "<>"..

    Thursday, November 20, 2014 1:37 AM
  • (For future queries, to assist in the motivation of potential helpers, you should demonstrate that you have spent some time and effort trying to answer your own question. If you require an on-demand script writing service you should seek professional help.)

    Since you have a node called "Iteration" what follows assumes there may be more than one of these nodes. There is also more than one way to approach the transformation of the xml. The method outlined above by DavidMCandy is probably the simplest.

    Using this method the browser opens the xml file (or if run locally, double click the xml file).

    There is a requirement for this method that the xml file includes the href for the xsl file. In the example below (assumes the xsl file is in the same directory as the xml file) this is

    <?xml-stylesheet type="text/xsl" href="test.xsl"?>

    Also the complete html for the output will need to be included in the xsl file.

    Example

    testxsl.xml

    <?xml version="1.0"?>
    <?xml-stylesheet type="text/xsl" href="test.xsl"?>
    <WebTestResultDetails>
      <Iteration>
        <Comment Text="EOL Main Page" />
        <Page Url="http://localhost/EOLDEV/docs/Public.aspx" ResponseTime="134">
          <DependentRequests>
            <DependentRequest Url="http://localhost/EOLDEV/content/scripts/SysWizard/js?v=fhHeZMuCVfBUWg5Y8_lLd4KAXvZiNGinY-QYijNtLXM1.js" />
          </DependentRequests>
        </Page>
      </Iteration>
      <Iteration>
        <Comment Text="EOL Main Page" />
        <Page Url="http://localhost/EOLDEV/docs/Public.aspx" ResponseTime="146">
          <DependentRequests>
            <DependentRequest Url="http://localhost/EOLDEV/content/scripts/SysWizard/js?v=fhHeZMuCVfBUWg5Y8_lLd4KAXvZiNGinY-QYijNtLXM1.js" />
          </DependentRequests>
        </Page>
      </Iteration>
    </WebTestResultDetails>

    test.xsl

    <?xml version="1.0" encoding="utf-8"?>
    <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    <xsl:output method="html" indent="no"/>
     <xsl:template match="/">
      <HTML>
       <HEAD>
        <TITLE></TITLE>
       </HEAD>
       <BODY>
        <h2>My Web Tests</h2>
        <table border="1">
         <tr bgcolor="#9acd32"><th style="text-align:left">Url</th><th style="text-align:left">Response Time</th></tr>
         <xsl:for-each select="WebTestResultDetails/Iteration">
          <tr><td><xsl:value-of select="Page/@Url"/></td><td><xsl:value-of select="Page/@ResponseTime"/></td></tr>
         </xsl:for-each>
        </table>
       </BODY>
      </HTML>  
     </xsl:template>
    </xsl:stylesheet>

    Output:

    Friday, November 21, 2014 6:43 AM