forked from usnistgov/OSCAL
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmetaschema-generate-outline.xsl
78 lines (61 loc) · 3.74 KB
/
metaschema-generate-outline.xsl
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
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE xsl:stylesheet [
<!ENTITY nl "
">
]>
<!-- this template outputs a textual outline for a Metaschema model -->
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xpath-default-namespace="http://csrc.nist.gov/ns/oscal/metaschema/1.0"
exclude-result-prefixes="xs"
version="2.0">
<xsl:output method="text" omit-xml-declaration="yes" indent="no"/>
<xsl:import href="../lib/metaschema-compose.xsl"/>
<xsl:variable name="source" select="$composed-metaschema"/>
<xsl:key name="definitions" match="$composed-metaschema//(define-assembly | define-field | define-flag)" use="@name"/>
<xsl:template match="/">
<xsl:value-of select="METASCHEMA/@root"/>
<xsl:variable name="target" select="$composed-metaschema/METASCHEMA/define-assembly[@name = /METASCHEMA/@root]"/>
<xsl:apply-templates select="$target" mode="type-and-flags"/>
<xsl:text> - </xsl:text><xsl:value-of select="normalize-space($target/description)"/>
<xsl:text>&nl;</xsl:text>
<xsl:apply-templates select="$target/model/*">
<xsl:with-param name="padding"><xsl:text>  </xsl:text></xsl:with-param>
</xsl:apply-templates>
</xsl:template>
<xsl:template match="define-assembly | define-field" mode="type-and-flags">
<xsl:if test="@as-type and @as-type != 'string'"><xsl:text>:</xsl:text><xsl:value-of select="@as-type"/></xsl:if>
<xsl:if test="flag">
<xsl:text> (</xsl:text>
<xsl:apply-templates select="flag"/>
<xsl:text>)</xsl:text>
</xsl:if>
</xsl:template>
<xsl:template match="flag">
<xsl:variable name="target" select="if (@ref) then key('definitions',@ref) else ."/>
<xsl:value-of select="$target/@name"/>
<xsl:if test="$target/@as-type and $target/@as-type != 'string'"><xsl:text>:</xsl:text><xsl:value-of select="$target/@as-type"/></xsl:if>
<xsl:if test="not(@required) or @required=('no','false')"><xsl:text>?</xsl:text></xsl:if>
<xsl:if test="following-sibling::flag"><xsl:text>,</xsl:text></xsl:if>
</xsl:template>
<xsl:template match="assembly | field">
<xsl:param name="padding" required="yes"/>
<xsl:variable name="target" select="if (@ref) then key('definitions',@ref) else ."/>
<xsl:value-of select="$padding"/>
<xsl:value-of select="$target/@name"/>
<!-- handle cardinality -->
<xsl:choose>
<xsl:when test="(not(@min-occurs) or @min-occurs=0) and @max-occurs='unbounded'"><xsl:text>*</xsl:text></xsl:when>
<xsl:when test="(@min-occurs=1) and @max-occurs='unbounded'"><xsl:text>+</xsl:text></xsl:when>
<xsl:when test="(not(@min-occurs) or @min-occurs=0) and not(@maz-occurs) or @max-occurs=1"><xsl:text>?</xsl:text></xsl:when>
<xsl:when test="(@min-occurs=1) and not(@maz-occurs) or @max-occurs=1"><!-- do nothing --></xsl:when>
<xsl:otherwise><xsl:value-of select="concat('[',if (@min-occurs) then @min-occurs else '0','..',if (@msx-occurs) then @max-occurs else '0')"></xsl:value-of></xsl:otherwise>
</xsl:choose>
<xsl:apply-templates select="$target" mode="type-and-flags"/>
<xsl:text> - </xsl:text><xsl:value-of select="normalize-space(if (description) then description else $target/description)"/>
<xsl:text>&nl;</xsl:text>
<xsl:apply-templates select="$target/model/*">
<xsl:with-param name="padding"><xsl:value-of select="$padding"/><xsl:text>  </xsl:text></xsl:with-param>
</xsl:apply-templates>
</xsl:template>
<xsl:template match="*"/>
</xsl:stylesheet>