Skip to content

Format

Applies the specified template to the current node and returns the resulting string.

1
myXml.Format(template: string, options: object):string

Parameters

string template
    Template to apply.

object options
    Optional template options. This can include parameters to be used in the template, or specific formatting options.

Returns

The result of applying the template to the current node.

Remarks

Similar to XSLT formatting, this method provides a simpler way to transform XML data into HTML or other formats using templates.
The template may contain XPath expressions or variables enclosed in {{ and }} characters. All formatting is done using the invariant culture unless otherwise specified in the options. Please refer to the Data+Templates section for more information.
Custom variables can be used in the template content using the {{$VariableName}} format. If a variable is an object, a formatting string can be used to access properties, such as {{$VariableName.Property}}.

Basic template:

1
2
3
var myNode = $Xml.Parse("<Customer><Name>John</Name></Customer");
var result = myNode.Format('<p>Hello {{Customer/Name}}!</p>');
// result now contains "<p>Hello John!</p>"

Date formatting:

1
2
3
var myNode = $Xml.Parse("<Customer><Name>John</Name><BirthDate>2014-01-31T09:00:00+02:00</BirthDate></Customer");
var result = myNode.Format('<p>Birth date : {{Customer/BirthDate}}</p>');
// result now contains "<p>Birth date : 01/31/2014 09:00:00 +02:00</p>"

Using a variable:

1
2
3
4
5
var myNode = $Xml.Parse("<Customer><Name>John</Name><BirthDate>2014-01-31T09:00:00+02:00</BirthDate></Customer");
var result = myNode.Format('<p>{{$MyVariable}}</p>', {
  MyVariable : 'Custom Variable'
});
// result: <p>Custom Variable</p>

See Also