Skip to content

Format

Returns result of specified template on current node.

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

Parameters

string template
    Template to apply.

object options
    Template options. Can be null. Option contains the parameters to be used in template or following properties:

Remarks

Like XSLT formatting this method provides much simpler template usage for converting XML data to HTML or any other data.
Template may contain xpath expressions or variables that wrapped in {{ and }} characters. All formatting done with invariant culture if not specified in options. Please refer the Data+Templates section for more information.
Custom variables can be used in template content as {{$VariableName}} format. If variable is an object; formatting string can be used 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 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