Skip to content

Instantly share code, notes, and snippets.

@dmj
Created July 27, 2022 10:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dmj/703daeda74340ba816f6a858c4132996 to your computer and use it in GitHub Desktop.
Save dmj/703daeda74340ba816f6a858c4132996 to your computer and use it in GitHub Desktop.
XSpec using throw/catch
<xsl:transform version="3.0" expand-text="yes"
xmlns:atop="http://www.tei-c.org/ns/atop"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:mode on-no-match="shallow-copy"/>
<xsl:template match="no-error-code">
<xsl:message terminate="yes"/>
</xsl:template>
<xsl:template match="error-code">
<xsl:message terminate="yes" error-code="atop:error"/>
</xsl:template>
</xsl:transform>
<xspec:description stylesheet="example.xsl"
xmlns:map="http://www.w3.org/2005/xpath-functions/map"
xmlns:atop="http://www.tei-c.org/ns/atop"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:xspec="http://www.jenitennison.com/xslt/xspec">
<xspec:scenario label="Terminating w/o error code" catch="yes">
<xspec:context>
<no-error-code/>
</xspec:context>
<!-- When terminated with an error, $xspec:resuls is a map(*)
rather than a node(). -->
<xspec:expect test="map:contains($xspec:result, 'err')"/>
</xspec:scenario>
<xspec:scenario label="Terminating with error code" catch="yes">
<xspec:context>
<error-code/>
</xspec:context>
<xspec:expect test="$xspec:result?err?code eq QName('http://www.tei-c.org/ns/atop', 'error')"/>
</xspec:scenario>
</xspec:description>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment