-
Notifications
You must be signed in to change notification settings - Fork 4
/
svrl2txt.xpl
110 lines (97 loc) · 4.07 KB
/
svrl2txt.xpl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
<?xml version="1.0" encoding="utf-8"?>
<p:declare-step xmlns:p="http:https://www.w3.org/ns/xproc"
xmlns:c="http:https://www.w3.org/ns/xproc-step"
xmlns:xsl="http:https://www.w3.org/1999/XSL/Transform"
xmlns:svrl="http:https://purl.oclc.org/dsdl/svrl"
xmlns:tr="http:https://transpect.io"
xmlns:cx="http:https://xmlcalabash.com/ns/extensions"
version="1.0"
name="svrl2txt"
type="tr:svrl2txt">
<p:input port="source" primary="true" >
<p:documentation>A c:reports wrapper document consisting of either c:errors or c:ok elements (the output of XSD
validations as performed by tr:xsdval) and the SVRL output of one or more Schematron validations</p:documentation>
</p:input>
<p:input port="rendering-xslt">
<p:inline>
<xsl:stylesheet xmlns:xsl="http:https://www.w3.org/1999/XSL/Transform"
xmlns:saxon="http:https://saxon.sf.net/"
xmlns:svrl="http:https://purl.oclc.org/dsdl/svrl"
xmlns:xs="http:https://www.w3.org/2001/XMLSchema"
xmlns:s="http:https://purl.oclc.org/dsdl/schematron"
version="2.0">
<!-- only important if used standalone, outside of XProc: -->
<xsl:output encoding="UTF-8" method="text"/>
<xsl:key name="by-id" match="*[@id]" use="@id"/>
<xsl:template match="/">
<bogo>
<xsl:text>
</xsl:text>
<xsl:variable name="svrl-items" as="element(*)*" select="//svrl:failed-assert | //svrl:successful-report"/>
<xsl:variable name="c-error-items" as="element(*)*" select="//c:error"/>
<xsl:choose>
<xsl:when test="exists($svrl-items | $c-error-items)">
<xsl:value-of select="distinct-values(//svrl:active-pattern/@document)"/>
<xsl:text>
XSD Validation:</xsl:text>
<xsl:apply-templates select="$c-error-items" mode="c-error"/>
<xsl:text>
Schematron Validation:
</xsl:text>
<xsl:for-each-group select="$svrl-items" group-by="preceding-sibling::svrl:active-pattern[1]/@id">
<xsl:variable name="active-pattern" select="key('by-id', current-grouping-key())"
as="element(svrl:active-pattern)"/>
<xsl:text>
ID: </xsl:text>
<xsl:value-of select="$active-pattern/@id" />
<xsl:if test="$active-pattern/@name ne $active-pattern/@id">
<xsl:text>
title: </xsl:text>
<xsl:value-of select="$active-pattern/@name"/>
</xsl:if>
<xsl:text>
test: </xsl:text>
<xsl:value-of select="@test"/>
<xsl:for-each select="current-group()">
<xsl:text>
location: </xsl:text>
<xsl:value-of select="@location"/>
<xsl:text>
message: </xsl:text>
<xsl:value-of select="svrl:text"/>
</xsl:for-each>
</xsl:for-each-group>
</xsl:when>
<xsl:otherwise>
<xsl:text>OK: </xsl:text>
<xsl:value-of select="distinct-values(//svrl:active-pattern/@document)"/>
</xsl:otherwise>
</xsl:choose>
<xsl:text>
</xsl:text>
</bogo></xsl:template>
<xsl:template match="c:error" mode="c-error">
<xsl:text xml:space="preserve">
</xsl:text>
<xsl:apply-templates select="@*" mode="#current"/>
<xsl:text xml:space="preserve">
</xsl:text>
<xsl:value-of select="'message: ', replace(., '^.+Number: \d+;\s+', '')" separator=""/>
</xsl:template>
<xsl:template match="@*" mode="c-error">
<xsl:text xml:space="preserve">
</xsl:text>
<xsl:value-of select="name(), ': ', ." separator=""/>
</xsl:template>
</xsl:stylesheet>
</p:inline>
</p:input>
<p:output port="result" primary="true"/>
<p:serialization port="result" method="text"/>
<p:xslt>
<p:input port="parameters">
<p:empty/>
</p:input>
<p:input port="stylesheet">
<p:pipe port="rendering-xslt" step="svrl2txt"/>
</p:input>
</p:xslt>
</p:declare-step>