Skip to content
This repository has been archived by the owner on Dec 12, 2023. It is now read-only.

Commit

Permalink
Add XSpec problem definition example documents
Browse files Browse the repository at this point in the history
  • Loading branch information
GaryGapinski committed Jul 2, 2021
1 parent b55dade commit d023c71
Show file tree
Hide file tree
Showing 4 changed files with 143 additions and 0 deletions.
38 changes: 38 additions & 0 deletions resources/validations/src/media-type.sch
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<?xml version="1.0" encoding="UTF-8"?>
<sch:schema
queryBinding="xslt2"
xmlns:sch="http://purl.oclc.org/dsdl/schematron"
xmlns:sqf="http://www.schematron-quickfix.com/validator/process">
<!-- evaluate a media-type attribute for allowed values -->
<sch:pattern>
<sch:rule
context="@media-type"
role="error">
<sch:let
name="media-types-url"
value="'media-types.xml'" />
<sch:assert
test="doc-available($media-types-url)">media-types document is available.</sch:assert>
<sch:let
name="media-types"
value="doc($media-types-url)" />
<sch:let
name="media-types"
value="$media-types//value-set[@name = 'media-type']//enum/@value" />
<sch:assert
test="count($media-types) &gt; 1">media-types have been correctly obtained.</sch:assert>
<sch:assert
diagnostics="has-allowed-media-type-diagnostic"
id="has-allowed-media-type"
role="error"
test="current() = $media-types">A media-type attribute must have an allowed value.</sch:assert>
</sch:rule>
</sch:pattern>
<sch:diagnostics>
<sch:diagnostic
id="has-allowed-media-type-diagnostic">This <sch:value-of
select="name(parent::node())" /> has a media-type=" <sch:value-of
select="current()" />" which is not in the list of allowed media types. Allowed media types are <sch:value-of
select="string-join($media-types, ' ∨ ')" />.</sch:diagnostic>
</sch:diagnostics>
</sch:schema>
9 changes: 9 additions & 0 deletions resources/validations/src/media-type.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?xml version="1.0" encoding="UTF-8"?>
<?xml-model href="file:media-type.sch" schematypens="http://purl.oclc.org/dsdl/schematron" ?>
<!-- This is an instance document for testing media-types.sch -->
<stuff>
<rlink
media-type="text/plain" />
<rlink
media-type="text/text" />
</stuff>
29 changes: 29 additions & 0 deletions resources/validations/src/media-type.xspec
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?xml version="1.0" encoding="UTF-8"?>
<!-- This XSpec document is unit tests for media-type.sch -->
<x:description
schematron="media-type.sch"
xmlns:x="http://www.jenitennison.com/xslt/xspec">
<x:scenario
label="when a media-type attribute">
<x:scenario
label="has an allowed value">
<x:context>
<rlink
media-type="text/plain" />
</x:context>
<x:expect-not-assert
id="has-allowed-media-type"
label="that is correct" />
</x:scenario>
<x:scenario
label="lacks an allowed value">
<x:context>
<rlink
media-type="text/text" />
</x:context>
<x:expect-assert
id="has-allowed-media-type"
label="that is an error" />
</x:scenario>
</x:scenario>
</x:description>
67 changes: 67 additions & 0 deletions resources/validations/src/media-types.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
<?xml version="1.0" encoding="UTF-8"?>
<!-- This is a companion document to media-types.sch -->
<value-sets>
<value-set
name="media-type">
<formal-name>Resource Media Types</formal-name>
<description>A subset of IANA media types expected to be encountered.</description>
<binding
pattern="rlink/@media-type" />
<binding
pattern="base64/@media-type" />
<allowed-values>
<enum
value="application/gzip">application/gzip</enum>
<enum
value="application/msword">application/msword</enum>
<enum
value="application/octet-stream">application/octet-stream<!-- (NOTE: Used for a variety of binary formats, often ZIP archives.) --></enum>
<enum
value="application/pdf">application/pdf</enum>
<enum
value="application/vnd.ms-excel">application/vnd.ms-excel</enum>
<enum
value="application/vnd.ms-works">application/vnd.ms-works</enum>
<enum
value="application/vnd.oasis.opendocument.graphics">application/vnd.oasis.opendocument.graphics</enum>
<enum
value="application/vnd.oasis.opendocument.presentation">application/vnd.oasis.opendocument.presentation</enum>
<enum
value="application/vnd.oasis.opendocument.spreadsheet">application/vnd.oasis.opendocument.spreadsheet</enum>
<enum
value="application/vnd.oasis.opendocument.text">application/vnd.oasis.opendocument.text</enum>
<enum
value="application/vnd.openxmlformats-officedocument.presentationml.presentation">application/vnd.openxmlformats-officedocument.presentationml.presentation</enum>
<enum
value="application/vnd.openxmlformats-officedocument.spreadsheetml.sheet">application/vnd.openxmlformats-officedocument.spreadsheetml.sheet</enum>
<enum
value="application/vnd.openxmlformats-officedocument.wordprocessingml.document">application/vnd.openxmlformats-officedocument.wordprocessingml.document</enum>
<enum
value="application/x-bzip">application/x-bzip</enum>
<enum
value="application/x-bzip2">application/x-bzip2</enum>
<enum
value="application/x-tar">application/x-tar</enum>
<enum
value="application/zip">application/zip</enum>
<enum
value="image/bmp">image/bmp</enum>
<enum
value="image/jpeg">image/jpeg<!-- (NOTE: Not standard, but very frequently used)--></enum>
<enum
value="image/png">image/png</enum>
<enum
value="image/tiff">image/tiff</enum>
<enum
value="image/webp">image/webp</enum>
<enum
value="image/svg+xml">image/svg+xml</enum>
<enum
value="text/csv">text/csv</enum>
<enum
value="text/html">text/html</enum>
<enum
value="text/plain">text/plain</enum>
</allowed-values>
</value-set>
</value-sets>

1 comment on commit d023c71

@AirQuick
Copy link

@AirQuick AirQuick commented on d023c71 Jul 20, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is not an XSpec bug but a bug of the skeleton Schematron implementation:

Unfortunately the development of the skeleton Schematron implementation has been ceased and there is virtually no hope of its fix.

Note that the skeleton Schematron implementation has other quirks and bugs that have never been fixed.
A longer-term solution would be to switch to SchXslt as mentioned in Schematron/schematron#89. XSpec v2.1.2 and onwards are fully tested with SchXslt. SchXslt may have its own quirks but it is maintained actively. See Using another implementation of Schematron for how to use SchXslt with XSpec.

Please sign in to comment.