1

我有几个这样的 XML 元素:

  <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>

我想做一个 xsl:variable 选择查询来按“身份”和“测试用例状态”计算测试用例。我能够实现 2 个单独的查询,但我不知道如何将它们都加入:

<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'])"/>

我希望加入的查询看起来像这样,但我无法查询属性:

<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'])"/>
4

2 回答 2

2

怎么样...

<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']
   ])"/>

选项

请注意,在 XSLT 2.0 中,您可以改为使用:

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

此外,而不是形式的表达......

testcase[ A and B]

...可以改为写....

testcase[A][B]

前一种情况可能会稍微高效一些,但我认为个人风格也应该考虑到你选择的表达方式。因此,例如,也可以将...

<xsl:variable name="totalTc" select="count(//testcase
   [not (ident in ('text','obsolete','rtm','status overview','statistics'))]
   [extendedinfo[@type='test case status'][.='Approved']])"/>
于 2012-09-03T12:10:36.923 回答
1

使用

 count(
   //testcase
      [extendedinfo[@type='test case status']='Approved'
     and
       not(teststep
            [contains('|text|obsolete|rtm|status overview|statistics',
                       concat('|',@ident,'|')
                       )
           ]
         )
      ]
       )
于 2012-09-03T15:52:09.907 回答