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>

「ident」と「test case status」でテストケースをカウントする 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 に答える