Datasheet

Relationships between elements: The root node has only children. All other nodes have one
parent node, as well as zero or more child nodes. Nodes can have elements that are related on
the same hierarchical level. In the code example that follows, the following apply:
The root node element is called <root>.
The root node has two child node elements: <branch_1> and <branch_2>.
The node <branch_1> has one child element called <leaf_1_1>.
The node <branch_2> has three child elements called <leaf_2_1>, <leaf_2_2>, and
<leaf_2_3>.
The nodes <leaf_2_1>, <leaf_2_2>, and <leaf_2_3> are all siblings, having the
same parent node element in common (node
<branch_2>):
<root>
<branch_1>
<leaf_1_1>
</leaf_1_1>
</branch_1>
<branch_2 name=”branch two”>
<leaf_2_1>
</leaf_2_1>
<leaf_2_2>
</leaf_2_2>
<leaf_2_3>This is a leaf</leaf_2_3>
</branch_2>
</root>
The content of elements: XML elements can have simple content (text only), attributes for the
element concerned, and can contain other child elements. Node
<branch_2> in the preceding
example has an attribute called name (with a value of
branch two). The node <leaf_1> contains
nothing. The node
<leaf_2_3> contains the text string This is a leaf.
Extensible elements: XML documents can be altered without necessarily altering what is deliv-
ered by an application. Examine Figure 1-7. The following is the XSL code used to apply the
reduced template for get the result shown in Figure 1-7:
<xsl:template>
<xsl:apply-templates select=”@*”/>
<xsl:if test=”@name[.=’Africa’]”><HR/></xsl:if>
<xsl:if test=”@name[.=’Asia’]”><HR/></xsl:if>
<xsl:if test=”@name[.=’Europe’]”><HR/></xsl:if>
<xsl:if test=”@name[.=’Latin America and the Caribbean’]”><HR/></xsl:if>
<xsl:if test=”@name[.=’North America’]”><HR/></xsl:if>
<xsl:if test=”@name[.=’Oceania’]”><HR/></xsl:if>
<xsl:value-of select=”@name”/>
<xsl:apply-templates/>
</xsl:template>
</xsl:stylesheet>
Looking at the preceding XSL script, yes, we have not as yet covered anything about eXtensible
Style Sheets (XSL). The point to note is that the boldface text in the preceding code finds only
the name attribute values, from all elements, ignoring everything else. Therefore all population
18
Chapter 1
04_791202 ch01.qxp 10/6/06 10:59 AM Page 18