<?xml version="1.0"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:html="http://www.w3.org/1999/xhtml"
xmlns:xlink="http://www.w3.org/1999/xlink"
version="1.0"
>
<xsl:output doctype-system="cexml_message.dtd"
indent="yes"
/>
<!-- The purpose of this XSLT stylesheet is to propagate the of a
builtobject to all his children. This is by having every element
copy the characteristics of his parents. The copied characteristics,
quantification and function) are marked by setting attribute
copied="yes". -->
<xsl:template match="/">
<xsl:apply-templates select="cexml"/>
</xsl:template>
<xsl:template match="cexml">
<xsl:element name="cexml">
<xsl:apply-templates select="builtobject" />
<xsl:apply-templates select="quantification" />
<xsl:apply-templates select="function" />
<xsl:apply-templates select="unit" />
</xsl:element>
</xsl:template>
<xsl:template match="builtobject">
<xsl:element name="builtobject">
<xsl:call-template name="copy-attributes"/>
<xsl:apply-templates select="name" />
<xsl:apply-templates select="characteristics" />
<xsl:apply-templates select="builtobject" />
</xsl:element>
</xsl:template>
<xsl:template match="characteristics">
<xsl:element name="characteristics">
<xsl:call-template name="copy-attributes"/>
<xsl:apply-templates select="builtobject" />
<xsl:apply-templates select="amount" />
<xsl:apply-templates select="quantification" />
<xsl:if test='../@mode!="search"'>
<!-- add all ancestor's quantifications here -->
<xsl:apply-templates
select="ancestor::builtobject/ancestor::builtobject/child::characteristics/child::quantification"
mode="propagate"/>
</xsl:if>
<!-- continue normally with the functions -->
<xsl:apply-templates select="function" />
<xsl:if test='../@mode!="search"'>
<!-- add all ancestor's functions here -->
<xsl:apply-templates
select="ancestor::builtobject/ancestor::builtobject/child::characteristics/child::function"
mode="propagate" />
</xsl:if>
</xsl:element>
</xsl:template>
<xsl:template match="name">
<xsl:element name="name">
<xsl:call-template name="copy-attributes"/>
<xsl:value-of select="."/>
</xsl:element>
</xsl:template>
<xsl:template match="amount">
<xsl:element name="amount">
<xsl:value-of select="."/>
</xsl:element>
</xsl:template>
<xsl:template match="quantification">
<xsl:element name="quantification">
<xsl:call-template name="copy-attributes"/>
<xsl:apply-templates select="name" />
<xsl:apply-templates select="amount" />
<xsl:apply-templates select="unit" />
</xsl:element>
</xsl:template>
<xsl:template match="function">
<xsl:element name="function">
<xsl:call-template name="copy-attributes"/>
<xsl:apply-templates select="name" />
<xsl:apply-templates select="quantification" />
</xsl:element>
</xsl:template>
<xsl:template match="unit">
<xsl:element name="unit">
<xsl:call-template name="copy-attributes"/>
<xsl:apply-templates select="name" />
</xsl:element>
</xsl:template>
<xsl:template name="copy-attributes">
<xsl:for-each select="@*">
<xsl:copy />
</xsl:for-each>
</xsl:template>
<!-- TEMPLATES SPECIFIC TO THIS STYLESHEET BELOW THIS LINE -->
<xsl:template match="quantification" mode="propagate">
<xsl:element name="quantification">
<xsl:call-template name="copy-attributes"/>
<xsl:attribute name="copied">yes</xsl:attribute>
<xsl:apply-templates select="name" />
<xsl:apply-templates select="amount" />
</xsl:element>
</xsl:template>
<xsl:template match="function" mode="propagate">
<xsl:element name="function">
<xsl:call-template name="copy-attributes"/>
<xsl:attribute name="copied">yes</xsl:attribute>
<xsl:apply-templates select="name" />
</xsl:element>
</xsl:template>
</xsl:stylesheet>
|