|
| 1 | +<?xml version="1.0" encoding="UTF-8"?> |
| 2 | +<xsl:stylesheet extension-element-prefixes="xdmp" xdmp:dialect="1.0-ml" version="2.0" xmlns:schold="http://www.ascc.net/xml/schematron" xmlns:iso="http://purl.oclc.org/dsdl/schematron" xmlns:xhtml="http://www.w3.org/1999/xhtml" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xdmp="http://marklogic.com/xdmp" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> |
| 3 | + <!--Implementers: please note that overriding process-prolog or process-root is |
| 4 | + the preferred method for meta-stylesheets to use where possible. --> |
| 5 | + <xsl:param name="archiveDirParameter"/> |
| 6 | + <xsl:param name="archiveNameParameter"/> |
| 7 | + <xsl:param name="fileNameParameter"/> |
| 8 | + <xsl:param name="fileDirParameter"/> |
| 9 | + <xsl:variable name="document-uri"><xsl:value-of select="document-uri(/)"/></xsl:variable> |
| 10 | + <!--PHASES--> |
| 11 | + <!--PROLOG--> |
| 12 | + <xsl:output method="xml" omit-xml-declaration="no" standalone="yes" indent="yes" xmlns:axsl="http://www.w3.org/1999/XSL/TransformAlias" xmlns:svrl="http://purl.oclc.org/dsdl/svrl"/> |
| 13 | + <!--XSD TYPES FOR XSLT2--> |
| 14 | + <!--KEYS AND FUNCTIONS--> |
| 15 | + <!--DEFAULT RULES--> |
| 16 | + <!--MODE: SCHEMATRON-SELECT-FULL-PATH--> |
| 17 | + <!--This mode can be used to generate an ugly though full XPath for locators--> |
| 18 | + <xsl:template match="*|/|object-node()" mode="schematron-select-full-path"><xsl:apply-templates select="." mode="schematron-get-full-path"/></xsl:template> |
| 19 | + <!--MODE: SCHEMATRON-FULL-PATH--> |
| 20 | + <!--This mode can be used to generate an ugly though full XPath for locators--> |
| 21 | + <xsl:template match="*|/|object-node()" mode="schematron-get-full-path"><xsl:value-of select="xdmp:path(.)"/></xsl:template> |
| 22 | + <xsl:template match="@*" mode="schematron-get-full-path"><xsl:value-of select="xdmp:path(.)"/></xsl:template> |
| 23 | + <!--MODE: SCHEMATRON-FULL-PATH-2--> |
| 24 | + <!--This mode can be used to generate prefixed XPath for humans--> |
| 25 | + <xsl:template match="node() | @*" mode="schematron-get-full-path-2"><xsl:for-each select="ancestor-or-self::*"><xsl:text>/</xsl:text><xsl:value-of select="name(.)"/><xsl:if test="preceding-sibling::*[name(.)=name(current())]"><xsl:text>[</xsl:text><xsl:value-of select="count(preceding-sibling::*[name(.)=name(current())])+1"/><xsl:text>]</xsl:text></xsl:if></xsl:for-each><xsl:if test="not(self::*)"><xsl:text/>/@<xsl:value-of select="name(.)"/></xsl:if></xsl:template> |
| 26 | + <!--MODE: SCHEMATRON-FULL-PATH-3--> |
| 27 | + <!--This mode can be used to generate prefixed XPath for humans |
| 28 | + (Top-level element has index)--> |
| 29 | + <xsl:template match="node() | @*" mode="schematron-get-full-path-3"><xsl:for-each select="ancestor-or-self::*"><xsl:text>/</xsl:text><xsl:value-of select="name(.)"/><xsl:if test="parent::*"><xsl:text>[</xsl:text><xsl:value-of select="count(preceding-sibling::*[name(.)=name(current())])+1"/><xsl:text>]</xsl:text></xsl:if></xsl:for-each><xsl:if test="not(self::*)"><xsl:text/>/@<xsl:value-of select="name(.)"/></xsl:if></xsl:template> |
| 30 | + <!--MODE: GENERATE-ID-FROM-PATH --> |
| 31 | + <xsl:template match="/" mode="generate-id-from-path"/> |
| 32 | + <xsl:template match="text()" mode="generate-id-from-path"><xsl:apply-templates select="parent::*" mode="generate-id-from-path"/><xsl:value-of select="concat('.text-', 1+count(preceding-sibling::text()), '-')"/></xsl:template> |
| 33 | + <xsl:template match="comment()" mode="generate-id-from-path"><xsl:apply-templates select="parent::*" mode="generate-id-from-path"/><xsl:value-of select="concat('.comment-', 1+count(preceding-sibling::comment()), '-')"/></xsl:template> |
| 34 | + <xsl:template match="processing-instruction()" mode="generate-id-from-path"><xsl:apply-templates select="parent::*" mode="generate-id-from-path"/><xsl:value-of select="concat('.processing-instruction-', 1+count(preceding-sibling::processing-instruction()), '-')"/></xsl:template> |
| 35 | + <xsl:template match="@*" mode="generate-id-from-path"><xsl:apply-templates select="parent::*" mode="generate-id-from-path"/><xsl:value-of select="concat('.@', name())"/></xsl:template> |
| 36 | + <xsl:template match="*" mode="generate-id-from-path" priority="-0.5"><xsl:apply-templates select="parent::*" mode="generate-id-from-path"/><xsl:text>.</xsl:text><xsl:value-of select="concat('.',name(),'-',1+count(preceding-sibling::*[name()=name(current())]),'-')"/></xsl:template> |
| 37 | + <!--MODE: GENERATE-ID-2 --> |
| 38 | + <xsl:template match="/" mode="generate-id-2">U</xsl:template> |
| 39 | + <xsl:template match="*" mode="generate-id-2" priority="2"><xsl:text>U</xsl:text><xsl:number level="multiple" count="*"/></xsl:template> |
| 40 | + <xsl:template match="node()" mode="generate-id-2"><xsl:text>U.</xsl:text><xsl:number level="multiple" count="*"/><xsl:text>n</xsl:text><xsl:number count="node()"/></xsl:template> |
| 41 | + <xsl:template match="@*" mode="generate-id-2"><xsl:text>U.</xsl:text><xsl:number level="multiple" count="*"/><xsl:text>_</xsl:text><xsl:value-of select="string-length(local-name(.))"/><xsl:text>_</xsl:text><xsl:value-of select="translate(name(),':','.')"/></xsl:template> |
| 42 | + <!--Strip characters--> |
| 43 | + <xsl:template match="text()|number-node()|boolean-node()|null-node()" priority="-1"/> |
| 44 | + <!--SCHEMA SETUP--> |
| 45 | + <xsl:template match="/"><svrl:schematron-output title="user-validation" schemaVersion="1.0" xmlns:axsl="http://www.w3.org/1999/XSL/TransformAlias" xmlns:svrl="http://purl.oclc.org/dsdl/svrl"><xsl:comment><xsl:value-of select="$archiveDirParameter"/> |
| 46 | + <xsl:value-of select="$archiveNameParameter"/> |
| 47 | + <xsl:value-of select="$fileNameParameter"/> |
| 48 | + <xsl:value-of select="$fileDirParameter"/></xsl:comment><svrl:active-pattern><xsl:attribute name="document"><xsl:value-of select="document-uri(/)"/></xsl:attribute><xsl:attribute name="id">structural</xsl:attribute><xsl:attribute name="name">structural</xsl:attribute><xsl:apply-templates/></svrl:active-pattern><xsl:apply-templates select="/" mode="M3"/><svrl:active-pattern><xsl:attribute name="document"><xsl:value-of select="document-uri(/)"/></xsl:attribute><xsl:attribute name="id">co-occurence</xsl:attribute><xsl:attribute name="name">co-occurence</xsl:attribute><xsl:apply-templates/></svrl:active-pattern><xsl:apply-templates select="/" mode="M4"/></svrl:schematron-output></xsl:template> |
| 49 | + <!--SCHEMATRON PATTERNS--> |
| 50 | + <svrl:text xmlns:axsl="http://www.w3.org/1999/XSL/TransformAlias" xmlns:svrl="http://purl.oclc.org/dsdl/svrl">user-validation</svrl:text> |
| 51 | + <!--PATTERN structural--> |
| 52 | + <!--RULE --> |
| 53 | + <xsl:template match="user" priority="1000" mode="M3"><svrl:fired-rule context="user" xmlns:axsl="http://www.w3.org/1999/XSL/TransformAlias" xmlns:svrl="http://purl.oclc.org/dsdl/svrl"/> |
| 54 | + |
| 55 | + <!--ASSERT --> |
| 56 | + <xsl:choose> |
| 57 | + <xsl:when test="@id"/> |
| 58 | + <xsl:otherwise><svrl:failed-assert test="@id" xmlns:axsl="http://www.w3.org/1999/XSL/TransformAlias" xmlns:svrl="http://purl.oclc.org/dsdl/svrl"><xsl:attribute name="location"><xsl:apply-templates select="." mode="schematron-select-full-path"/></xsl:attribute><svrl:text>user element must have an id attribute</svrl:text></svrl:failed-assert></xsl:otherwise> |
| 59 | + </xsl:choose> |
| 60 | + |
| 61 | + <!--ASSERT --> |
| 62 | + <xsl:choose> |
| 63 | + <xsl:when test="count(*) = 5"/> |
| 64 | + <xsl:otherwise><svrl:failed-assert test="count(*) = 5" xmlns:axsl="http://www.w3.org/1999/XSL/TransformAlias" xmlns:svrl="http://purl.oclc.org/dsdl/svrl"><xsl:attribute name="location"><xsl:apply-templates select="." mode="schematron-select-full-path"/></xsl:attribute><svrl:text> |
| 65 | + user element must have 5 child elements: name, gender, |
| 66 | + age, score and result |
| 67 | + </svrl:text></svrl:failed-assert></xsl:otherwise> |
| 68 | + </xsl:choose> |
| 69 | + |
| 70 | + <!--ASSERT --> |
| 71 | + <xsl:choose> |
| 72 | + <xsl:when test="score/@total"/> |
| 73 | + <xsl:otherwise><svrl:failed-assert test="score/@total" xmlns:axsl="http://www.w3.org/1999/XSL/TransformAlias" xmlns:svrl="http://purl.oclc.org/dsdl/svrl"><xsl:attribute name="location"><xsl:apply-templates select="." mode="schematron-select-full-path"/></xsl:attribute><svrl:text>score element must have a total attribute</svrl:text></svrl:failed-assert></xsl:otherwise> |
| 74 | + </xsl:choose> |
| 75 | + |
| 76 | + <!--ASSERT --> |
| 77 | + <xsl:choose> |
| 78 | + <xsl:when test="score/count(*) = 2"/> |
| 79 | + <xsl:otherwise><svrl:failed-assert test="score/count(*) = 2" xmlns:axsl="http://www.w3.org/1999/XSL/TransformAlias" xmlns:svrl="http://purl.oclc.org/dsdl/svrl"><xsl:attribute name="location"><xsl:apply-templates select="." mode="schematron-select-full-path"/></xsl:attribute><svrl:text>score element must have two child elements</svrl:text></svrl:failed-assert></xsl:otherwise> |
| 80 | + </xsl:choose><xsl:apply-templates select="*|comment()|processing-instruction()" mode="M3"/></xsl:template> |
| 81 | + <xsl:template match="text()" priority="-1" mode="M3"/> |
| 82 | + <xsl:template match="@*|node()" priority="-2" mode="M3"><xsl:apply-templates select="*|comment()|processing-instruction()" mode="M3"/></xsl:template> |
| 83 | + <!--PATTERN co-occurence--> |
| 84 | + <!--RULE --> |
| 85 | + <xsl:template match="score" priority="1000" mode="M4"><svrl:fired-rule context="score" xmlns:axsl="http://www.w3.org/1999/XSL/TransformAlias" xmlns:svrl="http://purl.oclc.org/dsdl/svrl"/> |
| 86 | + |
| 87 | + <!--ASSERT --> |
| 88 | + <xsl:choose> |
| 89 | + <xsl:when test="@total = test-1 + test-2"/> |
| 90 | + <xsl:otherwise><svrl:failed-assert test="@total = test-1 + test-2" xmlns:axsl="http://www.w3.org/1999/XSL/TransformAlias" xmlns:svrl="http://purl.oclc.org/dsdl/svrl"><xsl:attribute name="location"><xsl:apply-templates select="." mode="schematron-select-full-path"/></xsl:attribute><svrl:text> |
| 91 | + total score must be a sum of test-1 and test-2 scores |
| 92 | + </svrl:text></svrl:failed-assert></xsl:otherwise> |
| 93 | + </xsl:choose> |
| 94 | + |
| 95 | + <!--ASSERT --> |
| 96 | + <xsl:choose> |
| 97 | + <xsl:when test="(@total gt 30 and ../result = 'pass') or (@total le 30 and ../result = 'fail')"/> |
| 98 | + <xsl:otherwise><svrl:failed-assert test="(@total gt 30 and ../result = 'pass') or (@total le 30 and ../result = 'fail')" xmlns:axsl="http://www.w3.org/1999/XSL/TransformAlias" xmlns:svrl="http://purl.oclc.org/dsdl/svrl"><xsl:attribute name="location"><xsl:apply-templates select="." mode="schematron-select-full-path"/></xsl:attribute><svrl:text> |
| 99 | + if the score is greater than 30 then the result will be |
| 100 | + 'pass' else 'fail' |
| 101 | + </svrl:text> <svrl:diagnostic-reference diagnostic="d1"> |
| 102 | + the score does not match with the result</svrl:diagnostic-reference></svrl:failed-assert></xsl:otherwise> |
| 103 | + </xsl:choose><xsl:apply-templates select="*|comment()|processing-instruction()" mode="M4"/></xsl:template> |
| 104 | + <xsl:template match="text()" priority="-1" mode="M4"/> |
| 105 | + <xsl:template match="@*|node()" priority="-2" mode="M4"><xsl:apply-templates select="*|comment()|processing-instruction()" mode="M4"/></xsl:template> |
| 106 | +</xsl:stylesheet> |
0 commit comments