|
1 <?xml version="1.0"?> |
|
2 <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> |
|
3 <xsl:output method="xml" indent="yes"/> |
|
4 <!-- rules for filtering out system model items --> |
|
5 |
|
6 <!-- sysdef is the "data" element from the Model XML that filters are called on --> |
|
7 <xsl:template match="sysdef" mode="filter" priority="1"><xsl:param name="item"/> |
|
8 <xsl:variable name="result"> <!-- the ordered list of all ignores and filters, the last value is the one to note --> |
|
9 <xsl:choose> |
|
10 <xsl:when test="$item[self::meta]"> |
|
11 <xsl:apply-templates select="ignore|../ignore" mode="filter"> |
|
12 <xsl:with-param name="item" select="$item"/> |
|
13 </xsl:apply-templates> |
|
14 </xsl:when> |
|
15 <xsl:when test="$item[self::unit]"> |
|
16 <!-- only filter to determine if it's shown --> |
|
17 <xsl:apply-templates select="filter|../filter" mode="filter"> |
|
18 <xsl:with-param name="item" select="$item"/> |
|
19 </xsl:apply-templates> |
|
20 </xsl:when> |
|
21 <xsl:when test="$item/@id"> |
|
22 <!-- has an ID, so, use vars to save trouble of recalulating each time --> |
|
23 <xsl:variable name="id"><xsl:apply-templates select="$item/@id" mode="my-id"/></xsl:variable> <!-- namespaceless ID of this here --> |
|
24 <xsl:variable name="ns"><xsl:apply-templates select="$item/@id" mode="my-namespace"/></xsl:variable> <!-- ID's namespace --> |
|
25 <!-- use ignore and filter to determine if it's shown--> |
|
26 <xsl:apply-templates select="ignore[not(@meta or @meta-type)]|filter|../ignore[not(@meta or @meta-type)]|../filter" mode="filter"> |
|
27 <xsl:with-param name="id" select="$id"/> |
|
28 <xsl:with-param name="ns" select="$ns"/> |
|
29 <xsl:with-param name="item" select="$item"/> |
|
30 </xsl:apply-templates> |
|
31 </xsl:when> |
|
32 </xsl:choose> |
|
33 </xsl:variable> |
|
34 <xsl:choose> |
|
35 <xsl:when test="contains(concat(' ',normalize-space($result),' '),' ignore ')">hide</xsl:when> |
|
36 <xsl:otherwise> |
|
37 <xsl:variable name="display"> <!-- the last value in result --> |
|
38 <xsl:call-template name="notbefore"> |
|
39 <xsl:with-param name="string" select="normalize-space($result)"/> |
|
40 <xsl:with-param name="substr" select="' '"/> |
|
41 </xsl:call-template> |
|
42 </xsl:variable> |
|
43 |
|
44 |
|
45 <!-- if $display is empty or 'show' then return nothing (ie show), any other value return that --> |
|
46 <xsl:if test="$display!='show'"> |
|
47 <xsl:value-of select="$display"/> |
|
48 </xsl:if> |
|
49 </xsl:otherwise> |
|
50 </xsl:choose> |
|
51 </xsl:template> |
|
52 |
|
53 <!-- ignore a specific referenced ID --> |
|
54 <xsl:template match="ignore[@ref]" mode="filter" priority="2"><xsl:param name="item"/><xsl:param name="ns"/><xsl:param name="id"/> |
|
55 <xsl:variable name="this-id"><xsl:apply-templates select="@ref" mode="my-id"/></xsl:variable> <!-- namespaceless ID of this here --> |
|
56 <xsl:variable name="this-ns"><xsl:apply-templates select="@ref" mode="my-namespace"/></xsl:variable> <!-- ID's namespace --> |
|
57 <xsl:if test="$id = $this-id and $ns = $this-ns"> ignore </xsl:if> |
|
58 </xsl:template> |
|
59 |
|
60 <!-- ignore an entire namespace --> |
|
61 <xsl:template match="ignore[@namespace]" mode="filter" priority="2"><xsl:param name="ns"/> |
|
62 <xsl:if test="@namespace = $ns"> ignore </xsl:if> |
|
63 </xsl:template> |
|
64 |
|
65 <!-- ignore by human-readable name and item type (deprecated) --> |
|
66 <xsl:template match="ignore[not(@ref) and @name and @type]" mode="filter" priority="1"><xsl:param name="item"/> |
|
67 <!-- old way of doing this --> |
|
68 <xsl:if test="$item/@name=@name and name($item)= @type"> ignore </xsl:if> |
|
69 </xsl:template> |
|
70 |
|
71 |
|
72 <xsl:template match="ignore[@meta]" mode="filter" priority="2"><xsl:param name="item"/> |
|
73 <!-- ignore certain metadata rel values --> |
|
74 <xsl:if test="$item[self::meta] and (@meta='*' or $item/@rel=@meta or (not($item/@rel) and @meta='Generic')) |
|
75 and |
|
76 (not(@meta-type) or $item/@type=@meta-type or (@meta-type='auto' and not($item/@type)))"> ignore </xsl:if> |
|
77 </xsl:template> |
|
78 |
|
79 <xsl:template match="ignore[@meta-type]" mode="filter" priority="1"><xsl:param name="item"/> |
|
80 <!-- ignore certain metadata types, no rel values specified --> |
|
81 <xsl:if test="$item[self::meta] and $item/@type=@meta-type or (not($item/@type) and @meta-type='Generic')"> ignore </xsl:if> |
|
82 </xsl:template> |
|
83 |
|
84 <xsl:template match="filter" mode="filter" priority="1"><xsl:param name="item"/> |
|
85 <xsl:variable name="att" select="@select"/> |
|
86 <xsl:choose> |
|
87 <xsl:when test="not($item[self::component or self::unit or self::collection or self::package or self::layer])"/> |
|
88 <xsl:when test="@select='*'"> <!-- always matches --> |
|
89 <xsl:value-of select="concat(' ',@display,' ')"/> |
|
90 </xsl:when> |
|
91 <xsl:when test="not($item/@*[name()=$att])"/> <!-- this filter does not match this item--> |
|
92 <xsl:when test="not(@value) or @value='*'"> <!-- true if just checking for the presence of the attribute on the item --> |
|
93 <xsl:value-of select="concat(' ',@display,' ')"/> |
|
94 </xsl:when> |
|
95 <xsl:when test="@select='filter' and contains(@value,',')"> |
|
96 <!-- all items in @value must be in the comma-separated list of filter on this or child--> |
|
97 <xsl:variable name="ok"> |
|
98 <xsl:call-template name="all-in-list"> |
|
99 <xsl:with-param name="list" select="$item/@filter"/> |
|
100 <xsl:with-param name="items" select="@value"/> |
|
101 </xsl:call-template> |
|
102 </xsl:variable> |
|
103 <xsl:if test="$ok=1"> |
|
104 <xsl:value-of select="concat(' ',@display,' ')"/> |
|
105 </xsl:if> |
|
106 </xsl:when> |
|
107 <xsl:when test="@select='filter'"> |
|
108 <!-- @value must be in the comma-separated list of filter --> |
|
109 <xsl:if test="contains(concat(',',$item/@filter,','),concat(',',@value,','))"> |
|
110 <xsl:value-of select="concat(' ',@display,' ')"/> |
|
111 </xsl:if> |
|
112 </xsl:when> |
|
113 <xsl:when test="@select='class' and contains(@value,' ')"> |
|
114 <!-- all items in @value must be in the whitespace-separated list --> |
|
115 <xsl:variable name="ok"> |
|
116 <xsl:call-template name="all-in-list"> |
|
117 <xsl:with-param name="list" select="normalize-space($item/@class)"/> |
|
118 <xsl:with-param name="items" select="@value"/> |
|
119 <xsl:with-param name="separator" select="' '"/> |
|
120 </xsl:call-template> |
|
121 </xsl:variable> |
|
122 <xsl:if test="$ok=1"> |
|
123 <xsl:value-of select="concat(' ',@display,' ')"/> |
|
124 </xsl:if> |
|
125 </xsl:when> |
|
126 <xsl:when test="@select='class'"> |
|
127 <!-- @value must be in the whitespace-separated list --> |
|
128 <xsl:if test="contains(concat(' ',normalize-space($item/@class),' '),concat(' ',@value,' '))"> |
|
129 <xsl:value-of select="concat(' ',@display,' ')"/> |
|
130 </xsl:if> |
|
131 </xsl:when> |
|
132 <!-- any other attribute must match exactly on the component --> |
|
133 <xsl:when test="@value= $item/@*[name()=$att]"> |
|
134 <xsl:value-of select="concat(' ',@display,' ')"/> |
|
135 </xsl:when> |
|
136 </xsl:choose> |
|
137 </xsl:template> |
|
138 |
|
139 |
|
140 <!-- utility functions follow --> |
|
141 |
|
142 <!-- return 1 if all items in $items are in the list $list --> |
|
143 <xsl:template name="all-in-list"><xsl:param name="list"/><xsl:param name="items"/><xsl:param name="separator" select="','"/> |
|
144 <xsl:variable name="elist" select="concat($separator,$list,$separator)"/> |
|
145 <xsl:choose> |
|
146 <xsl:when test="contains($items,$separator)"> |
|
147 <xsl:variable name="item" select="concat($separator,substring-before($items,$separator),$separator)"/> |
|
148 <xsl:if test="contains($elist,$item) or (starts-with($item,'!') and not(contains($elist,substring($item,2))))"> |
|
149 <xsl:call-template name="all-in-list"> |
|
150 <xsl:with-param name="list" select="$list"/> |
|
151 <xsl:with-param name="separator" select="$separator"/> |
|
152 <xsl:with-param name="items" select="substring-after($items,$separator)"/> |
|
153 </xsl:call-template> |
|
154 </xsl:if> |
|
155 </xsl:when> |
|
156 <xsl:otherwise> |
|
157 <xsl:variable name="item" select="concat($separator,$items,$separator)"/> |
|
158 <xsl:if test="contains($elist,$item) or (starts-with($item,'!') and not(contains($elist,substring($item,2))))">1</xsl:if> |
|
159 </xsl:otherwise> |
|
160 </xsl:choose> |
|
161 </xsl:template> |
|
162 |
|
163 <!-- return the filename in a path --> |
|
164 <xsl:template name="notbefore"><xsl:param name="string"/><xsl:param name="substr" select="'/'"/> |
|
165 <xsl:choose> |
|
166 <xsl:when test="not(contains($string,$substr))"> |
|
167 <xsl:value-of select="$string"/> |
|
168 </xsl:when> |
|
169 <xsl:otherwise> |
|
170 <xsl:call-template name="notbefore"> |
|
171 <xsl:with-param name="string" select="substring-after($string,$substr)"/> |
|
172 <xsl:with-param name="substr" select="$substr"/> |
|
173 </xsl:call-template> |
|
174 </xsl:otherwise> |
|
175 </xsl:choose> |
|
176 </xsl:template> |
|
177 </xsl:stylesheet> |