Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4332384
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T10:14:55+00:00 2026-05-21T10:14:55+00:00

I’m trying to parse an xml file output from googletest to display the results

  • 0

I’m trying to parse an xml file output from googletest to display the results in a pretty way in an html page. I have had a fair crack at it and have a working solution. Only one thing left to do.
Currently each class has a header and each function+test is displayed underneath, I’m looking for a way to extract the function name from the xml attribute to have it as its own sub-heading. Example below


Current Output

Class Name
functionName_testName
functionName_test2Name
function2Name_testName

Desired Output

Class Name
functionName
testName
test2Name
function2Name
testName

XML To be Parsed

<testsuite name="testPacketProcessor" tests="27" failures="0" disabled="0" errors="0" time="36.875">
    <testcase name="testInitialise_IpNotSet" status="run" time="0" classname="testPacketProcessor" />
    <testcase name="testInitialise_GoodIp" status="run" time="2.046" classname="testPacketProcessor" />
    <testcase name="testInitialise_BadIp" status="run" time="0.032" classname="testPacketProcessor" />
</testsuite>

XSL Currently Implemented

<xsl:for-each select="testsuites/testsuite">
    <div class="testHeading">
        <span><xsl:value-of select="substring-after(@name,'test')"/></span>
    </div>
    <xsl:for-each select="testcase">
    <div class="testReport">
        <xsl:if test="not(starts-with(@name,'DISABLED'))"><xsl:value-of select="substring-after(@name,'test')"/></xsl:if>
        <xsl:if test="starts-with(@name,'DISABLED')"><xsl:value-of select="substring-after(@name,'DISABLED_test')"/></xsl:if>
        <xsl:text> - </xsl:text>
        <xsl:if test="starts-with(@status,'run')">
            <xsl:if test="failure"><xsl:text>Fail</xsl:text></xsl:if>
            <xsl:if test= "not(failure)"><xsl:text>Pass</xsl:text></xsl:if>
        </xsl:if>
        <xsl:if test="starts-with(@status,'not')"><xsl:text>Disabled</xsl:text></xsl:if>
    </div>
    </xsl:for-each>
</xsl:for-each>

Using the above xml as an example I would like a subheading of “Initialise” under the packet processor heading with each test doucumented under the subheading

Any advice on the best way to go about this would be much appreciated. I’ve looked at xsl variables but cannot fathom how to deal with not being able to change the value. Have also read a little on xsl templates and recursion but I’m not sure how that would work for this situation.

Thanks in advance

Dougie

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-21T10:14:56+00:00Added an answer on May 21, 2026 at 10:14 am

    This transformation produces the subheading and name for each testcase:

    <xsl:stylesheet version="1.0"
     xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
     <xsl:output omit-xml-declaration="yes" indent="yes"/>
     <xsl:strip-space elements="*"/>
    
     <xsl:template match="testcase">
      Subheading: <xsl:value-of select=
       "substring-before(substring-after(@name, 'test'),
                         '_'
                         )
       "/>
       Name: <xsl:value-of select="substring-after(@name, '_')"/>
       <xsl:text>&#xA;</xsl:text>
     </xsl:template>
    </xsl:stylesheet>
    

    When applied on the provided XML document:

    <testsuites>
        <testsuite name="testPacketProcessor" tests="27" failures="0" disabled="0" errors="0" time="36.875">
            <testcase name="testInitialise_IpNotSet" status="run" time="0" classname="testPacketProcessor" />
            <testcase name="testInitialise_GoodIp" status="run" time="2.046" classname="testPacketProcessor" />
            <testcase name="testInitialise_BadIp" status="run" time="0.032" classname="testPacketProcessor" />
        </testsuite>
    </testsuites>
    

    the wanted, correct result is produced:

      Subheading: Initialise
       Name: IpNotSet
    
      Subheading: Initialise
       Name: GoodIp
    
      Subheading: Initialise
       Name: BadIp
    

    Explanation: Using the standard XPath functions substring-before() and substring-after()

    Edit: In a comment the OP clarified that he wanted grouping by function (tired of bad questions ?):

    This transformation performs the wanted grouping:

    <xsl:stylesheet version="1.0"
     xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
        <xsl:output omit-xml-declaration="yes" indent="yes"/>
        <xsl:strip-space elements="*"/>
    
        <xsl:key name="kTestsByFunction" match="testcase"
         use="substring-before(substring-after(@name, 'test'),
                                 '_'
                                  )"
      />
    
        <xsl:template match=
         "testcase
         [generate-id()
       =
        generate-id(key('kTestsByFunction',
                        substring-before(substring-after(@name, 'test'),
                                         '_'
                                          )
                        )[1]
                   )
          ]
         ">
        Subheading: 
            <xsl:value-of select=
            "substring-before(substring-after(@name, 'test'),
                              '_'
                              )
         "/>
        <xsl:for-each select=
         "key('kTestsByFunction',
               substring-before(substring-after(@name, 'test'),
                                    '_'
                                    )
             )
         ">
          Name:
               <xsl:value-of select="substring-after(@name, '_')"/>
               <xsl:text>&#xA;</xsl:text>
        </xsl:for-each>
        </xsl:template>
    </xsl:stylesheet>
    

    and produces the wanted result:

        Subheading: 
            Initialise
      Name:
               IpNotSet
    
      Name:
               GoodIp
    
      Name:
               BadIp
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

In my XML file chapters tag has more chapter tag.i need to display chapters
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
i want to parse a xhtml file and display in UITableView. what is the
I have a .ini file as follows: [playlist] numberofentries=2 File1=http://87.230.82.17:80 Title1=(#1 - 365/1400) Example
I am trying to understand how to use SyndicationItem to display feed which is
Basically, what I'm trying to create is a page of div tags, each has
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have just tried to save a simple *.rtf file with some websites and
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.