Re: How to implement a Xspec unit testing
Posted: Thu Sep 01, 2022 11:33 am
Here is a simple example:
XSLT:
For more details see the wiki https://github.com/xspec/xspec/wiki/Wri ... -scenarios
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>
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>