source: main/trunk/ibisph-view/src/main/webapp/xslt/_ibis-format.xslt @ 19868

Last change on this file since 19868 was 18745, checked in by GarthBraithwaite_STG, 3 years ago

view - stubbed out videos. Menu icons. Added more columns to table index page.

File size: 10.2 KB
Line 
1<?xml version="1.0" encoding="ISO-8859-1"?>
2
3<xsl:stylesheet version="3.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.format</name>
13                <summary>Library of generic/common ibis format related functions</summary>
14        </ibis:doc>
15
16
17        <!-- ========================= P A R A M E T E R S   and   V A R I A B L E S
18                The java servlet controller code adds ALL URL query request parameters
19                to the XSLT transformation's parameters.  Other special parameters are
20                added as well. 
21
22                Many of the global type parameters are defined within this XSLT file. 
23                The parameters are passed in via the Java XSLT transformation parameter
24                map (and thus are nameed according to the Java model map key value). 
25                For ease of XSLT code maintenance these global XSLT parameters are
26                wrapped within an "ibis." prefix so that it is shown which XSLT file
27                contains the definition.
28        -->
29
30        <!-- tried all sorts of patterns for time zone [ZN,*-3] [ZMST], [ZN,MST] etc... -->
31        <xsl:param name="ibis.dateTimeFormatPicture" select="'[FNn,*-3], [D01] [MNn] [Y0001] [H]:[m]:[s]'"/>
32        <xsl:param name="ibis.dateFormatPicture"     select="'[FNn,*-3], [D01] [MNn] [Y0001]'"/>
33        <xsl:param name="ibis.timeFormatPicture"     select="'[H]:[m]:[s]'"/>
34
35
36        <!-- =========================== F O R M A T T I N G   F U N C T I O N S -->
37        <xsl:decimal-format name="ibis.defaultDecimalNumberFormat" NaN=" * " zero-digit="0"
38                ibis:doc="Default format for the 'ibis:formatNumber function."
39        />
40        <xsl:param name="ibis.defaultNumericPicture" select="',##0.##'"
41                ibis:doc="default number picture format.  Done as a variable so that
42                site specefic templates can override."
43        />
44
45        <!-- XSLT 2.0 does NOT provide for any literals inside the picture string that are
46        defined as a format character.  So to embed a "%" sign without actually multiplying
47        the value by 100 a format picture in XSLT 1.0 could simply be "#.#'%'".  In XSLT 2
48        it shows the #.#'%' with the value multiplied.  The way to get around this is to
49        change the % character with the decimal numeric format.  However some value will
50        need to be multiplied so the easiest way to deal with this is to simply replace
51        '%' with '' and add the % character to the end of the string.
52        See: http://www.w3.org/TR/xslt20/#defining-decimal-format.
53
54        Below is an example of how to redefine the % character:
55        <xsl:decimal-format name="ibis.percentSuffixDecimalNumberFormat" NaN=" * " zero-digit="0" percent="^"
56                ibis:doc="Decimal format that redefines the % character so it doesn't interfere with the
57                        format picture string."
58        />
59        -->
60        <xsl:param name="ibis.numberFormatQuotedPercentString" ibis:doc="Percentage
61                suffix signature to be searched and replaced with null and which signals
62                to concat the % sign to the end of the formatted value.  This value should
63                match the value used by the admin system to signify that a % should be
64                added as a numeric suffix.  If the % is standalone then the value should
65                be of the form 0.xx which will then cause the format number code to mult
66                by 100 and add the %.  Otherwise the value will be displayed 100x's too
67                large (xx00.00%)."
68        >'%'</xsl:param>
69
70
71
72        <xsl:function name="ibis:getFormattedNumber" as="xs:string"
73                ibis:doc="Numeric formatter that localizes the handling of numeric values.
74                If a format is not specified then the common.defaultFormat is used."
75        >
76                <xsl:param name="number" ibis:doc="Value to be formatted.  If the value is
77                        non numeric then that value will be returned.  Otherwise the format
78                        picture will be applied."
79                />
80                <xsl:param name="picture" ibis:doc="Format to be applied.  If '' is specified
81                        then the ibis.defaultNumericPicture is used.  If 'none' is specified then
82                        the actual value passed in will be used."
83                />
84                <xsl:value-of select="ibis:getFormattedValue($number, $picture, '')"/>
85        </xsl:function>
86
87
88        <xsl:function name="ibis:getFormattedValue" as="xs:string"
89                ibis:doc="Numeric formatter that localizes the handling of numeric values
90                        with a default null value.  If a format is not specified then the
91                        common.defaultFormat is used.
92                "
93        >
94                <xsl:param name="number" ibis:doc="Value to be formatted.  If the value is
95                        non numeric then that value will be returned.  Otherwise the format
96                        picture will be applied."
97                />
98                <xsl:param name="picture" ibis:doc="Format to be applied.  If '' is specified
99                        then the ibis.defaultNumericPicture is used.  If 'none' is specified then
100                        the actual value passed in will be used."
101                />
102                <xsl:param name="valueIfNull" 
103                        ibis:doc="Value to use if the number param value is not something."
104                />
105<xsl:if test="count($number) &gt; 1">
106        <xsl:message select="concat('ERROR: _ibis_format.getFormattedValue has a number that is a sequence!  First value is: ', $number[1], ', Count is: ', count($number) )"/>
107</xsl:if>
108                <xsl:variable name="value">
109                        <xsl:choose>
110                                <xsl:when test="(string-length(string($number[1])) != 0) or not($valueIfNull)">
111                                        <xsl:value-of select="$number[1]"/>
112                                </xsl:when>
113                                <xsl:otherwise>
114                                        <xsl:value-of select="$valueIfNull"/>
115                                </xsl:otherwise>
116                        </xsl:choose>
117                </xsl:variable>
118                <xsl:choose>
119                        <xsl:when test="$picture='none'"><xsl:value-of select="$value"/></xsl:when>
120                        <xsl:when test="string(number($value))='NaN'"><xsl:value-of select="$value"/></xsl:when>
121
122                        <!-- put this in because UT had some messed up QM configurations -->
123                        <xsl:when test="count($picture) &gt; 1">
124                                <xsl:message select="'ERROR: _ibis_format.getFormattedValue - TOO MANY XSLT FORMATS.  Picture:'"/> 
125                                <xsl:message select="$picture"/>
126                                <xsl:value-of select="'CONTENT ERROR - TOO MANY XSLT FORMATS - PLEASE CONTACT US!!!'"/>
127                        </xsl:when>
128
129                        <!-- if format string was passed in, then check for the '%' string.
130                                If found then need to replace with a null and add the % to the
131                                end.  See comments about about how XSLT 2.0 does not allow for
132                                literals that match one of the defined format control chars
133                                without effecting formatting.
134
135                                Else if the string doesn't contain the special percent character
136                                suffix signature then simply use as is.
137                        -->
138                        <xsl:when test="string-length($picture) != 0">
139                                <xsl:choose>
140                                        <xsl:when test="contains($picture, $ibis.numberFormatQuotedPercentString)">
141                                                <xsl:value-of select="concat(format-number($value, replace($picture,$ibis.numberFormatQuotedPercentString,''), 'ibis.defaultDecimalNumberFormat'), '%')"/>
142                                        </xsl:when>
143                                        <xsl:otherwise>
144                                                <xsl:value-of select="format-number($value, $picture, 'ibis.defaultDecimalNumberFormat')"/>
145                                        </xsl:otherwise>
146                                </xsl:choose>
147                        </xsl:when>
148
149                        <xsl:otherwise>
150                                <xsl:value-of select="format-number($value, $ibis.defaultNumericPicture, 'ibis.defaultDecimalNumberFormat')"/>
151                        </xsl:otherwise>
152                </xsl:choose>
153        </xsl:function>
154
155
156        <!-- See: http://stackoverflow.com/questions/16892344/convert-a-string-to-date-format-in-xslt -->
157        <xsl:function name="ibis:getFormattedDateTime" as="xs:string" 
158                ibis:doc="Localizes date and time formatting.  Uses the ibis.dateTimeFormatPicture param."
159        >
160                <xsl:param name="dateTime" ibis:doc="DateTime value to be formatted. 
161                        Call with current-dateTime() to get current system date and time."
162                />
163                <xsl:value-of select="format-dateTime($dateTime, $ibis.dateTimeFormatPicture)"/>
164        </xsl:function>
165        <xsl:function name="ibis:getFormattedDate" as="xs:string" 
166                ibis:doc="Localizes date formatting.  Uses the ibis.dateFormatPicture param."
167        >
168                <xsl:param name="date" ibis:doc="Date value to be formatted.  Call with
169                        current-date() to get current system date."
170                />
171                <xsl:value-of select="format-date($date, $ibis.dateFormatPicture)"/>
172        </xsl:function>
173        <xsl:function name="ibis:getFormattedTime" as="xs:string" 
174                ibis:doc="Localizes time formatting.  Uses the ibis.timeFormatPicture param."
175        >
176                <xsl:param name="time" ibis:doc="Time value to be formatted.  Call with
177                        current-time() to get current system time."
178                />
179                <xsl:value-of select="format-time($time, $ibis.timeFormatPicture)"/>
180        </xsl:function>
181
182
183        <xsl:function name="ibis:firstLetterLowerCase" as="xs:string" 
184                ibis:doc="Returns first letter forced to lower case"
185        >
186                        <xsl:param name="text" ibis:doc="Source text to be lowered"/>
187                        <xsl:variable name="firstLetter" select="lower-case(substring(normalize-space($text),1,1))"/>
188                        <xsl:value-of select="concat( lower-case(substring($text,1,1)), substring($text, 2, string-length($text)-1) )"/>
189        </xsl:function>
190
191</xsl:stylesheet>
192
193<!-- THIS CODE WAS MOVED TO THE IP TEXT AREA AS IT IS ONLY NEEDED THERE!!!!!!!
194        <xsl:function name="ibis:carriageReturnToBRTag"
195                ibis:doc="Searches the 'content' (nodes or string) for the \n character and
196                        replaces/inserts the HTML 'br' tag.  This is helpful to preserve white
197                        space formatting of some query meta data and indicator profile meta
198                        data.  If a node then the node is processed and any sub elements are
199                        copied into the output (which allows for embedded html support).  Else
200                        the text/string is tokenized and processed.
201                "
202        >
203                <xsl:param name="content" ibis:doc="Nodes or string to have Linefeed/Carriage
204                        Return characters searched and replaced with the HTML 'BR' tag element
205                "/>
206
207                <xsl:choose>
208                        <xsl:when test="$content/self::*">              < ! - - NODE - - >
209                                <xsl:apply-templates select="$content/* | $content/text()" mode="ibis.carriageReturnToBRTag"/>
210                        </xsl:when>     
211                        <xsl:otherwise>  <! - - STRING - - >
212                                <xsl:apply-templates select="$content" mode="ibis.carriageReturnToBRTag"/>
213                        </xsl:otherwise>
214                </xsl:choose>   
215        </xsl:function>
216
217
218        <xsl:template match="*" mode="ibis.carriageReturnToBRTag">
219                <xsl:copy-of select="."/>
220        </xsl:template>
221
222        <xsl:template match="text()" mode="ibis.carriageReturnToBRTag">
223                <xsl:param name="text" select="."/>
224                <xsl:for-each select="tokenize($text, '\n')">
225                        <xsl:value-of select="."/>
226                        <xsl:if test="position() != last()"><br/></xsl:if>
227                        <xsl:text>&#10;</xsl:text>  < ! - - added so the wiki script could handle correctly - - >
228                </xsl:for-each>
229        </xsl:template>
230-->
231<!-- ============================= End of File ============================= -->
232
Note: See TracBrowser for help on using the repository browser.