Vamos a ver como dar formato de una fecha especifica. En esta ocasión vamos a usar una transformación sencilla donde mapeamos un elemento de tipo cadena a otra variable con el formato solicitado.
Veamos la siguiente ejemplo:
01 | < xsl:stylesheet exclude-result-prefixes = "xsi xsl client ns1 plnk xsd wsdl bpws xp20 mhdr bpel oraext dvm hwf med ids bpm xdk xref ora socket ldap" version = "1.0" > |
02 | < xsl:template match = "/" > |
03 | < ns1:output > |
04 | < ns1:datesample > |
05 | < xsl:call-template name = "formatDateTime" > |
06 | < xsl:with-param name = "sampleDateTime" select = "/client:process/client:input" > |
07 | </ xsl:with-param ></ xsl:call-template > |
08 | </ ns1:datesample > |
09 | </ ns1:output > |
10 | </ xsl:template > <!-- User Defined Templates --> |
11 | < xsl:template name = "formatDateTime" > |
12 | < xsl:param name = "sampleDateTime" ></ xsl:param > |
13 | < xsl:value-of select = "substring($sampleDateTime,1,4)" > |
14 | < xsl:text >-</ xsl:text > |
15 | < xsl:value-of select = "substring($sampleDateTime,5,2)" > |
16 | < xsl:text >-</ xsl:text > |
17 | < xsl:value-of select = "substring($sampleDateTime,7,2)" > |
18 | < xsl:text >T</ xsl:text > |
19 | < xsl:value-of select = "substring($sampleDateTime,9,2)" > |
20 | < xsl:text >:</ xsl:text > |
21 | < xsl:value-of select = "substring($sampleDateTime,11,2)" > |
22 | < xsl:text >:</ xsl:text > |
23 | < xsl:value-of select = "substring($sampleDateTime,13,2)" > |
24 | < xsl:text ></ xsl:text > |
25 | </ xsl:value-of ></ xsl:value-of ></ xsl:value-of ></ xsl:value-of ></ xsl:value-of ></ xsl:value-of ></ xsl:template ></ xsl:stylesheet > |
Vamos a dar formato procesando una cadena con la función "substring". En este escenario esperamos dar formato a una cadena de caracteres cualquiera ej. 20060101000000. Definimos el siguiente template para parsear la cadena según el valor que vamos a leer y preparamos el formato que deseamos.
01 | < xsl:template name = "formatDateTime" > |
02 | < xsl:param name = "sampleDateTime" ></ xsl:param > |
03 | < xsl:value-of select = "substring($sampleDateTime,1,4)" > |
04 | < xsl:text >-</ xsl:text > |
05 | < xsl:value-of select = "substring($sampleDateTime,5,2)" > |
06 | < xsl:text >-</ xsl:text > |
07 | < xsl:value-of select = "substring($sampleDateTime,7,2)" > |
08 | < xsl:text >T</ xsl:text > |
09 | < xsl:value-of select = "substring($sampleDateTime,9,2)" > |
10 | < xsl:text >:</ xsl:text > |
11 | < xsl:value-of select = "substring($sampleDateTime,11,2)" > |
12 | < xsl:text >:</ xsl:text > |
13 | < xsl:value-of select = "substring($sampleDateTime,13,2)" > |
14 | < xsl:text ></ xsl:text > |
15 | </ xsl:value-of ></ xsl:value-of ></ xsl:value-of ></ xsl:value-of ></ xsl:value-of ></ xsl:value-of ></ xsl:template > |
Y finalmente añadimos el llamado al template dentro del mapeo de nuestra variable que queremos formatear:
1 | < ns1:output > |
2 | < ns1:datesample > |
3 | < xsl:call-template name = "formatDateTime" > |
4 | < xsl:with-param name = "sampleDateTime" select = "/client:process/client:input" > |
5 | </ xsl:with-param ></ xsl:call-template > |
6 | </ ns1:datesample > |
7 | </ ns1:output > |
Ahora realizamos un "Test" en JDeveloper.
gl hf ;)
No comments:
Post a Comment