0

有谁知道如何使用 XSLT 中的 XSpec 测试这个简单的代码?

<xsl:template match="@NameTitle">       
    <NameTitle Value="{if(. = ('Sir', 'Lady', 'Hon', 'R Hon')) then 'Other' else .}"
         Description="{if(. = ('Sir', 'Lady', 'Hon', 'R Hon')) then . else ''}"/>
</xsl:template>


<xsl:template match="BusinessChannel/Contact/ContactPerson | SalesChannel/LoanWriter">
    <PersonName>
        <xsl:apply-templates select="@NameTitle"/>
        <FirstName>
            <xsl:value-of select="@FirstName"/>
        </FirstName>
        <Surname>
            <xsl:value-of select="@Surname"/>
        </Surname>
    </PersonName>
</xsl:template>

从初学者的角度来看,使用 Xspec 测试函数很简单,但对于选择属性的模板来说则不是(至少对我来说,因为现在我已经开始使用它了)。

例如:这很容易:

    <xsl:function name="fn:RemoveSpace">
        <xsl:param name="RemoveSpace"/>
        <xsl:if test="$RemoveSpace != ''">
            <xsl:value-of select="translate($RemoveSpace, ' ', '')"/>   
        </xsl:if>
    </xsl:function>

    <x:scenario label="Scenario for testing function RemoveSpace">
       <x:call function="fn:RemoveSpace">
           <x:param name="RemoveSpace" select="'Person Applicant'"/>
       </x:call>
       <x:expect label="Remove the white space">PersonApplicant</x:expect>
    </x:scenario>

欢迎任何建议。PS 我正在使用来自 OxygenXML 的 Xspec。

4

1 回答 1

1

基于https://github.com/expath/xspec/wiki/Writing-Scenarios#matching-scenarioshttps://github.com/expath/xspec/wiki/Writing-Scenarios#expectations你会写

<x:scenario label="when processing a NameTitle attribute">
   <x:context href="dir/test.xml" select="/foo/bar/@NameTitle"/>
   <x:expect label="it should produce a NameTitle  element">
          <NameTitle Value="Other"
         Description="Lady"/>
   </x:expect>
</x:scenario>

这假设您有一个test.xml包含测试数据的文件。我想你也可以使用

<x:scenario label="when processing a NameTitle attribute">
   <x:context select="@NameTitle">
      <foo NameTitle="Sir"/>
   </x:content>
   <x:expect label="it should produce a NameTitle  element">
          <NameTitle Value="Other"
         Description="Sir"/>
   </x:expect>
</x:scenario>
于 2016-05-04T08:35:11.943 回答