untitled

(ff) #1
11.7 Procedural Programming 275

Summary



  • XSLT can process multiple input source files by using XML entities to in-
    clude one file in another.

  • Alternatively, XSLT can process multiple files by using thedocument
    function.


11.7 Procedural Programming


Although XSLT is a rule-based language, one can also program in XSLT us-
ing the traditional procedural style. In particular, this means that one can
declare and use variables and procedures, and one can pass parameters to
procedures.
A variable is declared using thexsl:variablecommand. For example,

<xsl:variable name="x" select="BindingStrength[1]"/>

will set the variablexto the firstbinding_strengthelement in the current
context. This command has approximately the same meaning as

$x = $BindingStrength[0];

in Perl. Note that XSLT starts counting at 1 while Perl normally starts count-
ing at 0.
An XSLT variable is used (evaluated) by writing the$character before
the variable name. This convention is almost the same as in Perl, except
that Perl variables are not declared so they always appear with a preceding
character such as$. Another difference is that Perl distinguishes between
variables that represent collections of values from variables that represent
single values (called “scalars” in Perl). XSLT makes no such distinction.
Procedures in XSLT are just templates that have a name. They are called
by using thexsl:call-templatecommand. The following template com-
putes the average of allbinding_strengthelements in the current con-
text:

<xsl:template name="BindingStrengthAverage">
<xsl:value-of select="sum(BindingStrength) div
count(BindingStrength)"/>
</xsl:template>
Free download pdf