<xsl:stylesheet
  xmlns:math="http://www.w3.org/1998/Math/MathML"
  xmlns:mdf="http://www.mathdox.org/MathDox/Functions"
  xmlns:om="http://www.openmath.org/OpenMath"
  xmlns:xs="http://www.w3.org/2001/XMLSchema"
  xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  version="2.0"
>

  <xsl:include href="functions.xsl"/>

  <xsl:template match='om:OMV|OMV' mode='short'>
    <xsl:apply-templates select='.' mode='#default'/>
  </xsl:template>

  <!--
    This file contains the CDs: (in alphabetical order)
    - plangeo1b version 0 (needs checking)
    - plangeo1c version 0 (needs checking)
    - plangeo7  version 2007-07-10 (needs checking)
    - plangeo8  version 2007-07-10 (needs checking)
    
    In these CDs all symbols are present in alphabetical order.
  -->

  <!--
    plangeo1b 
    - line
    - point
  -->

  <!--
    plangeo1b.line
  -->
  <xsl:template match='OMA[OMS[@cd="plangeo1b" and @name="line"]]|
    om:OMA[om:OMS[@cd="plangeo1b" and @name="line"]]'
  >
    <math:mrow>
      <math:mtext>
        <xsl:text>the line</xsl:text>
      </math:mtext>
      <xsl:if test='*[2]'>
        <!-- U+00A0 non breakable space -->
        <math:mtext>
          <xsl:text>, such that&#xA0;</xsl:text>
        </math:mtext>
        <xsl:copy-of select='mdf:makelist(*[position() &gt; 1])'/>
      </xsl:if>
    </math:mrow>
  </xsl:template>

  <!--
    plangeo1b.point
  -->
  <xsl:template match='OMA[OMS[@cd="plangeo1b" and @name="point"]]|
    om:OMA[om:OMS[@cd="plangeo1b" and @name="point"]]'
  >
    <math:mrow>
      <math:mtext>
        <xsl:text>the point</xsl:text>
      </math:mtext>
      <xsl:if test='*[2]'>
        <!-- U+00A0 non breakable space -->
        <math:mtext>
          <xsl:text>, such that&#xA0;</xsl:text>
        </math:mtext>
        <xsl:copy-of select='mdf:makelist(*[position() &gt; 1])'/>
      </xsl:if>
    </math:mrow>
  </xsl:template>

  <!--
    plangeo1c 
    - line
    - points
  -->

  <!--
    plangeo1c.line
  -->
  <xsl:template match='OMA[OMS[@cd="plangeo1c" and @name="line"]]|
    om:OMA[om:OMS[@cd="plangeo1c" and @name="line"]]'
  >
    <math:mrow>
      <math:mtext>
        <!-- U+00A0 non breakable space -->
        <xsl:text>line&#xA0;</xsl:text>
      </math:mtext>
      <xsl:apply-templates select='*[2]'/>
      <xsl:apply-templates select='*[3]'/>
    </math:mrow>
  </xsl:template>

  <!--
    plangeo1.points
  -->
  <xsl:template match='OMA[OMS[@cd="plangeo1c" and @name="points"]]|
    om:OMA[om:OMS[@cd="plangeo1c" and @name="points"]]'
  >
    <math:mrow>
      <math:mtext>
        <!-- U+00A0 non breakable space -->
        <xsl:text>the points&#xA0;</xsl:text>
      </math:mtext>
      <xsl:copy-of select='mdf:makelist(*[position() &gt; 1])'/>
    </math:mrow>
  </xsl:template>

  <!--
    plangeo7 
    - altitude
    - altitude_foot
    - area
    - bisector
    - circumcenter
    - corner
    - incenter
    - intersection
    - is_cevian
    - is_vertex
    - length
    - median
    - opposite_side
    - orthocenter
    - perpbisector
    - perpendicular_foot
    - polygon
    - side
    - triangle
    - vertices
  -->

  <!--
    plangeo7.altitude
  -->
  <xsl:template match='OMA[OMS[@cd="plangeo7" and @name="altitude"]]|
    om:OMA[om:OMS[@cd="plangeo7" and @name="altitude"]]'
  >
    <math:mrow>
      <math:mtext>
        <!-- U+00A0 non breakable space -->
        <xsl:text>the altitude of&#xA0;</xsl:text>
      </math:mtext>
      <xsl:apply-templates select='*[2]'/>
      <math:mtext>
        <!-- U+00A0 non breakable space -->
        <xsl:text>&#xA0;through&#xA0;</xsl:text>
      </math:mtext>
      <xsl:apply-templates select='*[3]'/>
    </math:mrow>
  </xsl:template>

  <!--
    plangeo7.altitude_foot
  -->
  <xsl:template match='OMA[OMS[@cd="plangeo7" and @name="altitude_foot"]]|
    om:OMA[om:OMS[@cd="plangeo7" and @name="altitude_foot"]]'
  >
    <math:mrow>
      <math:mtext>
        <!-- U+00A0 non breakable space -->
        <xsl:text>the foot of&#xA0;</xsl:text>
      </math:mtext>
      <xsl:apply-templates select='*[3]'/>
      <math:mtext>
        <!-- U+00A0 non breakable space -->
        <xsl:text>&#xA0;in&#xA0;</xsl:text>
      </math:mtext>
      <xsl:apply-templates select='*[2]'/>
    </math:mrow>
  </xsl:template>

  <!--
    plangeo7.area
  -->
  <xsl:template match='OMA[OMS[@cd="plangeo7" and @name="area"]]|
    om:OMA[om:OMS[@cd="plangeo7" and @name="area"]]'
  >
    <math:mrow>
      <math:mo>
        <xsl:text>(</xsl:text>
      </math:mo>
      <xsl:apply-templates select='*[2]'/>
      <math:mo>
        <xsl:text>)</xsl:text>
      </math:mo>
    </math:mrow>
  </xsl:template>

  <!--
    plangeo7.bisector
  -->
  <xsl:template match='OMA[OMS[@cd="plangeo7" and @name="bisector"]]|
    om:OMA[om:OMS[@cd="plangeo7" and @name="bisector"]]'
  >
    <math:mrow>
      <math:mtext>
        <!-- U+00A0 non breakable space -->
        <xsl:text>the bisector of&#xA0;</xsl:text>
      </math:mtext>
      <xsl:apply-templates select='*[2]'/>
    </math:mrow>
  </xsl:template>

  <!--
    plangeo7.circumcenter
  -->
  <xsl:template match='OMA[OMS[@cd="plangeo7" and @name="circumcenter"]]|
    om:OMA[om:OMS[@cd="plangeo7" and @name="circumcenter"]]'
  >
    <math:mrow>
      <math:mtext>
        <!-- U+00A0 non breakable space -->
        <xsl:text>the circumcenter of&#xA0;</xsl:text>
      </math:mtext>
      <xsl:apply-templates select='*[2]'/>
    </math:mrow>
  </xsl:template>

  <!--
    plangeo7.corner
  -->
  <xsl:template match='OMA[OMS[@cd="plangeo1" and @name="corner"]]|
    om:OMA[om:OMS[@cd="plangeo7" and @name="corner"]]'
  >
    <math:mrow>
      <math:mtext>
        <!-- U+2220 angle -->
        <xsl:text>&#x2220;</xsl:text>
      </math:mtext>
      <xsl:for-each select='*[position() &gt; 2]'>
        <xsl:apply-templates select='.'/>
      </xsl:for-each>
    </math:mrow>
  </xsl:template>

  <!--
    plangeo7.incenter
  -->
  <xsl:template match='OMA[OMS[@cd="plangeo7" and @name="incenter"]]|
    om:OMA[om:OMS[@cd="plangeo7" and @name="incenter"]]'
  >
    <math:mrow>
      <math:mtext>
        <!-- U+00A0 non breakable space -->
        <xsl:text>the incenter of&#xA0;</xsl:text>
      </math:mtext>
      <xsl:apply-templates select='*[2]'/>
    </math:mrow>
  </xsl:template>

  <!--
    plangeo7.intersection
  -->
  <xsl:template match='OMA[OMS[@cd="plangeo7" and @name="intersection"]]|
    om:OMA[om:OMS[@cd="plangeo7" and @name="intersection"]]'
  >
    <math:mrow>
      <math:mtext>
        <!-- U+00A0 non breakable space -->
        <xsl:text>the intersection of&#xA0;</xsl:text>
      </math:mtext>
      <xsl:copy-of select='mdf:makelist(*[position() &gt; 1])'/>
    </math:mrow>
  </xsl:template>

  <!--
    plangeo7.is_cevian
  -->
  <xsl:template match='OMA[OMS[@cd="plangeo7" and @name="is_cevian"]]|
    om:OMA[om:OMS[@cd="plangeo7" and @name="is_cevian"]]'
  >
    <math:mrow>
      <xsl:apply-templates select='*[2]'/>
      <math:mtext>
        <!-- U+00A0 non breakable space -->
        <xsl:text>&#xA0;is a cevian of&#xA0;</xsl:text>
      </math:mtext>
      <xsl:apply-templates select='*[3]'/>
    </math:mrow>
  </xsl:template>

  <!--
    plangeo7.is_vertex
  -->
  <xsl:template match='OMA[OMS[@cd="plangeo7" and @name="is_vertex"]]|
    om:OMA[om:OMS[@cd="plangeo7" and @name="is_vertex"]]'
  >
    <math:mrow>
      <xsl:apply-templates select='*[2]'/>
      <math:mtext>
        <!-- U+00A0 non breakable space -->
        <xsl:text>&#xA0;is a vertex of&#xA0;</xsl:text>
      </math:mtext>
      <xsl:apply-templates select='*[3]'/>
    </math:mrow>
  </xsl:template>

  <!--
    plangeo7.length
  -->
  <xsl:template match='OMA[OMS[@cd="plangeo7" and @name="length"]]|
    om:OMA[om:OMS[@cd="plangeo7" and @name="length"]]'
  >
    <!-- test whether the argument is a plangeo2.segment consisting of two
      plangeo1.points that have no conditions 
    -->
    <!-- do we have a segment : segment_ok -->
    <xsl:variable name='is_oma' as='xs:boolean' 
      select='boolean(OMA[2]|om:OMA[2])'
    />
    <xsl:variable name='is_oms' as='xs:boolean'
      select='boolean(*[2]/*[1][self::OMS or self::om:OMS])'
    />
    <xsl:variable name='is_segment' as='xs:boolean'
      select='boolean(*[2]/*[1][@name="segment" and @cd="plangeo2"])'
    />
    <xsl:variable name='segment_ok' as='xs:boolean'
      select='$is_oma and $is_oms and $is_segment'
    />
    <!-- is the first point ok : point1_ok -->
    <xsl:variable name='is_oma' as='xs:boolean' 
      select='boolean(*[2]/*[2][self::OMA or self::om:OMA])'
    />
    <xsl:variable name='is_oms' as='xs:boolean'
      select='boolean(*[2]/*[2]/*[1][self::OMS or self::om:OMS])'
    />
    <xsl:variable name='is_point' as='xs:boolean'
      select='boolean(*[2]/*[2]/*[1][@name="point" and @cd="plangeo1"])'
    />
    <xsl:variable name='no_conditions' as='xs:boolean'
      select='not(*[2]/*[2]/*[3])'
    />
    <xsl:variable name='point1_ok' as='xs:boolean'
      select='$is_oma and $is_oms and $is_point and $no_conditions'
    />
    <!-- is the first point ok : point2_ok -->
    <xsl:variable name='is_oma' as='xs:boolean' 
      select='boolean(*[2]/*[3][self::OMA or self::om:OMA])'
    />
    <xsl:variable name='is_oms' as='xs:boolean'
      select='boolean(*[2]/*[3]/*[1][self::OMS or self::om:OMS])'
    />
    <xsl:variable name='is_point' as='xs:boolean'
      select='boolean(*[2]/*[3]/*[1][@name="point" and @cd="plangeo1"])'
    />
    <xsl:variable name='no_conditions' as='xs:boolean'
      select='not(*[2]/*[3]/*[3])'
    />
    <xsl:variable name='point2_ok' as='xs:boolean'
      select='$is_oma and $is_oms and $is_point and $no_conditions'
    />
    <xsl:choose>
      <xsl:when test='$segment_ok and $point1_ok and $point2_ok'>
        <math:mover>
          <math:mrow>
            <xsl:apply-templates select='*[2]/*[2]/*[2]'/>
            <xsl:apply-templates select='*[2]/*[3]/*[2]'/>
          </math:mrow>
          <math:mo>
            <!-- U+0305 combining overline -->
            <xsl:text>&#x0305;</xsl:text>
          </math:mo>
        </math:mover>
      </xsl:when>
      <xsl:otherwise>
        <math:mrow>
          <math:mtext>
            <!-- U+00A0 non breakable space -->
            <xsl:text>the length of&#xA0;</xsl:text>
          </math:mtext>
          <xsl:apply-templates select='*[2]'/>
        </math:mrow>
      </xsl:otherwise>
    </xsl:choose>
  </xsl:template>

  <!--
    plangeo7.median
  -->
  <xsl:template match='OMA[OMS[@cd="plangeo7" and @name="median"]]|
    om:OMA[om:OMS[@cd="plangeo7" and @name="median"]]'
  >
    <math:mrow>
      <math:mtext>
        <!-- U+00A0 non breakable space -->
        <xsl:text>the median of&#xA0;</xsl:text>
      </math:mtext>
      <xsl:apply-templates select='*[2]'/>
      <math:mtext>
        <!-- U+00A0 non breakable space -->
        <xsl:text>&#xA0;through&#xA0;</xsl:text>
      </math:mtext>
      <xsl:apply-templates select='*[3]'/>
    </math:mrow>
  </xsl:template>

  <!--
    plangeo7.opposite_side
  -->
  <xsl:template match='OMA[OMS[@cd="plangeo7" and @name="opposite_side"]]|
    om:OMA[om:OMS[@cd="plangeo7" and @name="opposite_side"]]'
  >
    <math:mrow>
      <math:mtext>
        <!-- U+00A0 non breakable space -->
        <xsl:text>the opposite side of&#xA0;</xsl:text>
      </math:mtext>
      <xsl:apply-templates select='*[3]'/>
      <math:mtext>
        <!-- U+00A0 non breakable space -->
        <xsl:text>&#xA0;in&#xA0;</xsl:text>
      </math:mtext>
      <xsl:apply-templates select='*[2]'/>
    </math:mrow>
  </xsl:template>

  <!--
    plangeo7.orthocenter
  -->
  <xsl:template match='OMA[OMS[@cd="plangeo7" and @name="orthocenter"]]|
    om:OMA[om:OMS[@cd="plangeo7" and @name="orthocenter"]]'
  >
    <math:mrow>
      <math:mtext>
        <!-- U+00A0 non breakable space -->
        <xsl:text>the orthocenter of&#xA0;</xsl:text>
      </math:mtext>
      <xsl:apply-templates select='*[2]'/>
    </math:mrow>
  </xsl:template>

  <!--
    plangeo7.perpbisector
  -->
  <xsl:template match='OMA[OMS[@cd="plangeo7" and @name="perpbisector"]]|
    om:OMA[om:OMS[@cd="plangeo7" and @name="perpbisector"]]'
  >
    <math:mrow>
      <math:mtext>
        <!-- U+00A0 non breakable space -->
        <xsl:text>the perpbisector foot of&#xA0;</xsl:text>
      </math:mtext>
      <xsl:apply-templates select='*[2]'/>
    </math:mrow>
  </xsl:template>

  <!--
    plangeo7.perpendicular_foot
  -->
  <xsl:template match='OMA[OMS[@cd="plangeo7" and @name="perpendicular_foot"]]|
    om:OMA[om:OMS[@cd="plangeo7" and @name="perpendicular_foot"]]'
  >
    <math:mrow>
      <math:mtext>
        <!-- U+00A0 non breakable space -->
        <xsl:text>the perpendicular foot of&#xA0;</xsl:text>
      </math:mtext>
      <xsl:apply-templates select='*[2]'/>
      <math:mtext>
        <!-- U+00A0 non breakable space -->
        <xsl:text>&#xA0;and&#xA0;</xsl:text>
      </math:mtext>
      <xsl:apply-templates select='*[3]'/>
    </math:mrow>
  </xsl:template>

  <!--
    plangeo7.polygon
  -->
  <xsl:template match='OMA[OMS[@cd="plangeo7" and @name="polygon"]]|
    om:OMA[om:OMS[@cd="plangeo7" and @name="polygon"]]'
  >
    <math:mrow>
      <xsl:choose>
        <xsl:when test=
          'mdf:all_points_without_conditions(*[position() &gt; 1])'
        >
          <math:mtext>
            <!-- U+00A0 non breakable space -->
            <xsl:text>the polygon&#xA0;</xsl:text>
          </math:mtext>
          <xsl:apply-templates select='*[position() &gt; 1]' mode='short'/>
        </xsl:when>
        <xsl:otherwise>
          <math:mtext>
            <!-- U+00A0 non breakable space -->
            <xsl:text>the polygon defined by&#xA0;</xsl:text>
          </math:mtext>
          <xsl:copy-of select='mdf:makelist(*[position() &gt; 1])'/>
        </xsl:otherwise>
      </xsl:choose>
    </math:mrow>
  </xsl:template>

  <!--
    plangeo7.side
  -->
  <xsl:template match='OMA[OMS[@cd="plangeo7" and @name="side"]]|
    om:OMA[om:OMS[@cd="plangeo7" and @name="side"]]'
  >
    <math:mrow>
      <xsl:choose>
        <xsl:when test=
          'mdf:all_points_without_conditions(*[position() &gt; 2])'
        >
          <math:mtext>
            <!-- U+00A0 non breakable space -->
            <xsl:text>the side&#xA0;</xsl:text>
          </math:mtext>
          <xsl:apply-templates select='*[position() &gt; 2]' mode='short'/>
        </xsl:when>
        <xsl:otherwise>
          <math:mtext>
            <!-- U+00A0 non breakable space -->
            <xsl:text>the side of&#xA0;</xsl:text>
          </math:mtext>
          <xsl:copy-of select='mdf:makelist(*[position() &gt; 2])'/>
        </xsl:otherwise>
      </xsl:choose>
    </math:mrow>
  </xsl:template>

  <!--
    plangeo7.triangle
  -->
  <xsl:template match='OMA[OMS[@cd="plangeo7" and @name="triangle"]]|
    om:OMA[om:OMS[@cd="plangeo7" and @name="triangle"]]'
  >
    <math:mrow>
      <xsl:choose>
        <xsl:when test=
          'mdf:all_points_without_conditions(*[position() &gt; 1])'
        >
          <math:mtext>
            <!-- U+25B3 white up-pointing triangle -->
            <xsl:text>&#x25B3;</xsl:text>
          </math:mtext>
          <xsl:apply-templates select='*[position() &gt; 1]' mode='short'/>
        </xsl:when>
        <xsl:otherwise>
          <math:mtext>
            <!-- U+00A0 non breakable space -->
            <xsl:text>the triangle of&#xA0;</xsl:text>
          </math:mtext>
          <xsl:copy-of select='mdf:makelist(*[position() &gt; 1])'/>
        </xsl:otherwise>
      </xsl:choose>
    </math:mrow>
  </xsl:template>

  <!--
    plangeo7.type
  -->
  <xsl:template match='OMA[OMS[@cd="plangeo7" and @name="type"]]|
    om:OMA[om:OMS[@cd="plangeo7" and @name="type"]]'
  >
    <math:mrow>
      <math:mtext>
        <!-- U+00A0 non breakable space -->
        <xsl:text>the type of&#xA0;</xsl:text>
      </math:mtext>
      <xsl:apply-templates select='*[2]'/>
    </math:mrow>
  </xsl:template>

  <!--
    plangeo7.vertices
  -->
  <xsl:template match='OMA[OMS[@cd="plangeo7" and @name="vertices"]]|
    om:OMA[om:OMS[@cd="plangeo7" and @name="vertices"]]'
  >
    <math:mrow>
      <math:mtext>
        <!-- U+00A0 non breakable space -->
        <xsl:text>the vertices of&#xA0;</xsl:text>
      </math:mtext>
      <xsl:apply-templates select='*[2]'/>
    </math:mrow>
  </xsl:template>

  <!--
    plangeo8 
    - are_concurrent
    - are_congruent
    - are_similar
    - intersect
    - is [not implemented]
    - is_acute_angle
    - is_acute_triangle
    - is_equilateral_triangle
    - is_isosceles_right_triangle
    - is_isosceles_triangle
    - is_obtuse_angle
    - is_obtuse_triangle
    - is_right_angle
    - is_right_triangle
  -->

  <!--
    plangeo8.are_concurrent
  -->
  <xsl:template match='OMA[OMS[@cd="plangeo8" and @name="are_concurrent"]]|
    om:OMA[om:OMS[@cd="plangeo8" and @name="are_concurrent"]]'
  >
    <xsl:copy-of select='mdf:makelist(*[position() &gt; 1])'/>
    <math:mrow>
      <math:mtext>
        <!-- U+00A0 non breakable space -->
        <xsl:text>&#xA0;are concurrent</xsl:text>
      </math:mtext>
    </math:mrow>
  </xsl:template>

  <!--
    plangeo8.are_congruent
  -->
  <xsl:template match='OMA[OMS[@cd="plangeo8" and @name="are_congruent"]]|
    om:OMA[om:OMS[@cd="plangeo8" and @name="are_congruent"]]'
  >
    <math:mrow>
      <xsl:apply-templates select='*[2]'/>
      <math:mo>
        <!-- U+224C all equal to (reversed '~' above '=')-->
        <xsl:text>&#x224C;</xsl:text>
      </math:mo>
      <xsl:apply-templates select='*[3]'/>
    </math:mrow>
  </xsl:template>

  <!--
    plangeo8.are_similar
  -->
  <xsl:template match='OMA[OMS[@cd="plangeo8" and @name="are_similar"]]|
    om:OMA[om:OMS[@cd="plangeo8" and @name="are_similar"]]'
  >
    <math:mrow>
      <xsl:apply-templates select='*[2]'/>
      <math:mo>
        <!-- U+223D reversed tilde -->
        <xsl:text>&#x223D;</xsl:text>
      </math:mo>
      <xsl:apply-templates select='*[3]'/>
    </math:mrow>
  </xsl:template>

  <!--
    plangeo8.intersect
  -->
  <xsl:template match='OMA[OMS[@cd="plangeo8" and @name="intersect"]]|
    om:OMA[om:OMS[@cd="plangeo8" and @name="intersect"]]'
  >
    <math:mrow>
      <xsl:apply-templates select='*[2]'/>
      <math:mtext>
        <!-- U+00A0 non breakable space -->
        <xsl:text>&#xA0;and&#xA0;</xsl:text>
      </math:mtext>
      <xsl:apply-templates select='*[3]'/>
      <math:mtext>
        <!-- U+00A0 non breakable space -->
        <xsl:text>&#xA0;intersect</xsl:text>
      </math:mtext>
    </math:mrow>
  </xsl:template>

  <!--
    plangeo8.is_acute_angle
  -->
  <xsl:template match='OMA[OMS[@cd="plangeo8" and @name="is_acute_angle"]]|
    om:OMA[om:OMS[@cd="plangeo8" and @name="is_acute_angle"]]'
  >
    <math:mrow>
      <math:mo>
        <!-- U+2221 measured angle-->
        <xsl:text>&#x2221;</xsl:text>
      </math:mo>
      <xsl:apply-templates select='*[2]'/>
      <math:mo>
        <xsl:text>&lt;</xsl:text>
      </math:mo>
      <math:mn>
        <xsl:text>90</xsl:text>
      </math:mn>
      <math:mo>
        <!-- U+00B0 degree sign -->
        <xsl:text>&#xB0;</xsl:text>
      </math:mo>
    </math:mrow>
  </xsl:template>

  <!--
    plangeo8.is_acute_triangle
  -->
  <xsl:template match='OMA[OMS[@cd="plangeo8" and @name="is_acute_triangle"]]|
    om:OMA[om:OMS[@cd="plangeo8" and @name="is_acute_triangle"]]'
  >
    <math:mrow>
      <xsl:apply-templates select='*[2]'/>
      <math:mtext>
        <!-- U+00A0 non breakable space -->
        <xsl:text>&#xA0;is acute</xsl:text>
      </math:mtext>
    </math:mrow>
  </xsl:template>

  <!--
    plangeo8.is_equilateral_triangle
  -->
  <xsl:template 
    match='OMA[OMS[@cd="plangeo8" and @name="is_equilateral_triangle"]]| 
      om:OMA[om:OMS[@cd="plangeo8" and @name="is_equilateral_triangle"]]'
  >
    <math:mrow>
      <xsl:apply-templates select='*[2]'/>
      <math:mtext>
        <!-- U+00A0 non breakable space -->
        <xsl:text>&#xA0;is equilateral</xsl:text>
      </math:mtext>
    </math:mrow>
  </xsl:template>

  <!--
    plangeo8.is_isosceles_right_triangle
  -->
  <xsl:template 
    match='OMA[OMS[@cd="plangeo8" and @name="is_isosceles_right_triangle"]]|
      om:OMA[om:OMS[@cd="plangeo8" and @name="is_isosceles_right_triangle"]]'
  >
    <math:mrow>
      <xsl:apply-templates select='*[2]'/>
      <math:mtext>
        <!-- U+00A0 non breakable space -->
        <xsl:text>&#xA0;is an isosceles triangle with&#xA0;</xsl:text>
      </math:mtext>
      <xsl:choose>
        <xsl:when test='*[4]'>
	  <!--
	    the two sides of equal length
	  -->
          <xsl:apply-templates select='*[3]'/>
          <math:mtext>
            <!-- U+00A0 non breakable space -->
            <xsl:text>&#xA0;and&#xA0;</xsl:text>
          </math:mtext>
          <xsl:apply-templates select='*[4]'/>
          <math:mtext>
            <!-- U+00A0 non breakable space -->
            <xsl:text>&#xA0;of equal length and a right angle connecting them</xsl:text>
          </math:mtext>
	</xsl:when>
	<xsl:otherwise>
	  <!--
	    point connecting the sides of equal length
	  -->
          <xsl:apply-templates select='*[3]'/>
	  <math:mtext>
	    <!-- U+00A0 non breakable space -->
	    <xsl:text>&#xA0; connecting the sides of equal length with a right angle</xsl:text>
	  </math:mtext>
	</xsl:otherwise>
      </xsl:choose>
    </math:mrow>
  </xsl:template>

  <!--
    plangeo8.is_isosceles_triangle
  -->
  <xsl:template 
    match='OMA[OMS[@cd="plangeo8" and @name="is_isosceles_triangle"]]|
    om:OMA[om:OMS[@cd="plangeo8" and @name="is_isosceles_triangle"]]'
  >
    <math:mrow>
      <xsl:apply-templates select='*[2]'/>
      <math:mtext>
        <!-- U+00A0 non breakable space -->
        <xsl:text>&#xA0;is an isosceles triangle with&#xA0;</xsl:text>
      </math:mtext>
      <xsl:choose>
        <xsl:when test='*[4]'>
	  <!--
	    the two sides of equal length
	  -->
          <xsl:apply-templates select='*[3]'/>
	  <math:mtext>
	    <!-- U+00A0 non breakable space -->
	    <xsl:text>&#xA0;and&#xA0;</xsl:text>
	  </math:mtext>
	  <xsl:apply-templates select='*[4]'/>
	  <math:mtext>
	    <!-- U+00A0 non breakable space -->
	    <xsl:text>&#xA0;of equal length</xsl:text>
	  </math:mtext>
	</xsl:when>
	<xsl:otherwise>
	  <!--
	    point connecting the sides of equal length
	  -->
          <xsl:apply-templates select='*[3]'/>
	  <math:mtext>
	    <!-- U+00A0 non breakable space -->
	    <xsl:text>&#xA0; on sides of equal length</xsl:text>
	  </math:mtext>
	</xsl:otherwise>
      </xsl:choose>
    </math:mrow>
  </xsl:template>

  <!--
    plangeo8.is_obtuse_angle
  -->
  <xsl:template match='OMA[OMS[@cd="plangeo8" and @name="is_obtuse_angle"]]|
    om:OMA[om:OMS[@cd="plangeo8" and @name="is_obtuse_angle"]]'
  >
    <math:mrow>
      <math:mo>
        <!-- U+2221 measured angle-->
        <xsl:text>&#x2221;</xsl:text>
      </math:mo>
      <xsl:apply-templates select='*[2]'/>
      <math:mo>
        <xsl:text>&gt;</xsl:text>
      </math:mo>
      <math:mn>
        <xsl:text>90</xsl:text>
      </math:mn>
      <math:mo>
        <!-- U+00B0 degree sign -->
        <xsl:text>&#xB0;</xsl:text>
      </math:mo>
    </math:mrow>
  </xsl:template>

  <!--
    plangeo8.is_obtuse_triangle
  -->
  <xsl:template 
    match='OMA[OMS[@cd="plangeo8" and @name="is_obtuse_triangle"]]|
      om:OMA[om:OMS[@cd="plangeo8" and @name="is_obtuse_triangle"]]'
  >
    <math:mrow>
      <xsl:apply-templates select='*[2]'/>
      <math:mtext>
        <!-- U+00A0 non breakable space -->
        <xsl:text>&#xA0;is obtuse, with&#xA0;</xsl:text>
      </math:mtext>
      <!-- use plangeo8.is_obtuse_angle for the condition -->
      <xsl:variable name='is_obtuse_corner' as='node()'>
        <om:OMA>
          <om:OMS cd='plangeo8' name='is_obtuse_angle'/>
          <xsl:copy-of select='*[3]'/>
        </om:OMA>
      </xsl:variable>
      <xsl:apply-templates select='$is_obtuse_corner'/>
    </math:mrow>
  </xsl:template>

  <!--
    plangeo8.is_right_angle
  -->
  <xsl:template match='OMA[OMS[@cd="plangeo8" and @name="is_right_angle"]]|
    om:OMA[om:OMS[@cd="plangeo8" and @name="is_right_angle"]]'
  >
    <math:mrow>
      <math:mo>
        <!-- U+2221 measured angle-->
        <xsl:text>&#x2221;</xsl:text>
      </math:mo>
      <xsl:apply-templates select='*[2]'/>
      <math:mo>
        <xsl:text>&gt;</xsl:text>
      </math:mo>
      <math:mn>
        <xsl:text>90</xsl:text>
      </math:mn>
      <math:mo>
        <!-- U+00B0 degree sign -->
        <xsl:text>&#xB0;</xsl:text>
      </math:mo>
    </math:mrow>
  </xsl:template>

  <!--
    plangeo8.is_right_triangle
  -->
  <xsl:template match='OMA[OMS[@cd="plangeo8" and @name="is_right_triangle"]]|
    om:OMA[om:OMS[@cd="plangeo8" and @name="is_right_triangle"]]'
  >
    <math:mrow>
      <xsl:apply-templates select='*[2]'/>
      <math:mtext>
        <!-- U+00A0 non breakable space -->
        <xsl:text>&#xA0;is a right triangle, with&#xA0;</xsl:text>
      </math:mtext>
      <!-- use plangeo8.is_obtuse_angle for the condition -->
      <xsl:variable name='is_right_corner' as='node()'>
        <om:OMA>
          <om:OMS cd='plangeo8' name='is_right_angle'/>
          <xsl:copy-of select='*[3]'/>
        </om:OMA>
      </xsl:variable>
      <xsl:apply-templates select='$is_right_corner'/>
    </math:mrow>
  </xsl:template>

</xsl:stylesheet>
