Appendix E. XSL/T listings

Table of Contents
language-.xslt
propagate.xslt
rejoin.xslt
search.xslt
print_answer.xslt

language-.xslt

<?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"
	      method="xml"
	      />
  <!-- This default declaration is needed immediately at the top,
  otherwise the xslt sheet won't even know this variable exists. The
  true value is passed to this xslt sheet on the command line -->
  <xsl:param name="selectedlanguage" select="'default value'"/>

  <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:apply-templates select="function" />
    </xsl:element>
  </xsl:template>

  <xsl:template match="name">
    <!-- If a "name" tag is found, remove it, unless it is in the
    desired language OR in the language "si", indicating an S.I. unit
    --> 
    <xsl:if test="@language=$selectedlanguage or @language='si'">
      <xsl:element name="name">
	<xsl:call-template name="copy-attributes"/>
	<xsl:value-of select="."/>
      </xsl:element>
    </xsl:if>
  </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>
    
</xsl:stylesheet>