Populating a DataTable using an existing data structure

In this example, a node list is selected from the given Xml document, and a given DataTable is populated with nodes relative to the nodes in the selected nodes.

To create a datatable structure, the placeholder macro is used, because of its declarative column syntax.

Smartsite SXML CopyCode image Copy Code
<se:xmlprocessor save="snippet" ><![CDATA[ 
<cars xmlns="uri:cars">
    <car nr="1" brand="Alfa Romeo" type="156" />
    <car nr="2" brand="Rover" type="75" />
    <car nr="3" brand="lexus" type="IS 250" />
    <car nr="4" brand="Mercedes" type="C" />
</cars>
]]></se:xmlprocessor>

<h3>XML Snippet</h3>
<se:viewsource xml="{buffer.get(snippet)}" recurse="true" />
<se:hidden whitespace="remove">
    <se:placeholder localid="xml" render="false">
        <se:parameters>
            <se:parameter name="fieldnames">
                <se:collection>
                    <se:member name="nr" primarykey="true" type="integer" />
                    <se:member name="brand" type="string" />
                    <se:member name="type" type="string" />
                </se:collection>
            </se:parameter>
        </se:parameters>
    </se:placeholder>
    
    <se:xmlprocessor resulttype="none" xml="{buffer.get(snippet)}" >
        <se:parameters>
            <se:parameter name="namespaces">
                <se:collection>
                    <se:member prefix="def" value="uri:cars" />
                </se:collection>
            </se:parameter>
            <se:parameter name="actions">
                <se:collection>
                    <se:member query="//def:car" type="multiplenodes">
                        {this.populatedatatable(scope.xml.data(), 'nr=@nr', 'brand=@brand', 'type=@type' )}
                    </se:member>
                </se:collection>
            </se:parameter>
        </se:parameters>
    </se:xmlprocessor>
</se:hidden>
<se:format inputdata="{scope.xml.data()}">
    <se:rowformat trim="both">
        <dt>{this.field(nr)}</dt><dd class="brand">{this.field(brand)}</dd><dd class="type">{this.field(type)}</dd>{char.crlf()}
    </se:rowformat>
    <se:resultformat whitespace="remove">
        <h3>Translations defined in snippet</h3>
        <dl>{this.result()}</dl>
    </se:resultformat>
</se:format>
Example Result CopyCode image Copy Code
<h3>XML Snippet</h3>
<pre>&lt;cars xmlns="uri:cars"&gt;
    &lt;car nr="1" brand="Alfa Romeo" type="156" /&gt;
    &lt;car nr="2" brand="Rover" type="75" /&gt;
    &lt;car nr="3" brand="lexus" type="IS 250" /&gt;
    &lt;car nr="4" brand="Mercedes" type="C" /&gt;
&lt;/cars&gt;</pre>

<h3>Translationsdefinedinsnippet</h3><dl><dt>1</dt><dd class="brand">Alfa Romeo</dd><dd class="type">156</dd>
<dt>2</dt><dd class="brand">Rover</dd><dd class="type">75</dd>
<dt>3</dt><dd class="brand">lexus</dd><dd class="type">IS 250</dd>
<dt>4</dt><dd class="brand">Mercedes</dd><dd class="type">C</dd>
</dl>