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 3346736
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T01:20:20+00:00 2026-05-18T01:20:20+00:00

I run CruiseControl.NET and am trying to construct an XSL stylesheet that extracts certain

  • 0

I run CruiseControl.NET and am trying to construct an XSL stylesheet that extracts certain information about broken unit tests from the XML build log. For each broken unit test, I would like to obtain in XSL the unit test’s name, the class name in which the unit test resides, and the failure message. Currently, I can obtain the unit test name and failure message, but I am having trouble obtaining the class name. I think this is because the unit test’s class name is only contained in a different area of the XML build log, and I am a noob at XSL. Here is a pared-down sample of my XSL stylesheet:

<!-- Unit tests -->
<xsl:template match="/">
 <table border="1" width="100%">
  <tr>
   <th align="left">Class</th>
   <th align="left">Method</th>
   <th align="left">Message</th>
  </tr>
  <xsl:apply-templates select="/cruisecontrol/build/*[local-name()='TestRun']/*[local-name()='Results']/*[local-name()='UnitTestResult']"/>
 </table>
</xsl:template>

<!-- Failed uint test -->
<xsl:template match="*[local-name()='UnitTestResult'][@outcome='Failed']">
 <tr>
  <td>
   <xsl:apply-templates select="/cruisecontrol/build/*[local-name()='TestRun']/*[local-name()='TestDefinitions']/*[local-name()='UnitTest'][@id=@testId]"/>
  </td>
  <td>
   <xsl:value-of select="@testName"/>
  </td>
  <td>
   <xsl:value-of select="*[local-name()='Output']/*[local-name()='ErrorInfo']/*[local-name()='Message']"/>
  </td>
 </tr>
</xsl:template>

<!-- Failed unit test class name -->
<xsl:template match="/cruisecontrol/build/*[local-name()='TestRun']/*[local-name()='TestDefinitions']/*[local-name()='UnitTest']">
 <xsl:value-of select="@className"/>
</xsl:template>

Here is a pared-down sample XML build log:

<cruisecontrol>
 <build>
  <TestRun>
   <TestDefinitions>
    <UnitTest name="MyUnitTest" storage="Test.dll" id="b17e5b2a-47d0-5f78-1750-07c8ac14518c">
     <TestMethod className="UnitTests.cs" name="MyUnitTest" />
    </UnitTest>
    ...
   </TestDefinitions>
   <Results>
    <UnitTestResult testId="b17e5b2a-47d0-5f78-1750-07c8ac14518c" testName="MyUnitTest" outcome="Failed">
     <Output>
      <ErrorInfo>
       <Message>Assert.AreEqual failed</Message>
      </ErrorInfo>
     </Output>
    </UnitTestResult>
    ...
   </Results>
  </TestRun>
 </build>
</cruisecontrol>

Here is the current output:

Unit test class name:

Unit test method name: MyUnitTest

Failure message: Assert.AreEqual failed

Here is the desired output:

Unit test class name: UnitTests.cs

Unit test method name: MyUnitTest

Failure message: Assert.AreEqual failed

My problem is that the class name is always empty. I am trying to use the testId attribute of the UnitTestResult node to reference the correct UnitTest node elsewhere in the document. What XSL or Xpath magic do I need to accomplish my goal?

  • 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-18T01:20:21+00:00Added an answer on May 18, 2026 at 1:20 am

    At first glance it looks like this is your problem:

    <xsl:apply-templates select="/cruisecontrol/build/*[local-name()='TestRun']/*[local-name()='TestDefinitions']/*[local-name()='UnitTest'][@id=@testId]"/>
    

    Specifically, the [@id=@testId] part. You’re trying to look up a UnitTest based on its id attribute from the testid attribute of a UnitTestResult. The problem is in this context [@id=@testId] means “look for UnitTest elements whose id and testId attributes match.”

    What you really want is to use the current() function, which allows you to have more than one context within a filter, like this:

    [@id=current()/@testId]
    

    Also, like Lucero commented, you’ll want to remove your local-name() calls since it’ll make everything simpler:

    <xsl:apply-templates 
      select="/cruisecontrol/build/TestRun/TestDefinitions/UnitTest[@id=current()/@testId]"
    />
    

    As an alternative to using a long XPath expression for your lookups you can use keys instead. They let you define a key, which you can use for shorter lookups later.

    Define a key like this:

    <xsl:key 
      name="tests" 
      match="/cruisecontrol/build/TestRun/TestDefinitions/UnitTest" 
      use="@id"/>
    

    Then use it like this:

    <xsl:apply-templates select="key('tests',@testId)"/>
    

    That saves you from having to use the current() function. Either way it’ll work.


    Using the local-name() function might indicate that you have a namespace problem. If the build and TestRun elements are in different namespaces, you can’t simply query them by using /cruisecontrol/build/TestRun/. That will query elements from the default namespace only. If TestRun is in another namespace, you’ll need to define that namespace in the XSLT file and use its prefix in your expressions, like this: /cruisecontrol/build/ns:TestRun where ns is the namespace prefix in question. What local-name() does is it ignores the namespace part of an element’s name, bypassing defining the namespace properly. It’s also useful when you don’t know what namespace(s) are going to be used in the source document.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

No related questions found

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.