untitled

(ff) #1

268 11 The XML Transformation Language


...
<xsl:template match="Protein">
<P>
<xsl:attribute name="averageBindingStrength">
<xsl:value-of
select="sum(interaction/BindingStrength) div
count(interaction/BindingStrength)"/>
</xsl:attribute>
<xsl:apply-templates select="@*|node()"/>
</P>
</xsl:template>
..

Transform 11.4 A modification of the program in transform 11.1 to compute the av-
erage binding strength of all interactions with a protein. The average binding strength
is shown as another attribute in eachPelement.

programming languages such as Perl, but XSLT adds a new feature to com-
putation:navigation.
Navigation is the process of conducting vehicles from one place to another.
The original meaning was concerned with ships on the sea. Nowadays it is
more commonly applied to the directions for driving a car from one place to
another. In the case of XML documents, one navigates from one element to
another. Instead of streets one navigates over elements, and instead of turn-
ing from one street to another, one traverses either “down” from an element
to a child element, or “up” from an element to its parent element.
The template in transform 11.4 shows how to perform both navigation and
computation. The objective is to compute the average binding strength of all
interactions of a protein. Thevalue-ofcommand evaluates the expression
in itsselectattribute. Theinteraction/BindingStrengthpart of this
expression is the navigation using XPath as in section 8.1. It specifies that one
should select allinteractionelements in the context and then select all
BindingStrengthelements within theinteractionelements. The slash
means that one navigates from a parent element to a child element. This
notation emulates the notation used for navigating among directories and
files (except that in Windows, a backward slash is used instead of a forward
slash).
Anattributecommand inserts an attribute into the current element (in
this case aPelement). Thesumis the numerical sum of all matching el-
ements, and thecountis the number of all matching elements. Thediv
Free download pdf