389
<xsl:template match="gene">
<xsl:copy>
<xsl:attribute name="locus">
<xsl:value-of select="../@name"/>
</xsl:attribute>
<xsl:apply-templates select="@*|node()"/>
</xsl:copy>
</xsl:template>
This template applies only togeneelements. All other elements are copied
exactly. Forgeneelements, the element itself is copied, then a new attribute
is added namedlocus, having a value equal to thenameattribute of its
ANSWER TO parent element.
EXERCISE11.2
<xsl:template match="locus">
<xsl:apply-templates select="gene"/>
</xsl:template>
<xsl:template match="gene">
<xsl:copy>
<xsl:apply-templates select="@*|node()"/>
<xsl:apply-templates select="../reference"/>
</xsl:copy>
</xsl:template>
The first template removes thelocuselement, along with all of its child
elements, except for thegeneelement. The second template copies allgene
elements and adds thereferenceelements that were removed by the first
ANSWER TO template.
EXERCISE11.3
<xsl:template match="organism">
<organism>
<xsl:apply-templates select="@*"/>
<contains>
<xsl:apply-templates select="node()"/>
</contains>
</organism>
</xsl:template>