0

Does anyone know how to test this simple code using the XSpec in XSLT?

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

Using Xspec is simple for testing functions from a beginner point of view but for templates that select attributes is not(At least for me at the moment, because now I have started to use it).

Ex: This was easy:

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

Any suggestion is welcome. P.S. I'm using Xspec from OxygenXML.

potame
  • 7,597
  • 4
  • 26
  • 33
DanielCSD
  • 73
  • 1
  • 8

1 Answers1

1

Based on https://github.com/expath/xspec/wiki/Writing-Scenarios#matching-scenarios and https://github.com/expath/xspec/wiki/Writing-Scenarios#expectations you would write

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

This assumes you have a file test.xml with test data. I think you can also use

<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>
Martin Honnen
  • 160,499
  • 6
  • 90
  • 110
  • It seams that the error i've had can be solved by using . Starting from your response I realized that so thank you @Martin Honnen. – DanielCSD May 04 '16 at 09:04