XmlDataTable and Format Example

This example demonstrates the use of XmlDataTable to fill a datatable and the Format macro to render a datatable.

Note that the format macro is a special case where you can use formatting and the resultformat parameter inside the macro itself. This is a convenient way of formatting a datatable after you have modified it using other macros such as Join or Sort.

Smartsite SXML CopyCode image Copy Code
<se:xmldatatable save="inputdatatable" resulttype="datatable">
    <se:row>
        <se:col name="Animal">Tiger</se:col>
        <se:col name="Legs" datatype="integer">4</se:col>
        <se:col name="Diet">carnivore</se:col>
    </se:row>
    <se:row>
        <se:col>Owl</se:col>
        <se:col>2</se:col>
        <se:col>carnivore</se:col>
    </se:row>
    <se:row>
        <se:col>Snake</se:col>
        <se:col>0</se:col>
        <se:col>carnivore</se:col>
    </se:row>
    <se:row>
        <se:col>Rabbit</se:col>
        <se:col>4</se:col>
        <se:col>herbivore</se:col>
    </se:row>
    <se:row>
        <se:col>Bee</se:col>
        <se:col>6</se:col>
        <se:col>herbivore</se:col>
    </se:row>
    <se:row>
        <se:col>Human</se:col>
        <se:col>2</se:col>
        <se:col>omnivore</se:col>
    </se:row>
    <se:row>
        <se:col>Bear</se:col>
        <se:col>4</se:col>
        <se:col>omnivore</se:col>
    </se:row>
</se:xmldatatable>

<se:format inputdata="inputdatatable" rem="render datatable in an html table">
    <se:rowformat>
        <se:colformat><td>{this.field()}</td></se:colformat>
        <se:rowresult>{char.tab()}<tr>{this.rowresult()}</tr>{char.crlf()}</se:rowresult>
    </se:rowformat>

    <se:captionformat match="first">
        <se:colformat><th>{this.colname()}</th></se:colformat>
        <se:rowresult>{char.tab()}<tr>{this.rowresult()}</tr>{char.crlf()}</se:rowresult>
    </se:captionformat>

    <se:resultformat><table>{char.crlf()}{this.result()}</table></se:resultformat>
</se:format>
Example Result CopyCode image Copy Code
<table>
    <tr><th>Animal</th><th>Legs</th><th>Diet</th></tr>
    <tr><td>Tiger</td><td>4</td><td>carnivore</td></tr>
    <tr><td>Owl</td><td>2</td><td>carnivore</td></tr>
    <tr><td>Snake</td><td>0</td><td>carnivore</td></tr>
    <tr><td>Rabbit</td><td>4</td><td>herbivore</td></tr>
    <tr><td>Bee</td><td>6</td><td>herbivore</td></tr>
    <tr><td>Human</td><td>2</td><td>omnivore</td></tr>
    <tr><td>Bear</td><td>4</td><td>omnivore</td></tr>
</table>