How to implement a Xspec unit testing

Questions about XML that are not covered by the other forums should go here.
Martin Honnen
Posts: 95
Joined: Tue Aug 19, 2014 12:04 pm

Re: How to implement a Xspec unit testing

Post by Martin Honnen »

Here is a simple example:

Code: Select all

<x:description xmlns:x="http://www.jenitennison.com/xslt/xspec"
               stylesheet="sheet1.xsl">
  
  <x:scenario label="attribute match to child elements">
    <x:context>
      <Persons>
        <Person NameTitle="Sir"/>
        <Person NameTitle="Dr"/>
      </Persons>
    </x:context>
    <x:expect label="attribute match to child elements">
      <Persons>
        <Person>
          <NameTitle Value="Other" Description="Sir"/>
        </Person>
        <Person>
          <NameTitle Value="Dr" Description=""/>
        </Person>
      </Persons>
    </x:expect>
  </x:scenario>

</x:description>
XSLT:

Code: Select all

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
   xmlns:xs="http://www.w3.org/2001/XMLSchema"
   exclude-result-prefixes="#all" version="3.0">

 <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:mode on-no-match="shallow-copy" on-multiple-match="fail" />

</xsl:stylesheet>
For more details see the wiki https://github.com/xspec/xspec/wiki/Wri ... -scenarios