The string-format() function

Smartsite 7.2 - ...

The string-format() extension function replaces the format item(s) in a specified string with the string representation of the specified object(s).

XML CopyCode image Copy Code
string exf:string-format(arg1, arg2, ...)

Parameters:

  • arg1: a node reference or string literal.
  • arg2, ... : one or more arguments (format item(s)), each of them a node reference or a string literal  

Example

XML CopyCode image Copy Code
<html xmlns="http://www.w3.org/1999/xhtml" 
   xmlns:xf="http://www.w3.org/2002/xforms" 
   xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
   xmlns:xsd="http://www.w3.org/2001/XMLSchema" 
   xmlns:ev="http://www.w3.org/2001/xml-events" 
   xmlns:a="http://smartsite.nl/namespaces/xforms-instance" 
   xmlns:exf="http://smartsite.nl/namespaces/xforms/1.0" 
   xmlns:cst="http://smartsite.nl/customtypes"> 
<head>
 <title>Address Form</title>
 <xf:model>
   <xf:instance>
     <a:data>
       <a:number>1234.5789</a:number>
       <a:number2 xsi:type="xsd:double">98765.4321</a:number2>
       <a:postcode>2628 XG</a:postcode>
       <a:text1>Tekst 1</a:text1>
       <a:text2>Tekst 2</a:text2>
       <a:text3>Tekst 3</a:text3>
       <a:stringformat lang="en">Formatted number: {0:#,##0.000}</a:stringformat>
       <a:stringformat lang="nl">Geformatteerd nummer: {0:#,##0.000}</a:stringformat>
       <a:amountuntyped>120.49</a:amountuntyped>
       <a:amount xsi:type="xsd:double">120.49</a:amount>
       <a:amount2>153.42</a:amount2>
       <a:date xsi:type="xsd:dateTime">2014-04-30T10:34:00.000</a:date>
     </a:data>
   </xf:instance>
   <xf:submission id="save" method="post" action="/" replace="all" serialization="application/xml">
   </xf:submission>
   <xf:bind nodeset="a:amount2" type="xsd:double" />
 </xf:model>
</head>
<body>
 <xf:group ref="/a:data" appearance="full">
   <xf:label /> 
   <xf:group xml:lang="en-US">
     <xf:label>String-format examples (en-US)</xf:label>
     <em>Literals</em>
     <xf:output value="exf:string-format('Formatted number (custom): {0:#,##0}', 1234.56789)" />
     <xf:output value="exf:string-format('Formatted number (custom): {0:#,##0.0}', 1234.56789)" />
     <xf:output value="exf:string-format('Formatted number (custom): {0:#,##0.00}', 1234.56789)" />
     <xf:output value="exf:string-format('Formatted number (custom): {0:#,##0.000}', 1234.56789)" />
     <xf:output value="exf:string-format('Formatted number (custom): {0:#,##0.0000}', 1234.56789)" />
     <xf:output value="exf:string-format('Formatted number (E): {0:E}', 1234.56789)" />
     <xf:output value="exf:string-format('Formatted number (N): {0:N}', 1234.56789)" />
     <xf:output value="exf:string-format('Formatted number (P): {0:P}', 0.32)" />
     <br />
     <em>Nodes</em>
     <xf:output value="exf:string-format('Zip code: {0}', a:postcode)" />    
     <xf:output value="exf:string-format('Multiple arguments: {0}-{1}-{2}', 1, 2, 3)" />
     <xf:output value="exf:string-format('Multiple arguments: {0}, {1}, {2}', a:text1, a:text2, a:text3)" />
     <xf:output value="exf:string-format('Formatted number (custom): {0:#,##0}', number(a:number))" />
     <xf:output value="exf:string-format('Formatted number (custom): {0:#,##0}', a:number2)" />
     <xf:output value="exf:string-format(string(a:stringformat[@lang='en']), number(a:number))" />
     <xf:output value="exf:string-format('Formatted number (E): {0:E}', number(a:number))" />
     <xf:output value="exf:string-format('Formatted number (E): {0:E}', a:number2)" />
     <xf:output value="exf:string-format('Amount (C): {0:C}', number(a:amountuntyped))" />
     <xf:output value="exf:string-format('Amount (C): {0:C}', a:amount)" />
     <xf:output value="exf:string-format('Amount (C): {0:C}', a:amount2)" />
     <br />
     <em>Date/time</em>
     <xf:output value="exf:string-format('Short date pattern (d): {0:d}', a:date)" />
     <xf:output value="exf:string-format('Long date pattern (D): {0:D}', a:date)" />
     <xf:output value="exf:string-format('Full date/time pattern (short time) (f): {0:f}', a:date)" />
     <xf:output value="exf:string-format('Full date/time pattern (long time)(F): {0:F}', a:date)" />
     <xf:output value="exf:string-format('General date/time pattern (short time) (g): {0:g}', a:date)" />
     <xf:output value="exf:string-format('General date/time pattern (long time) (G): {0:G}', a:date)" />
     <xf:output value="exf:string-format('Month/day pattern (M): {0:M}', a:date)" />
     <xf:output value="exf:string-format('Year pattern (Y): {0:Y}', a:date)" />
     <xf:output value="exf:string-format('RFC1123 pattern (R): {0:R}', a:date)" />
     <xf:output value="exf:string-format('Short time pattern (t): {0:t}', a:date)" />
     <xf:output value="exf:string-format('Long time pattern (T): {0:T}', a:date)" />
     <xf:output value="exf:string-format('Universal sortable date/time pattern (u): {0:u}', a:date)" />
     <xf:output value="exf:string-format('Universal full date/time pattern (U): {0:U}', a:date)" />
   </xf:group> 
   <br /> 
   <xf:group xml:lang="nl-nl">
     <xf:label>String-format examples (nl-nl)</xf:label>
     <em>Literals</em> 
     <xf:output value="exf:string-format('Geformatteerd nummer (custom): {0:#,##0}', 1234.56789)" />
     <xf:output value="exf:string-format('Geformatteerd nummer (custom): {0:#,##0.0}', 1234.56789)" />
     <xf:output value="exf:string-format('Geformatteerd nummer (custom): {0:#,##0.00}', 1234.56789)" />
     <xf:output value="exf:string-format('Geformatteerd nummer (custom): {0:#,##0.000}', 1234.56789)" />
     <xf:output value="exf:string-format('Geformatteerd nummer (custom): {0:#,##0.0000}', 1234.56789)" />
     <xf:output value="exf:string-format('Geformatteerd nummer (E): {0:E}', 1234.56789)" />
     <xf:output value="exf:string-format('Geformatteerd nummer (N): {0:N}', 1234.56789)" />
     <xf:output value="exf:string-format('Geformatteerd nummer (P): {0:P}', 0.32)" />
     <br />
     <em>Nodes</em>
     <xf:output value="exf:string-format('Postcode: {0}', a:postcode)" />
     <xf:output value="exf:string-format('Meerdere argumenten: {0}-{1}-{2}', 1, 2, 3)" />
     <xf:output value="exf:string-format('Meerdere argumenten: {0}, {1}, {2}', a:text1, a:text2, a:text3)" />
     <xf:output value="exf:string-format('Geformatteerd nummer (custom): {0:#,##0}', number(a:number))" />
     <xf:output value="exf:string-format('Geformatteerd nummer (custom): {0:#,##0}', a:number2)" />
     <xf:output value="exf:string-format(string(a:stringformat[@lang='nl']), number(a:number))" />\
     <xf:output value="exf:string-format('Geformatteerd nummer (E): {0:E}', number(a:number))" />
     <xf:output value="exf:string-format('Geformatteerd nummer (E): {0:E}', a:number2)" />
     <br />
     <em>Date/time</em>
     <xf:output value="exf:string-format('Short date pattern (d): {0:d}', a:date)" />
     <xf:output value="exf:string-format('Long date pattern (D): {0:D}', a:date)" />
     <xf:output value="exf:string-format('Full date/time pattern (short time) (f): {0:f}', a:date)" />
     <xf:output value="exf:string-format('Full date/time pattern (long time) (F): {0:F}', a:date)" />
     <xf:output value="exf:string-format('General date/time pattern (short time) (g): {0:g}', a:date)" />
     <xf:output value="exf:string-format('General date/time pattern (long time) (G): {0:G}', a:date)" />
     <xf:output value="exf:string-format('Month/day pattern (M): {0:M}', a:date)" />
     <xf:output value="exf:string-format('Year pattern (Y): {0:Y}', a:date)" />
     <xf:output value="exf:string-format('RFC1123 pattern (R): {0:R}', a:date)" />
     <xf:output value="exf:string-format('Short time pattern (t): {0:t}', a:date)" />
     <xf:output value="exf:string-format('Long time pattern (T): {0:T}', a:date)" />
     <xf:output value="exf:string-format('Universal sortable date/time pattern (u): {0:u}', a:date)" />
     <xf:output value="exf:string-format('Universal full date/time pattern (U): {0:U}', a:date)" />
   </xf:group>
 </xf:group>
</body>
</html>

The result will be:

String-format examples (en-US)
Literals
Formatted number (custom): 1,235
Formatted number (custom): 1,234.6
Formatted number (custom): 1,234.57
Formatted number (custom): 1,234.568
Formatted number (custom): 1,234.5679
Formatted number (E): 1.234568E+003
Formatted number (N): 1,234.57
Formatted number (P): 32.00 %

Nodes
Zip code: 2628 XG
Multiple arguments: 1-2-3
Multiple arguments: Tekst 1, Tekst 2, Tekst 3
Formatted number (custom): 1,235
Formatted number (custom): 98,765
Formatted number: 1,234.579
Formatted number (E): 1.234579E+003
Formatted number (E): 9.876543E+004
Amount (C): $120.49
Amount (C): $120.49
Amount (C): $153.42

Date/time
Short date pattern (d): 4/30/2014
Long date pattern (D): Wednesday, April 30, 2014
Full date/time pattern (short time) (f): Wednesday, April 30, 2014 10:34 AM
Full date/time pattern (long time)(F): Wednesday, April 30, 2014 10:34:00 AM
General date/time pattern (short time) (g): 4/30/2014 10:34 AM
General date/time pattern (long time) (G): 4/30/2014 10:34:00 AM
Month/day pattern (M): April 30
Year pattern (Y): April 2014
RFC1123 pattern (R): Wed, 30 Apr 2014 10:34:00 GMT
Short time pattern (t): 10:34 AM
Long time pattern (T): 10:34:00 AM
Universal sortable date/time pattern (u): 2014-04-30 10:34:00Z
Universal full date/time pattern (U): Wednesday, April 30, 2014 8:34:00 AM

String-format examples (nl-nl)
Literals
Geformatteerd nummer (custom): 1.235
Geformatteerd nummer (custom): 1.234,6
Geformatteerd nummer (custom): 1.234,57
Geformatteerd nummer (custom): 1.234,568
Geformatteerd nummer (custom): 1.234,5679
Geformatteerd nummer (E): 1,234568E+003
Geformatteerd nummer (N): 1.234,57
Geformatteerd nummer (P): 32,00 %

Nodes
Postcode: 2628 XG
Meerdere argumenten: 1-2-3
Meerdere argumenten: Tekst 1, Tekst 2, Tekst 3
Geformatteerd nummer (custom): 1.235
Geformatteerd nummer (custom): 98.765
Geformatteerd nummer: 1.234,579
Geformatteerd nummer (E): 1,234579E+003
Geformatteerd nummer (E): 9,876543E+004

Date/time
Short date pattern (d): 30-4-2014
Long date pattern (D): woensdag 30 april 2014
Full date/time pattern (short time) (f): woensdag 30 april 2014 10:34
Full date/time pattern (long time) (F): woensdag 30 april 2014 10:34:00
General date/time pattern (short time) (g): 30-4-2014 10:34
General date/time pattern (long time) (G): 30-4-2014 10:34:00
Month/day pattern (M): 30 april
Year pattern (Y): april 2014
RFC1123 pattern (R): Wed, 30 Apr 2014 10:34:00 GMT
Short time pattern (t): 10:34
Long time pattern (T): 10:34:00
Universal sortable date/time pattern (u): 2014-04-30 10:34:00Z
Universal full date/time pattern (U): woensdag 30 april 2014 08:34:00

Namespace

This function is available within the Smartsite XForms namespace (http://smartsite.nl/namespaces/xforms/1.0).