Creating templates that perform a subset of the script code is useful for code modularization and self-documentation. Additionally, there are many times when the calling template can process a desired result from the called named template. In this scenario, the called template is designed to perform a specific operation and then return the result. Named templates (unlike functions in other languages) do not have a direct mechanism for returning values; however, they are able to write to the result tree, and it is possible to redirect the result tree to a variable. Doing this allows called templates to effectively return a string value to the calling template by writing to the result tree. The calling template then redirects the result tree output into a variable. Example to the right shows how to do this.

version 1.0;

ns junos = "*/junos";
ns xnm = "";
ns jcs = "";

import "../import/junos.xsl";

match / {
    <op-script-results> {
        /* get-day-of-week returns the day – assign it to $day-of-week */
        var $day-of-week = { call get-day-of-week(); }
        /* Output day string to the console */
        <output> $day-of-week;

/* Extract the day of week string from the $localtime global parameter */
template get-day-of-week {
    /* Write the first three characters of the $localtime to the result tree */
    expr substring( $localtime, 1, 3 );