1
votes

I have several XML elements like this:

  <testcase starttime="2012-09-03 10:41:29" timestamp=" 622.922000">
    <testlogfile file="" />
    <teststep timestamp=" 622.944000" level="0" type="user" ident="1" result="pass">Do something</teststep>
    <teststep timestamp=" 622.965000" level="0" type="user" ident="2" result="pass">Do something</teststep>
    <teststep timestamp=" 622.986000" level="0" type="user" ident="3" result="pass">Do something</teststep>
    <verdict time="2012-09-03 10:41:30" timestamp=" 623.428000" endtime="2012-09-03 10:41:30" endtimestamp=" 623.428000" result="pass" />
    <title>Title goes here</title>
    <ident>TC100_06</ident>
    <description>description goes here</description>
    <extendedinfo type="test case status">Approved</extendedinfo>
    <extendedinfo type="traceability">some requirement</extendedinfo>
    <extendedinfo type="vehicle mode">Hibernate, Parked, Living, Accessory</extendedinfo>
    <extendedinfo type="environment">Station with ATB</extendedinfo>
    <extendedinfo type="variants">veh variants</extendedinfo>
  </testcase>

I would like to make a xsl:variable select query to count testcases by "ident" and "test case status". I am able to implement 2 separate queries, but I dont know how to join them both:

<xsl:variable name="totalTc" select="count(//testcase[./ident!='text' and ./ident!='obsolete' and ./ident!='rtm' and ./ident!='status overview' and ./ident!='statistics'])"/>
<xsl:variable name="approvedTc" select="count(//extendedinfo[@type='test case status' and text()='Approved'])"/>

I expect joined query should look something like this, but I am unable to query attribute:

<xsl:variable name="totalTc" select="count(//testcase[./ident!='text' and ./ident!='obsolete' and ./ident!='rtm' and ./ident!='status overview' and ./ident!='statistics' and ./extendedinfo=='Approved'])"/>
2
You say you want to "join" the results. I'm not sure what you mean by "join". Do you mean you want to sum the results? Or that you want one variable to contain both values? Or something else? - Michael Kay
So what should be the result that you want obtained? Literally, please. - Dimitre Novatchev

2 Answers

2
votes

How about...

<xsl:variable name="totalTc" select="count(
  //testcase[
     ident!='text' and
     ident!='obsolete' and
     ident!='rtm' and
     ident!='status overview' and
     ident!='statistics' and
     extendedinfo[
         @type='test case status' and
         .='Approved']
   ])"/>

Options

Note in XSLT 2.0, you could instead use:

<xsl:variable name="totalTc" select="count(
  //testcase[
     not (ident in ('text','obsolete','rtm','status overview','statistics')) and
     extendedinfo[@type='test case status' and .='Approved']
   ])"/>

Also, instead of an expression of the form ...

testcase[ A and B]

... one could instead write....

testcase[A][B]

The former case may be ever so slightly more efficient, but I think personal style should also factor in, in relation to your choice of expression. So for example, one could also put...

<xsl:variable name="totalTc" select="count(//testcase
   [not (ident in ('text','obsolete','rtm','status overview','statistics'))]
   [extendedinfo[@type='test case status'][.='Approved']])"/>
1
votes

Use:

 count(
   //testcase
      [extendedinfo[@type='test case status']='Approved'
     and
       not(teststep
            [contains('|text|obsolete|rtm|status overview|statistics',
                       concat('|',@ident,'|')
                       )
           ]
         )
      ]
       )