1 | <?xml version="1.0" encoding="ISO-8859-1"?> |
---|
2 | |
---|
3 | <xsl:stylesheet version="2.0" |
---|
4 | xmlns:xsl ="http://www.w3.org/1999/XSL/Transform" |
---|
5 | xmlns:xs ="http://www.w3.org/2001/XMLSchema" |
---|
6 | xmlns:ibis="http://www.ibisph.org" |
---|
7 | |
---|
8 | exclude-result-prefixes="ibis xs xsl" |
---|
9 | > |
---|
10 | |
---|
11 | <ibis:doc> |
---|
12 | <name>ibis</name> |
---|
13 | <summary>Library of generic/common ibis specific functions</summary> |
---|
14 | <description> |
---|
15 | Library of generic/common IBIS specific global variables and functions. |
---|
16 | These functions are auto included in all pages because this file is |
---|
17 | imported by _main.xslt which is a part of all IBISPH-View system HTML |
---|
18 | output pages. |
---|
19 | </description> |
---|
20 | |
---|
21 | <author>Garth Braithwaite</author> |
---|
22 | <company>Software Technology Group/CDC/Ut Department of Health</company> |
---|
23 | </ibis:doc> |
---|
24 | |
---|
25 | |
---|
26 | <!-- ========================= P A R A M E T E R S and V A R I A B L E S |
---|
27 | The java servlet controller code adds ALL URL query request parameters |
---|
28 | to the XSLT transformation's parameters. Other special parameters are |
---|
29 | added as well. |
---|
30 | |
---|
31 | Many of the global type parameters are defined within this XSLT file. |
---|
32 | The parameters are passed in via the Java XSLT transformation parameter |
---|
33 | map (and thus are nameed according to the Java model map key value). |
---|
34 | For ease of XSLT code maintenance these global XSLT parameters are |
---|
35 | wrapped within an "ibis." prefix so that it is shown which XSLT file |
---|
36 | contains the definition. |
---|
37 | --> |
---|
38 | |
---|
39 | <!-- RESOURCE ADDRESSING: The "WebAppURLContextPrefix" parameter is used to |
---|
40 | explicitly build URL addresses to site related resources. The value is |
---|
41 | typically pulled from the servlet context. The resource's path is relative |
---|
42 | to the application's root. The prefix and the relative root address are |
---|
43 | then concatenated together (along with a separator) to build a complete, |
---|
44 | explicit path for the resource. This value can either be hard coded as an |
---|
45 | XSLT variable or in this case is set as a parameter passed in from the |
---|
46 | XML/XSLT transformer. |
---|
47 | |
---|
48 | This full context path value is needed because relative paths do not work |
---|
49 | for sites that have resources under different directory paths. E.g. the |
---|
50 | browser tries to get the resource based on the current resource's path. |
---|
51 | Relative paths work well with sites that deliver dynamic content using a |
---|
52 | servlet call that is located at the root level of the application's context. |
---|
53 | Addressing anything within a site like this using a relative address path |
---|
54 | works since the current resource's path is the root directory. |
---|
55 | |
---|
56 | The resource could also be explicitly coded for a given application context |
---|
57 | (or as the default application - without any context path) but then the code |
---|
58 | is context deployment dependent and would need changing based on the context |
---|
59 | the app was deployed under. So the root "/" can't be used either... |
---|
60 | |
---|
61 | This solution is messier from an XSLT perspective and in making sure that the |
---|
62 | XML/XSLT transformer is passed the correct value and inserts the value in as |
---|
63 | the "WebAppURLContextPrefix" parameter. However, this is a safe way to ensure |
---|
64 | that the resources are found while remaining deployment context independent. |
---|
65 | |
---|
66 | OLDER SOLUTIONS: |
---|
67 | If the apps context is the root then this value should be '/'. If it's |
---|
68 | not then it should be something like: '/ibisph-view/' |
---|
69 | <xsl:variable name="webappURLContextPrefix" select="'/ibisph-view/'"/> |
---|
70 | <xsl:variable name="webappURLContextPrefix" select="concat('/', SystemServlet:System.getWebAppContextName(), '/')" xmlns:SystemServlet="org.ibisph.servlets.view"/> |
---|
71 | |
---|
72 | WORKS - should be a little faster than system properties... |
---|
73 | <xsl:variable name="webappURLContextPrefix" select="concat('/', SystemServlet:System.getWebAppContextName(), '/')" xmlns:SystemServlet="org.ibisph.servlet.view"/> |
---|
74 | |
---|
75 | ALSO WORKS: |
---|
76 | <xsl:variable name="webappURLContext" select="org.ibisph:SystemProperties.getProperty('WebAppContextName')" xmlns:org.ibisph="org.ibisph"/> |
---|
77 | <xsl:variable name="webappURLContextPrefix" select="concat('/', $webappURLContext, '/')"/> |
---|
78 | |
---|
79 | TRIED: |
---|
80 | doesn't blow but doesn't have the correct content path either... |
---|
81 | select="concat(java:org.springframework.web.context.support.StaticWebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE, '/')" xmlns:java="http://xml.apache.org/xslt/java" |
---|
82 | |
---|
83 | ONE LINE PROPERTY CALL - WORKS: |
---|
84 | <xsl:variable name="webappURLContextPrefix" select="concat('/', org.ibisph:SystemProperties.getProperty('WebAppContextName'), '/')" xmlns:org.ibisph="org.ibisph"/> |
---|
85 | <xsl:variable name="webappURLContextPrefix" select="org.ibisph:SystemProperties.getProperty('WebAppURLContextPrefix')" xmlns:org.ibisph="org.ibisph"/> |
---|
86 | --> |
---|
87 | <xsl:param name="ibis.adopterTitle" select="'State'" |
---|
88 | ibis:doc="Value to be used when the XSLT code needs a title usage example |
---|
89 | is CP reports that compare community, state, and US. This should be |
---|
90 | overridden in the main ss.xslt with values like 'Utah', 'New Mexico' etc. |
---|
91 | " |
---|
92 | /> |
---|
93 | |
---|
94 | <xsl:param name="WebAppContextURLPrefix" |
---|
95 | ibis:doc="Prefix used/needed for referencing resources within the site." |
---|
96 | /> |
---|
97 | <xsl:variable name="ibis.urlPrefix" select="$WebAppContextURLPrefix" |
---|
98 | ibis:doc="WebAppContextURLPrefix access variable that all pages should use. |
---|
99 | Has the 'ibis.' prefix to know what XSLT the variable/param is defined in. |
---|
100 | " |
---|
101 | /> |
---|
102 | |
---|
103 | <xsl:param name="WebAppRemoteURLPrefix" select="$ibis.urlPrefix" |
---|
104 | ibis:doc=" |
---|
105 | Prefix used/needed for referencing this apps resources outside the |
---|
106 | site. This value is primarily used for the site search. |
---|
107 | " |
---|
108 | /> |
---|
109 | <xsl:variable name="ibis.remoteURLPrefix" select="$WebAppRemoteURLPrefix" |
---|
110 | ibis:doc="WebAppRemoteURLPrefix access variable that any pages could use. |
---|
111 | Has the 'ibis.' prefix to know what XSLT the variable/param is defined in. |
---|
112 | " |
---|
113 | /> |
---|
114 | |
---|
115 | <xsl:param name="UserProfile" |
---|
116 | ibis:doc="User's XML Profile document. Must provide a default node type |
---|
117 | value so that $UserProfile//AUTHORITIES will work when no user profile |
---|
118 | doc is injected. Otherwise the following type of check is needed: |
---|
119 | xsl:with-param name='userAuthorities' select='if(boolean($UserProfile))then $UserProfile//AUTHORITIES else '' |
---|
120 | " |
---|
121 | /> |
---|
122 | <xsl:variable name="ibis.userProfile" |
---|
123 | ibis:doc="User Profile XML variable that all pages should use. Has the |
---|
124 | 'ibis.' prefix to know what XSLT the variable/param is defined in. |
---|
125 | " |
---|
126 | > |
---|
127 | <xsl:choose> |
---|
128 | <xsl:when test="not($UserProfile)"> |
---|
129 | <FULL_NAME>Not Authenticated</FULL_NAME> |
---|
130 | </xsl:when> |
---|
131 | <xsl:when test="exists($UserProfile/USER)"> |
---|
132 | <xsl:copy-of select="$UserProfile/USER/*"/> |
---|
133 | </xsl:when> |
---|
134 | <xsl:when test="exists($UserProfile)"> |
---|
135 | <xsl:copy-of select="$UserProfile"/> |
---|
136 | </xsl:when> |
---|
137 | <xsl:otherwise> |
---|
138 | <FULL_NAME>Not Authenticated</FULL_NAME> |
---|
139 | </xsl:otherwise> |
---|
140 | </xsl:choose> |
---|
141 | </xsl:variable> |
---|
142 | <xsl:param name="ibis.userAuthorities" select="$ibis.userProfile/AUTHORITIES" |
---|
143 | ibis:doc="Variable used by the ibis:hasAuthority function or can be used directly." |
---|
144 | /> |
---|
145 | |
---|
146 | |
---|
147 | <xsl:param name="XMLModifedDate" |
---|
148 | ibis:doc="Parameter which is set via the Java model code so that the |
---|
149 | resultant page can display the XML file's modified date/time." |
---|
150 | /> |
---|
151 | <xsl:variable name="ibis.XMLModifedDate" |
---|
152 | select="if(string-length($XMLModifedDate) = 0) then //ibis:doc/versions/version[1]/date else $XMLModifedDate" |
---|
153 | ibis:doc="Variable that wraps the 'XMLModifedDate' parameter so that we |
---|
154 | know where this variable/parameter is defined. If the parameter |
---|
155 | value is not specified then the parameter defaults to selecting the |
---|
156 | XML document's ibis:doc version date." |
---|
157 | /> |
---|
158 | |
---|
159 | |
---|
160 | <!-- tried all sorts of patterns for time zone [ZN,*-3] [ZMST], [ZN,MST] etc... --> |
---|
161 | <xsl:param name="ibis.dateTimeFormatPicture" select="'[FNn,*-3], [D01] [MNn] [Y0001] [H]:[m]:[s]'"/> |
---|
162 | <xsl:param name="ibis.dateFormatPicture" select="'[FNn,*-3], [D01] [MNn] [Y0001]'"/> |
---|
163 | <xsl:param name="ibis.timeFormatPicture" select="'[H]:[m]:[s]'"/> |
---|
164 | |
---|
165 | |
---|
166 | <!-- ===================================================== G E N E R A L --> |
---|
167 | <xsl:function name="ibis:isFirstLetter_T_or_Y_or_X" as="xs:boolean" |
---|
168 | ibis:doc="Returns 'true' if the text is 'T'rue, 'Y'es, or 'x' - 'false' otherwise (case insensitive)." |
---|
169 | > |
---|
170 | <!-- can also be done by regexp --> |
---|
171 | <xsl:param name="text" ibis:doc="Source text to be tested"/> |
---|
172 | <xsl:variable name="firstLetter" select="lower-case(substring(normalize-space($text),1,1))"/> |
---|
173 | <xsl:value-of select="if(($firstLetter='y') or ($firstLetter='t') or ($firstLetter='x')) then true() else false()"/> |
---|
174 | </xsl:function> |
---|
175 | |
---|
176 | <xsl:function name="ibis:isAuthenticated" as="xs:boolean" |
---|
177 | ibis:doc="localizes checking the UserProfile param exists as a node. |
---|
178 | Note the not not is needed to handle string vs node xslt problem. |
---|
179 | Exists returns true for any/all defined variables/params. not |
---|
180 | handles a null or zero len string as false and also handles an |
---|
181 | empty node set as false. |
---|
182 | " |
---|
183 | > |
---|
184 | <xsl:value-of select="not(not($UserProfile))"/> |
---|
185 | </xsl:function> |
---|
186 | |
---|
187 | <xsl:function name="ibis:hasAuthorities" as="xs:boolean" |
---|
188 | ibis:doc="localizes checking if the user is authenticated and if so if |
---|
189 | they have an authority (secure type user). |
---|
190 | " |
---|
191 | > |
---|
192 | <xsl:value-of select="if(ibis:isAuthenticated()) then exists($ibis.userAuthorities/AUTHORITY) else false()"/> |
---|
193 | </xsl:function> |
---|
194 | |
---|
195 | <xsl:function name="ibis:hasAuthority" as="xs:boolean" |
---|
196 | ibis:doc="localizes checking the user authorities against the passed in |
---|
197 | AUTHORITY. If an AUTHORITY's text() matches one of the user's |
---|
198 | AUTHORITY values then true is returned. Else false is returned. |
---|
199 | This function is dependent on the global UserAuthorities param |
---|
200 | which needs to be injected via the java controller/transformer code. |
---|
201 | " |
---|
202 | > |
---|
203 | <xsl:param name="authority" ibis:doc="AUTHORITY value to be tested for."/> |
---|
204 | <xsl:value-of select="not(exists($authority)) or exists($ibis.userAuthorities[AUTHORITY = $authority])"/> |
---|
205 | </xsl:function> |
---|
206 | |
---|
207 | |
---|
208 | |
---|
209 | <!-- =========================== F O R M A T T I N G F U N C T I O N S --> |
---|
210 | <xsl:decimal-format name="ibis.defaultDecimalNumberFormat" NaN=" * " zero-digit="0" |
---|
211 | ibis:doc="Default format for the 'ibis:formatNumber function." |
---|
212 | /> |
---|
213 | <xsl:param name="ibis.defaultNumericPicture" select="',##0.##'" |
---|
214 | ibis:doc="default number picture format. Done as a variable so that |
---|
215 | site specefic templates can override." |
---|
216 | /> |
---|
217 | |
---|
218 | <!-- XSLT 2.0 does NOT provide for any literals inside the picture string that are |
---|
219 | defined as a format character. So to embed a "%" sign without actually multiplying |
---|
220 | the value by 100 a format picture in XSLT 1.0 could simply be "#.#'%'". In XSLT 2 |
---|
221 | it shows the #.#'%' with the value multiplied. The way to get around this is to |
---|
222 | change the % character with the decimal numeric format. However some value will |
---|
223 | need to be multiplied so the easiest way to deal with this is to simply replace |
---|
224 | '%' with '' and add the % character to the end of the string. |
---|
225 | See: http://www.w3.org/TR/xslt20/#defining-decimal-format. |
---|
226 | |
---|
227 | Below is an example of how to redefine the % character: |
---|
228 | <xsl:decimal-format name="ibis.percentSuffixDecimalNumberFormat" NaN=" * " zero-digit="0" percent="^" |
---|
229 | ibis:doc="Decimal format that redefines the % character so it doesn't interfere with the |
---|
230 | format picture string." |
---|
231 | /> |
---|
232 | --> |
---|
233 | <xsl:param name="ibis.numberFormatQuotedPercentString" ibis:doc="Percentage |
---|
234 | suffix signature to be searched and replaced with null and which signals |
---|
235 | to concat the % sign to the end of the formatted value. This value should |
---|
236 | match the value used by the admin system to signify that a % should be |
---|
237 | added as a numeric suffix. If the % is standalone then the value should |
---|
238 | be of the form 0.xx which will then cause the format number code to mult |
---|
239 | by 100 and add the %. Otherwise the value will be displayed 100x's too |
---|
240 | large (xx00.00%)." |
---|
241 | >'%'</xsl:param> |
---|
242 | |
---|
243 | |
---|
244 | |
---|
245 | <xsl:function name="ibis:getJavaScriptValue" as="xs:string" |
---|
246 | ibis:doc="If value exists then returns value otherwise null." |
---|
247 | > |
---|
248 | <xsl:param name="value" ibis:doc="Value to be tested."/> |
---|
249 | <!-- |
---|
250 | <xsl:value-of select="if(starts-with($value, '*') or (string-length($value) = 0))then 'null' else $value"/> |
---|
251 | --> |
---|
252 | <xsl:value-of select="if((string(number($value)) = 'NaN') or (string-length($value) = 0))then 'null' else $value"/> |
---|
253 | </xsl:function> |
---|
254 | |
---|
255 | |
---|
256 | |
---|
257 | <xsl:function name="ibis:getFormattedNumber" as="xs:string" |
---|
258 | ibis:doc="Numeric formatter that localizes the handling of numeric values. |
---|
259 | If a format is not specified then the common.defaultFormat is used." |
---|
260 | > |
---|
261 | <xsl:param name="number" ibis:doc="Value to be formatted. If the value is |
---|
262 | non numeric then that value will be returned. Otherwise the format |
---|
263 | picture will be applied." |
---|
264 | /> |
---|
265 | <xsl:param name="picture" ibis:doc="Format to be applied. If '' is specified |
---|
266 | then the ibis.defaultNumericPicture is used. If 'none' is specified then |
---|
267 | the actual value passed in will be used." |
---|
268 | /> |
---|
269 | <xsl:value-of select="ibis:getFormattedValue($number, $picture, '')"/> |
---|
270 | </xsl:function> |
---|
271 | |
---|
272 | |
---|
273 | <xsl:function name="ibis:getFormattedValue" as="xs:string" |
---|
274 | ibis:doc="Numeric formatter that localizes the handling of numeric values |
---|
275 | with a default null value. If a format is not specified then the |
---|
276 | common.defaultFormat is used. |
---|
277 | " |
---|
278 | > |
---|
279 | <xsl:param name="number" ibis:doc="Value to be formatted. If the value is |
---|
280 | non numeric then that value will be returned. Otherwise the format |
---|
281 | picture will be applied." |
---|
282 | /> |
---|
283 | <xsl:param name="picture" ibis:doc="Format to be applied. If '' is specified |
---|
284 | then the ibis.defaultNumericPicture is used. If 'none' is specified then |
---|
285 | the actual value passed in will be used." |
---|
286 | /> |
---|
287 | <xsl:param name="valueIfNull" |
---|
288 | ibis:doc="Value to use if the number param value is not something." |
---|
289 | /> |
---|
290 | |
---|
291 | <!-- |
---|
292 | <xsl:message select="'using the picture'"/> |
---|
293 | <xsl:message select="'when percent'"/> |
---|
294 | <xsl:message select="'otherwise using default picture'"/> |
---|
295 | <xsl:message select="concat('ibis:getFormattedValue - number: ', $number, ', value: ', $value, ', Picture: ', $picture, ', valueIfNull: ', $valueIfNull)"/> |
---|
296 | --> |
---|
297 | <xsl:variable name="value"> |
---|
298 | <xsl:choose> |
---|
299 | <xsl:when test="count($number) > 1"> |
---|
300 | <xsl:message select="'ibis:getFormattedValue - number is a sequence of the following values: '"/> |
---|
301 | <xsl:message select="$number"/> |
---|
302 | -999999 |
---|
303 | </xsl:when> |
---|
304 | <xsl:when test="(string-length(string($number)) != 0) or not($valueIfNull)"> |
---|
305 | <xsl:value-of select="$number"/> |
---|
306 | </xsl:when> |
---|
307 | <xsl:otherwise> |
---|
308 | <xsl:value-of select="$valueIfNull"/> |
---|
309 | </xsl:otherwise> |
---|
310 | </xsl:choose> |
---|
311 | </xsl:variable> |
---|
312 | <xsl:choose> |
---|
313 | <xsl:when test="$picture='none'"><xsl:value-of select="$value"/></xsl:when> |
---|
314 | |
---|
315 | <xsl:when test="string(number($value))='NaN'"><xsl:value-of select="$value"/></xsl:when> |
---|
316 | |
---|
317 | <!-- put this in because UT had some messed up QM configurations --> |
---|
318 | <xsl:when test="count($picture) > 1"> |
---|
319 | <xsl:message select="'***ibis:getFormattedValue - TOO MANY XSLT FORMATS***, picture:'"/> |
---|
320 | <xsl:message select="$picture"/> |
---|
321 | <xsl:value-of select="'CONTENT ERROR - TOO MANY XSLT FORMATS - PLEASE CONTACT US!!!'"/> |
---|
322 | </xsl:when> |
---|
323 | |
---|
324 | <!-- if format string was passed in, then check for the '%' string. |
---|
325 | If found then need to replace with a null and add the % to the |
---|
326 | end. See comments about about how XSLT 2.0 does not allow for |
---|
327 | literals that match one of the defined format control chars |
---|
328 | without effecting formatting. |
---|
329 | |
---|
330 | Else if the string doesn't contain the special percent character |
---|
331 | suffix signature then simply use as is. |
---|
332 | --> |
---|
333 | <xsl:when test="string-length($picture) != 0"> |
---|
334 | <xsl:choose> |
---|
335 | <xsl:when test="contains($picture, $ibis.numberFormatQuotedPercentString)"> |
---|
336 | <xsl:value-of select="concat(format-number($value, replace($picture,$ibis.numberFormatQuotedPercentString,''), 'ibis.defaultDecimalNumberFormat'), '%')"/> |
---|
337 | </xsl:when> |
---|
338 | <xsl:otherwise> |
---|
339 | <xsl:value-of select="format-number($value, $picture, 'ibis.defaultDecimalNumberFormat')"/> |
---|
340 | </xsl:otherwise> |
---|
341 | </xsl:choose> |
---|
342 | </xsl:when> |
---|
343 | |
---|
344 | <xsl:otherwise> |
---|
345 | <xsl:value-of select="format-number($value, $ibis.defaultNumericPicture, 'ibis.defaultDecimalNumberFormat')"/> |
---|
346 | </xsl:otherwise> |
---|
347 | </xsl:choose> |
---|
348 | </xsl:function> |
---|
349 | |
---|
350 | |
---|
351 | <!-- See: http://stackoverflow.com/questions/16892344/convert-a-string-to-date-format-in-xslt --> |
---|
352 | <xsl:function name="ibis:getFormattedDateTime" as="xs:string" |
---|
353 | ibis:doc="Localizes date and time formatting. Uses the ibis.dateTimeFormatPicture param." |
---|
354 | > |
---|
355 | <xsl:param name="dateTime" ibis:doc="DateTime value to be formatted. |
---|
356 | Call with current-dateTime() to get current system date and time." |
---|
357 | /> |
---|
358 | <xsl:value-of select="format-dateTime($dateTime, $ibis.dateTimeFormatPicture)"/> |
---|
359 | </xsl:function> |
---|
360 | <xsl:function name="ibis:getFormattedDate" as="xs:string" |
---|
361 | ibis:doc="Localizes date formatting. Uses the ibis.dateFormatPicture param." |
---|
362 | > |
---|
363 | <xsl:param name="date" ibis:doc="Date value to be formatted. Call with |
---|
364 | current-date() to get current system date." |
---|
365 | /> |
---|
366 | <xsl:value-of select="format-date($date, $ibis.dateFormatPicture)"/> |
---|
367 | </xsl:function> |
---|
368 | <xsl:function name="ibis:getFormattedTime" as="xs:string" |
---|
369 | ibis:doc="Localizes time formatting. Uses the ibis.timeFormatPicture param." |
---|
370 | > |
---|
371 | <xsl:param name="time" ibis:doc="Time value to be formatted. Call with |
---|
372 | current-time() to get current system time." |
---|
373 | /> |
---|
374 | <xsl:value-of select="format-time($time, $ibis.timeFormatPicture)"/> |
---|
375 | </xsl:function> |
---|
376 | |
---|
377 | |
---|
378 | <xsl:function name="ibis:getCompleteIndicatorViewTitle" as="xs:string" |
---|
379 | ibis:doc="Builds a complete view title." |
---|
380 | > |
---|
381 | <xsl:param name="indicatorView" ibis:doc="Indicator Profile View to be used to build the title from."/> |
---|
382 | <xsl:value-of select="concat($indicatorView/TITLE, ' ', $indicatorView/SUB_TITLE, ' ', $indicatorView/PERIOD_TITLE)"/> |
---|
383 | </xsl:function> |
---|
384 | <xsl:function name="ibis:getPartialIndicatorViewTitle" as="xs:string" |
---|
385 | ibis:doc="Builds the view's partial, most specific title." |
---|
386 | > |
---|
387 | <xsl:param name="indicatorView" ibis:doc="Indicator Profile View to be used to build the title from."/> |
---|
388 | <xsl:value-of select="concat($indicatorView/SUB_TITLE, ' ', $indicatorView/PERIOD_TITLE)"/> |
---|
389 | </xsl:function> |
---|
390 | |
---|
391 | |
---|
392 | |
---|
393 | <!-- ===================================== M A T C H C O P Y M O D E --> |
---|
394 | <xsl:template match="*" mode="ibis.copy" |
---|
395 | ibis:doc="Provides the ability to do an apply-templates to a copy-of of |
---|
396 | an element (some call this an 'identity transformation'). This |
---|
397 | allows for a deep copy with processing (which also allows ibis.include |
---|
398 | to be processed)." |
---|
399 | > |
---|
400 | <!-- Used the new element and copied the attributes, text, and sub |
---|
401 | elements so that any namespace attributes would not be copied. |
---|
402 | <xsl:apply-templates select="@*" mode="ibis.copy"/> |
---|
403 | <xsl:message>IBIS.COPY</xsl:message> |
---|
404 | --> |
---|
405 | <xsl:element name="{local-name()}"> |
---|
406 | <xsl:apply-templates select="current()/@* | current()/text() | current()/*" mode="ibis.copy"/> |
---|
407 | </xsl:element> |
---|
408 | </xsl:template> |
---|
409 | |
---|
410 | |
---|
411 | <xsl:template match="text()" mode="ibis.copy" ibis:doc="copies the text."> |
---|
412 | <!-- trims the text - not really needed for wiki - biggest issue with weird text |
---|
413 | was page indent on and extra line spacing etc. |
---|
414 | <xsl:value-of select="replace(., '^\s+|\s+$', '')"/> |
---|
415 | --> |
---|
416 | <xsl:value-of select="."/> |
---|
417 | </xsl:template> |
---|
418 | |
---|
419 | <!-- Match Copy Mode was lifted from the page.xslt in 4/2007. That code has a note |
---|
420 | about 4-18-06: removed template code and replaced with the mode="ibis.copy" |
---|
421 | templates above because the namespace was being copied into some HTML elements. |
---|
422 | See: http://www.stylusstudio.com/xsllist/200008/post50850.html |
---|
423 | --> |
---|
424 | |
---|
425 | <!-- The following templates are used to help page developers avoid having to |
---|
426 | hard code the deployment specific context into the URL path of IBIS related |
---|
427 | web pages. Example: If the app is deployed into a context called "ibisph-view" |
---|
428 | and your page is "http://localhost/ibisph-view/about/welcome.html" and it |
---|
429 | references an image that is under the "webapps/ibisph-view/image" directory |
---|
430 | it would need a url like "src='/ibisph-view/image/the_image.gif'" to properly |
---|
431 | get the correct resource. A relative path of "src='image/the_image.gif'" |
---|
432 | would cause the browser to request "http://localhost/ibisph-view/about/image/the_image.gif", |
---|
433 | while a path of "src='/image/the_image.gif'" would request this resource |
---|
434 | "http://localhost/image/the_image.gif" both of which are wrong. If the context |
---|
435 | path is coded so that the resource's URL is explicitly defined then a dependency |
---|
436 | exists between the web pages and the context which makes the deployment not |
---|
437 | as portable. Since the web app context path is needed by the XSLTs to build |
---|
438 | the correct HTML code it is implemented here to help static page development. |
---|
439 | Relative links work fine if the resource it within the same directory e.g. |
---|
440 | if the "about/welcome.html" page contains a relative link to the "about/content_usage.html" |
---|
441 | page then all is well. The "about/welcome.html" page can NOT contains a relative |
---|
442 | link to the "indicator/introduction.html" as it will not find the correct |
---|
443 | directory. |
---|
444 | --> |
---|
445 | |
---|
446 | <!-- Local IBIS URL adjustment templates. These templates simply add the web application's |
---|
447 | context path as a prefix to the link reference attribute. |
---|
448 | --> |
---|
449 | <xsl:template match="@ibis:href" mode="ibis.copy" ibis:doc="Inner 'ibis:href' template that adds the 'WebAppURLContextPrefix' to the 'href' attribute."> |
---|
450 | <xsl:attribute name="href" select="concat($ibis.urlPrefix, .)"/> |
---|
451 | </xsl:template> |
---|
452 | <xsl:template match="@ibis:src" mode="ibis.copy" ibis:doc="Inner 'ibis:src' template that adds the 'WebAppURLContextPrefix' to the 'src' attribute."> |
---|
453 | <xsl:attribute name="src" select="concat($ibis.urlPrefix, .)"/> |
---|
454 | </xsl:template> |
---|
455 | <xsl:template match="@ibis:action" mode="ibis.copy" ibis:doc="Inner 'ibis:action' template that adds the 'WebAppURLContextPrefix' to the 'action' attribute."> |
---|
456 | <xsl:attribute name="action" select="concat($ibis.urlPrefix, .)"/> |
---|
457 | </xsl:template> |
---|
458 | |
---|
459 | <xsl:template match="ibis:urlPrefix" mode="ibis.copy" ibis:doc="Mechanism that allows the HTML_CONTENTN PAGE type XML content to get the ibis:urlPrefix value. This is useful for pages that have javascript that need this value."> |
---|
460 | <xsl:value-of select="$ibis.urlPrefix"/> |
---|
461 | </xsl:template> |
---|
462 | |
---|
463 | <xsl:template match="@*" mode="ibis.copy" ibis:doc="Inner '@*' template that copies the non ibis: namespace attributes"> |
---|
464 | <xsl:copy-of select="."/> |
---|
465 | </xsl:template> |
---|
466 | |
---|
467 | <xsl:template match="@ibis:doc" mode="ibis.copy" ibis:doc="Eats ibis:doc attribute"/> |
---|
468 | <xsl:template match="ibis:doc" mode="ibis.copy" ibis:doc="Eats ibis:doc element"/> |
---|
469 | |
---|
470 | |
---|
471 | |
---|
472 | <!-- =============================== I B I S I N C L U D E M A T C H --> |
---|
473 | <xsl:template match="ibis:include" mode="#all" |
---|
474 | ibis:doc=" |
---|
475 | 'ibis:' namespace specific match template which opens |
---|
476 | the document via the 'href' attribute and does an 'apply-template' |
---|
477 | operation on its contents to process sub 'ibis:include' statements |
---|
478 | and to copy its text, attributes, and processing instructions. |
---|
479 | |
---|
480 | Provides the IBISPH system the ability to do simple xinclude |
---|
481 | type operations. As of 6-2004 the xerces parser 2.6.x has xinclude support |
---|
482 | but it must be configured when starting the Java JVM or with Java system |
---|
483 | properties. Since this might not be an option for some deployments (like |
---|
484 | Utah's state wide ITS app server) the system wide property solution is not |
---|
485 | an option. To handle being able to deploy into environments where we don't |
---|
486 | know which XSL engine is being used this two step xinclude processing |
---|
487 | was developed. This option is not nearly as seamless and requires that |
---|
488 | the java controller do 2 transformations - the first being this xinclude |
---|
489 | type transformation with the second being the normal desired page type |
---|
490 | transformation. Another option was to do the xinclude template inside the |
---|
491 | XSLT as a variable then use that variable for all XML nodes. This option |
---|
492 | appears to be somewhat slow but it is seamless. |
---|
493 | |
---|
494 | See: http://www.sagehill.net/docbookxsl/Xinclude.html |
---|
495 | |
---|
496 | This page simply copies the contents of the base document and when it |
---|
497 | hits the ibis:include element it opens the document with an XSLT document |
---|
498 | call based on the href attribute of the xi:include element. These |
---|
499 | elements are then copied into the source document. |
---|
500 | |
---|
501 | NOTE: the included document MUST be a valid XML file e.g. well |
---|
502 | formed with a root/master/parent element. |
---|
503 | |
---|
504 | If an children-only-flag attribute exists in the element then only |
---|
505 | only the sub elements and child text are included and processed. |
---|
506 | This is useful for including an element's text without having to |
---|
507 | include its root element. |
---|
508 | " |
---|
509 | > |
---|
510 | <!-- this only copies child content - skips container element. |
---|
511 | <xsl:copy> |
---|
512 | <xsl:apply-templates select="document(@href, /)" mode="ibis.include"/> |
---|
513 | </xsl:copy> |
---|
514 | <xsl:message select="document(@href, /)"/> |
---|
515 | <xsl:message select="concat('FOUND IBIS INCLUDE: ', @href)"/> |
---|
516 | |
---|
517 | <xsl:choose> |
---|
518 | <xsl:when test="exists(@include-children-only)"> |
---|
519 | <xsl:apply-templates select="document(@href, /)/(text() | *)" mode="ibis.copy"/> |
---|
520 | </xsl:when> |
---|
521 | <xsl:otherwise> |
---|
522 | <xsl:apply-templates select="document(@href, /)" mode="ibis.copy"/> |
---|
523 | </xsl:otherwise> |
---|
524 | </xsl:choose> |
---|
525 | --> |
---|
526 | <!--xsl:message select="'=================================================='"/> |
---|
527 | <xsl:message select="document(@href, /)"/> |
---|
528 | <xsl:message select="concat('FOUND IBIS INCLUDE: ', @href)"/--> |
---|
529 | <xsl:apply-templates select= |
---|
530 | "if(exists(@children-only-flag)) |
---|
531 | then document(@href, /)/(text() | *) |
---|
532 | else document(@href, /) |
---|
533 | " |
---|
534 | mode="ibis.copy" |
---|
535 | /> |
---|
536 | </xsl:template> |
---|
537 | |
---|
538 | </xsl:stylesheet> |
---|
539 | |
---|
540 | |
---|
541 | |
---|
542 | <!-- left here for posterity - a way to totally replace an element... |
---|
543 | <xsl:template match="ibis:a"> |
---|
544 | <xsl:element name="a"> |
---|
545 | <xsl:attribute name="href"><xsl:value-of select="concat($ibis.urlPrefix, @href)"/></xsl:attribute> |
---|
546 | <xsl:copy-of select="attribute::*[name() != 'href']"/> |
---|
547 | <xsl:apply-templates select="current()/text() | current()/*"/> |
---|
548 | </xsl:element> |
---|
549 | </xsl:template> |
---|
550 | --> |
---|
551 | <!-- img elements do not contain any text or other elements so it doesn't need |
---|
552 | to process/worry about anything other than it's attributes. |
---|
553 | <xsl:template match="ibis:img"> |
---|
554 | <img> |
---|
555 | <xsl:attribute name="src"><xsl:value-of select="concat($ibis.urlPrefix, @src)"/></xsl:attribute> |
---|
556 | <xsl:copy-of select="attribute::*[name() != 'src']"/> |
---|
557 | </img> |
---|
558 | </xsl:template> |
---|
559 | --> |
---|
560 | <!-- Since the a element can contain images, divs etc need to process text |
---|
561 | and elements contained within. |
---|
562 | <xsl:template match="ibis:form"> |
---|
563 | <xsl:element name="form"> |
---|
564 | <xsl:attribute name="action"><xsl:value-of select="concat($ibis.urlPrefix, @action)"/></xsl:attribute> |
---|
565 | <xsl:copy-of select="attribute::*[name() != 'action']"/> |
---|
566 | <xsl:apply-templates select="current()/text() | current()/*"/> |
---|
567 | </xsl:element> |
---|
568 | </xsl:template> |
---|
569 | --> |
---|
570 | |
---|
571 | <!-- ============================= End of File ============================= --> |
---|
572 | |
---|