Versions Compared

Key

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

...

Code Block
titleScripting Usage
var result = $Xml.Format('{{
SAMPLE REPORT\
<h1>{{Customer/Name}}</h1>\
<table>\
{{ Rows/Row => <tr><td>{{Date}}</td><td>{{Description}}</td></tr>
 }}\
</table>');

...

}}

Generates the following output:

Code Block
SAMPLE REPORT
<h1>John</h1>
<p>Long
text</p>
<table>
<tr><td>2010-01-01</td><td>description</td></tr>
<tr><td>2015-01-01</td><td>other description</td></tr>
</table>

...

While generating HTML content some tags ( like table tag ) may become corrupted if {{ x => y}} template is used. As an alternative method format function supports the x-repeat attribute to perform repeating content. 

Code Block
var{{ resultSAMPLE = $Xml.Format('SAMPLE REPORT\
<h1>{{Customer/Name}}</h1>\
<table>\REPORT
   <table>
     <tr x-repeat="Rows/Row">\
       <td>{{Date}}</td><td>{{Description}}</td>\
     </tr>\
   </table>'); }}

This attribute can be used with any element. For example can be used with "li" tag also.

Code Block
var{{ result<ul>
= $Xml.Format('\ <ul>\   <li x-repeat="Rows/Row">\
       <span>{{Date}}</span>\
     </li>\
  </ul>'); }}

Recursive Repeating Template

...

For each item at specified in ItemXPath sub template is generated and also same template is repeated again for Template content recursively.

Code Block
var result = $Xml.Format('{{ <h1>SAMPLE REPORT</h1>\
<p>{{DocumentTitle}}</p>\
   {{ Sections/Section =>>>> 
      <h2>{{Name}}</h2><p>h2>
      <p>{{Body}}</p>  }}');

}}

result:

Code Block
<h1>SAMPLE REPORT</h1>
<h2>My Section</h2>
<p>Section content</p>
<h2>Sub Section</h2>
<p>Child section content</p>