tags:

views:

127

answers:

2

I'm having a problem with a xsl transformation on a extended xml JUnit report file. I've extended the file as follows:

<testcase classname="net.luminis.osgitest.test.adhoc.AdHocTest" name="testGetExportedPackagesByPackage" osgi-vendor-name="felix/1.8.0" time="3.212">
<osgi-specs>
  <osgi-spec version="4.1">
    <sections>
      <section>3.5.5</section>
    </sections>
  </osgi-spec>
  <osgi-spec version="4.2">
    <sections>
      <section>3.5.6</section>
    </sections>
  </osgi-spec>
</osgi-specs>

The osgi-specs node (and subnodes) in the testcase corresponds to a section overview file:

<versions>
  <version name="4.1" id="41">
    <sections>
      <section id="12" number="2" name="Security Layer">
        <sections>
          <section id="13" number="2.1" name="Introduction" parent="12">
            <sections>
              <section id="14" number="2.1.1" name="Essentials" parent="13" />
            </sections>
          </section>
        </sections>
      </section>
      <!-- some more sections with subsections -->
    </sections>
  </version>
  <version name="4.2" id="42">
    <!-- some more sections with subsections -->
  </version>
</version>

With these two xml files I generate an HTML table to display a section overview (per version) and a mark to show if the testresults succeeded (per osgi-vendor) with a xsl transformation. See the current version at http://opensource.luminis.net/svn/OSGITESTRESULTS/trunk/index.html

Now. I'm having the following problem. Sometimes I have a test with 3.5.5.1 as section number. But the section overview file only goes as deep as 3.5.5. So I want to display the test under the section 3.5.5. I tried this with xpath using something like this:

//testcase[@osgi-vendor-name=$osgi.vendor.name]//osgi-spec[@version=$osgi.version.name]//section[starts-with(text(), $osgi.section.number)]/../../../..

With this, I select all the testcases that corresponds to some section in a specific with a specific version and vendor. The problem is, when putting this expression in a for-each the testcase with section 3.5.5.1 is also shown in section 3, 3.5 end so on, but I only want it to show up in the most accurate section possible. (3.5.5) I'm not that familiar with xsl/xpath and I don't know if this can be achieved with one single xpath expression in a for-each. If so. What kind of expression do I need? If not. What is the best alternative?

+1  A: 

Why do you use starts-with() anyway, what about a simple value comparison?

//testcase[@osgi-vendor-name=$osgi.vendor.name]//osgi-spec[@version=$osgi.version.name]//section[. = $osgi.section.number]/../../../..
Erlock
Well. That's happening in my current xsl, but it only shows the testcases with the exact section number. In the example the testcases with 3.5.5.1 aren't shown anywhere, because that section doesn't exist. I therefore want it to show up in section 3.5.5
Treur
OK, I get the point. I think you can't express it within a mere XPath expression, but I'm searching for it.
Erlock
+1  A: 

Assuming that the most accurate section is also the last section, you can select just the last (and best) match by just getting the last node from the list of nodes using [last()]

//testcase[@osgi-vendor-name=$osgi.vendor.name]//osgi-spec[@version=$osgi.version.name]//section[starts-with(text(), $osgi.section.number)][last()]/../../../..

Robert Christie
The last section is indeed the most accurate. It seems that did the trick. Thanks a lot!
Treur
Hmm. Actually it didn't. The testcases still show op in less accurate sections. Though, I haven't found out why now.
Treur
Can you post a link to the overview file and the xslt?
Robert Christie
Sure. The xsl is located at:http://opensource.luminis.net/source/browse/OSGITEST/trunk/var/test-result-resources/junit-styles/junit-frames.xsl?r=338#l357 The section overview at:http://opensource.luminis.net/source/browse/OSGITEST/trunk/var/test-result-resources/osgi-specifications.xml?r=338
Treur