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

Last change on this file since 22751 was 22707, checked in by GarthBraithwaite_STG, 7 months ago

view - updated docs and internal workings of ibis.include.

File size: 8.6 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
106                <xsl:if test="count($number) &gt; 1">
107                        <xsl:message select="concat('ERROR: _ibis_format.getFormattedValue has a number that is a sequence!  First value is: ', $number[1], ', Count is: ', count($number) )"/>
108                </xsl:if>
109                <xsl:variable name="value">
110                        <xsl:choose>
111                                <xsl:when test="(string-length(string($number[1])) != 0) or not($valueIfNull)">
112                                        <xsl:value-of select="$number[1]"/>
113                                </xsl:when>
114                                <xsl:otherwise>
115                                        <xsl:value-of select="$valueIfNull"/>
116                                </xsl:otherwise>
117                        </xsl:choose>
118                </xsl:variable>
119                <xsl:choose>
120                        <xsl:when test="$picture='none'"><xsl:value-of select="$value"/></xsl:when>
121                        <xsl:when test="string(number($value))='NaN'"><xsl:value-of select="$value"/></xsl:when>
122
123                        <!-- put this in because UT had some messed up QM configurations -->
124                        <xsl:when test="count($picture) &gt; 1">
125                                <xsl:message select="'ERROR: _ibis_format.getFormattedValue - TOO MANY XSLT FORMATS.  Picture:'"/> 
126                                <xsl:message select="$picture"/>
127                                <xsl:value-of select="'CONTENT ERROR - TOO MANY XSLT FORMATS - PLEASE CONTACT US!!!'"/>
128                        </xsl:when>
129
130                        <!-- if format string was passed in, then check for the '%' string.
131                                If found then need to replace with a null and add the % to the
132                                end.  See comments about about how XSLT 2.0 does not allow for
133                                literals that match one of the defined format control chars
134                                without effecting formatting.
135
136                                Else if the string doesn't contain the special percent character
137                                suffix signature then simply use as is.
138                        -->
139                        <xsl:when test="string-length($picture) != 0">
140                                <xsl:choose>
141                                        <xsl:when test="contains($picture, $ibis.numberFormatQuotedPercentString)">
142                                                <xsl:value-of select="concat(format-number($value, replace($picture,$ibis.numberFormatQuotedPercentString,''), 'ibis.defaultDecimalNumberFormat'), '%')"/>
143                                        </xsl:when>
144                                        <xsl:otherwise>
145                                                <xsl:value-of select="format-number($value, $picture, 'ibis.defaultDecimalNumberFormat')"/>
146                                        </xsl:otherwise>
147                                </xsl:choose>
148                        </xsl:when>
149
150                        <xsl:otherwise>
151                                <xsl:value-of select="format-number($value, $ibis.defaultNumericPicture, 'ibis.defaultDecimalNumberFormat')"/>
152                        </xsl:otherwise>
153                </xsl:choose>
154        </xsl:function>
155
156
157        <!-- See: http://stackoverflow.com/questions/16892344/convert-a-string-to-date-format-in-xslt -->
158        <xsl:function name="ibis:getFormattedDateTime" as="xs:string" 
159                ibis:doc="Localizes date and time formatting.  Uses the ibis.dateTimeFormatPicture param."
160        >
161                <xsl:param name="dateTime" ibis:doc="DateTime value to be formatted. 
162                        Call with current-dateTime() to get current system date and time."
163                />
164                <xsl:value-of select="format-dateTime($dateTime, $ibis.dateTimeFormatPicture)"/>
165        </xsl:function>
166        <xsl:function name="ibis:getFormattedDate" as="xs:string" 
167                ibis:doc="Localizes date formatting.  Uses the ibis.dateFormatPicture param."
168        >
169                <xsl:param name="date" ibis:doc="Date value to be formatted.  Call with
170                        current-date() to get current system date."
171                />
172                <xsl:value-of select="format-date($date, $ibis.dateFormatPicture)"/>
173        </xsl:function>
174        <xsl:function name="ibis:getFormattedTime" as="xs:string" 
175                ibis:doc="Localizes time formatting.  Uses the ibis.timeFormatPicture param."
176        >
177                <xsl:param name="time" ibis:doc="Time value to be formatted.  Call with
178                        current-time() to get current system time."
179                />
180                <xsl:value-of select="format-time($time, $ibis.timeFormatPicture)"/>
181        </xsl:function>
182
183
184        <xsl:function name="ibis:firstLetterLowerCase" as="xs:string" 
185                ibis:doc="Returns first letter forced to lower case"
186        >
187                        <xsl:param name="text" ibis:doc="Source text to be lowered"/>
188                        <xsl:variable name="firstLetter" select="lower-case(substring(normalize-space($text),1,1))"/>
189                        <xsl:value-of select="concat( lower-case(substring($text,1,1)), substring($text, 2, string-length($text)-1) )"/>
190        </xsl:function>
191
192</xsl:stylesheet>
193
194<!-- ============================= End of File ============================= -->
195
Note: See TracBrowser for help on using the repository browser.