Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

Overview

Returns result of specified template on current node.

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

Arguments

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}}.

Example

Basic template

Code Block
languagejs
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>"

Example

Date formatting

Code Block
languagejs
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>"

Example

Using Variable

Code Block
languagejs
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>