How to implement a Xspec unit testing
Questions about XML that are not covered by the other forums should go here.
-
- Posts: 101
- 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:
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>
Return to “General XML Questions”
Jump to
- Oxygen XML Editor/Author/Developer
- ↳ Feature Request
- ↳ Common Problems
- ↳ DITA (Editing and Publishing DITA Content)
- ↳ SDK-API, Frameworks - Document Types
- ↳ DocBook
- ↳ TEI
- ↳ XHTML
- ↳ Other Issues
- Oxygen XML Web Author
- ↳ Feature Request
- ↳ Common Problems
- Oxygen Content Fusion
- ↳ Feature Request
- ↳ Common Problems
- Oxygen JSON Editor
- ↳ Feature Request
- ↳ Common Problems
- Oxygen PDF Chemistry
- ↳ Feature Request
- ↳ Common Problems
- Oxygen Feedback
- ↳ Feature Request
- ↳ Common Problems
- Oxygen XML WebHelp
- ↳ Feature Request
- ↳ Common Problems
- XML
- ↳ General XML Questions
- ↳ XSLT and FOP
- ↳ XML Schemas
- ↳ XQuery
- NVDL
- ↳ General NVDL Issues
- ↳ oNVDL Related Issues
- XML Services Market
- ↳ Offer a Service