XmlProcessor action with condition Example

In this example, a conditional action is declared in the XmlProcessor macro.

If the querystring variable 'scale' starts with 'F' (fahrenheit), the Google Weather API xml will be queried for the fahrenheit temperature node, otherwise for the celsius node.

Smartsite SXML CopyCode image Copy Code
{buffer.set(fa, string.startswith(request.query(scale, default='C'), 'F'))}
<se:xmlprocessor>
    <se:parameters>
        <se:parameter name="xml" trim="both">
            <se:cache maxage="00:20" trim="both" keydependencies="|loc={request.query(loc)}|">
                <se:embeduri location="{url.setparameter('http://www.google.com/ig/api', 
                    weather, request.query(loc, 
                    default='Delft, The Netherlands'))}" 
                    resulttype="xml"
                />
            </se:cache>
        </se:parameter>
        <se:parameter name="actions">
            <se:collection>
                <se:member condition="! $fa" query="//temp_c/@data">
                    {this.setresult(this.getvalue())}
                </se:member>
                <se:member condition="$fa" query="//temp_f/@data">
                    {this.setresult(this.getvalue())}
                </se:member>
            </se:collection>
        </se:parameter>
        <se:parameter name="resultformat" trim="both">
            {this.result()}&deg;
        </se:parameter>
    </se:parameters>
</se:xmlprocessor>
Example Result CopyCode image Copy Code
13&deg;