有人知道如何使用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>任何建议都是欢迎的。我使用的是OxygenXML的Xspec。
发布于 2016-05-04 08:35:11
基于https://github.com/expath/xspec/wiki/Writing-Scenarios#matching-scenarios和https://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>https://stackoverflow.com/questions/37021073
复制相似问题