--- mathmlc2p.xsl	2005-07-05 13:58:45.000000000 -0500
+++ mathmlc2p-2.xsl	2005-07-06 13:55:59.000000000 -0500
@@ -201,7 +201,7 @@
 </xsl:template>
 
 <!-- externally defined symbols-->
-<xsl:template match="m:apply[*[position()=1 and name()='csymbol']]">
+<xsl:template match="m:apply[*[position()=1 and self::m:csymbol]]">
   <mrow>
   <xsl:apply-templates select="m:csymbol[position()=1]"/>
   <mfenced>
@@ -232,7 +232,7 @@
 <!-- #################### 4.4.2 #################### -->
 
 <!-- apply/apply -->
-<xsl:template match="m:apply[*[position()=1 and name()='apply']]">  <!-- when the function itself is defined by other functions: (F+G)(x) -->
+<xsl:template match="m:apply[*[position()=1 and self::m:apply]]">  <!-- when the function itself is defined by other functions: (F+G)(x) -->
   <xsl:choose>
   <xsl:when test="count(*)>=2">
     <mrow>
@@ -247,10 +247,10 @@
 </xsl:template>
 
 <!-- force function or operator MathML 1.0 deprecated-->
-<xsl:template match="m:apply[*[position()=1 and name()='fn']]">
+<xsl:template match="m:apply[*[position()=1 and self::m:fn]]">
 <mrow>
   <xsl:choose>
-    <xsl:when test="name(m:fn/*[position()=1])='apply'"> <!-- fn definition is complex, surround with brackets, but only one child-->
+    <xsl:when test="m:fn/*[position()=1 and self::m:apply]"> <!-- fn definition is complex, surround with brackets, but only one child-->
       <mfenced separators=""><mrow><xsl:apply-templates select="m:fn/*"/></mrow></mfenced>
     </xsl:when>
     <xsl:otherwise>
@@ -267,7 +267,7 @@
 </xsl:template>
 
 <!--first ci is supposed to be a function-->
-<xsl:template match="m:apply[*[position()=1 and name()='ci']]">
+<xsl:template match="m:apply[*[position()=1 and self::m:ci]]">
 <mrow>
   <xsl:apply-templates select="m:ci[position()=1]"/>
   <xsl:if test="count(*)>1">  <!-- if no operands, don't put empty parentheses-->
@@ -279,7 +279,7 @@
 </mrow>
 </xsl:template>
 
-<xsl:template match="m:apply[*[position()=1 and name()='mo']]">
+<xsl:template match="m:apply[*[position()=1 and self::m:mo]]">
   <!--operator assumed to be infix-->
   <xsl:choose>
   <xsl:when test="count(*)>=3">
@@ -341,7 +341,7 @@
 </xsl:template>
 
 <!-- inverse -->
-<xsl:template match="m:apply[*[position()=1 and name()='apply']/m:inverse]">
+<xsl:template match="m:apply[*[position()=1 and self::m:apply]/m:inverse]">
   <mrow>
   <msup> <!-- elementary classical functions have two templates: apply[func] for standard case, func[position()!=1] for inverse and compose case-->
     <mrow><xsl:apply-templates select="m:apply[position()=1]/*[position()=2]"/></mrow> <!-- function to be inversed-->
@@ -356,7 +356,7 @@
   </mrow>
 </xsl:template>
 
-<xsl:template match="m:apply[*[position()=1 and name()='inverse']]">
+<xsl:template match="m:apply[*[position()=1 and self::m:inverse]]">
   <msup> <!-- elementary classical functions have two templates: apply[func] for standard case, func[position()!=1] for inverse and compose case-->
     <mrow><xsl:apply-templates select="*[position()=2]"/></mrow> <!-- function to be inversed-->
     <mfenced><mn>-1</mn></mfenced>
@@ -388,7 +388,7 @@
 </xsl:template>
 
 <!-- composition -->
-<xsl:template match="m:apply[*[position()=1 and name()='apply']/m:compose]">
+<xsl:template match="m:apply[*[position()=1 and self::m:apply]/m:compose]">
   <mrow> <!-- elementary classical functions have two templates: apply[func] for standard case, func[position()!=1] for inverse and compose case-->
     <xsl:choose>
     <xsl:when test="count(*)>=2"> <!-- if there are operands, mfence functions-->
@@ -420,7 +420,7 @@
   </mrow>
 </xsl:template>
 
-<xsl:template match="m:apply[*[position()=1 and name()='compose']]">
+<xsl:template match="m:apply[*[position()=1 and self::m:compose]]">
    <!-- elementary classical functions have two templates: apply[func] for standard case, func[position()!=1] for inverse and compose case-->
   <xsl:for-each select="*[position()!=1 and position()!=last()]">
     <xsl:apply-templates select="."/><mo><xsl:text disable-output-escaping="yes"><![CDATA[&SmallCircle;]]></xsl:text></mo> <!-- compose functions --><!-- does not work, perhaps compfn, UNICODE 02218-->
@@ -434,21 +434,21 @@
 </xsl:template>
 
 <!-- domain -->
-<xsl:template match="m:apply[*[position()=1 and name()='domain']]">
+<xsl:template match="m:apply[*[position()=1 and self::m:domain]]">
   <mrow>
     <mi>domain</mi><mfenced open="(" close=")"><xsl:apply-templates select="*[position()!=1]"/></mfenced>
   </mrow>
 </xsl:template>
 
 <!-- codomain -->
-<xsl:template match="m:apply[*[position()=1 and name()='codomain']]">
+<xsl:template match="m:apply[*[position()=1 and self::m:codomain]]">
   <mrow>
     <mi>codomain</mi><mfenced open="(" close=")"><xsl:apply-templates select="*[position()!=1]"/></mfenced>
   </mrow>
 </xsl:template>
 
 <!-- image -->
-<xsl:template match="m:apply[*[position()=1 and name()='image']]">
+<xsl:template match="m:apply[*[position()=1 and self::m:image]]">
   <mrow>
     <mi>image</mi><mfenced open="(" close=")"><xsl:apply-templates select="*[position()!=1]"/></mfenced>
   </mrow>
@@ -477,12 +477,12 @@
 <!-- #################### 4.4.3 #################### -->
 
 <!-- quotient -->
-<xsl:template match="m:apply[*[position()=1 and name()='quotient']]">
+<xsl:template match="m:apply[*[position()=1 and self::m:quotient]]">
   <mrow>  <!-- the third notation uses UNICODE chars x0230A and x0230B -->
     <mo>integer part of</mo>
     <mrow>
       <xsl:choose> <!-- surround with brackets if operands are composed-->
-      <xsl:when test="*[position()=2] and name()='apply'">
+      <xsl:when test="*[position()=2] and self::m:apply">
         <mfenced separators=""><xsl:apply-templates select="*[position()=2]"/></mfenced>
       </xsl:when>
       <xsl:otherwise>
@@ -491,7 +491,7 @@
       </xsl:choose>
       <mo>/</mo>
       <xsl:choose>
-      <xsl:when test="*[position()=3] and name()='apply'">
+      <xsl:when test="*[position()=3] and self::m:apply">
         <mfenced separators=""><xsl:apply-templates select="*[position()=3]"/></mfenced>
       </xsl:when>
       <xsl:otherwise>
@@ -503,10 +503,10 @@
 </xsl:template>
 
 <!-- factorial -->
-<xsl:template match="m:apply[*[position()=1 and name()='factorial']]">
+<xsl:template match="m:apply[*[position()=1 and self::m:factorial]]">
   <mrow>
     <xsl:choose> <!-- surround with brackets if operand is composed-->
-    <xsl:when test="name(*[position()=2])='apply'">
+    <xsl:when test="*[position()=2 and self::m:apply]">
       <mfenced separators=""><xsl:apply-templates select="*[position()=2]"/></mfenced>
     </xsl:when>
     <xsl:otherwise>
@@ -518,7 +518,7 @@
 </xsl:template>
 
 <!-- divide -->
-<xsl:template match="m:apply[*[position()=1 and name()='divide']]">
+<xsl:template match="m:apply[*[position()=1 and self::m:divide]]">
   <mrow>
     <xsl:choose>
     <xsl:when test="contains(@other,'scriptstyle')">
@@ -538,7 +538,7 @@
 </xsl:template>
 
 <!-- min -->
-<xsl:template match="m:apply[*[position()=1 and name()='min']]">
+<xsl:template match="m:apply[*[position()=1 and self::m:min]]">
   <mrow>
     <xsl:choose>
     <xsl:when test="m:bvar"> <!-- if there are bvars-->
@@ -552,7 +552,7 @@
         </mrow>
       </msub>
       <mrow><mo>{</mo>
-        <xsl:apply-templates select="*[name()!='condition' and name()!='bvar']"/>
+        <xsl:apply-templates select="*[not(self::m:condition) and not(self::m:bvar)]"/>
         <xsl:if test="m:condition">
           <mo>|</mo><xsl:apply-templates select="m:condition"/>
         </xsl:if>
@@ -561,7 +561,7 @@
     <xsl:otherwise> <!-- if there are no bvars-->
       <mo>min</mo>
       <mrow><mo>{</mo>
-      <mfenced open="" close=""><xsl:apply-templates select="*[name()!='condition']"/></mfenced>
+      <mfenced open="" close=""><xsl:apply-templates select="*[not(self::m:condition)]"/></mfenced>
       <xsl:if test="m:condition">
         <mo>|</mo><xsl:apply-templates select="m:condition"/>
       </xsl:if>
@@ -572,7 +572,7 @@
 </xsl:template>
 
 <!-- max -->
-<xsl:template match="m:apply[*[position()=1 and name()='max']]">
+<xsl:template match="m:apply[*[position()=1 and self::m:max]]">
   <mrow>
     <xsl:choose>
     <xsl:when test="m:bvar"> <!-- if there are bvars-->
@@ -586,7 +586,7 @@
         </mrow>
       </msub>
       <mrow><mo>{</mo>
-      <xsl:apply-templates select="*[name()!='condition' and name()!='bvar']"/>
+      <xsl:apply-templates select="*[not(self::m:condition) and not(self::m:bvar)]"/>
       <xsl:if test="m:condition">
         <mo>|</mo><xsl:apply-templates select="m:condition"/>
       </xsl:if>
@@ -595,7 +595,7 @@
     <xsl:otherwise> <!-- if there are no bvars-->
       <mo>max</mo>
       <mrow><mo>{</mo>
-        <mfenced open="" close=""><xsl:apply-templates select="*[name()!='condition']"/></mfenced>
+        <mfenced open="" close=""><xsl:apply-templates select="*[not(self::m:condition)]"/></mfenced>
         <xsl:if test="m:condition">
           <mo>|</mo><xsl:apply-templates select="m:condition"/>
         </xsl:if>
@@ -606,14 +606,14 @@
 </xsl:template>
 
 <!-- substraction(minus); unary or binary operator-->
-<xsl:template match="m:apply[*[position()=1 and name()='minus']]">
+<xsl:template match="m:apply[*[position()=1 and self::m:minus]]">
   <mrow>
   <xsl:choose> <!-- binary -->
   <xsl:when test="count(*)=3">
     <xsl:apply-templates select="*[position()=2]"/>
     <mo>-</mo>
     <xsl:choose>
-      <xsl:when test="((name(*[position()=3])='ci' or name(*[position()=3])='cn') and contains(*[position()=3]/text(),'-')) or (name(*[position()=3])='apply')">
+      <xsl:when test="(*[position()=3 and (self::m:ci or self::m:cn)] and contains(*[position()=3]/text(),'-')) or *[position()=3 and self::m:apply]">
         <mfenced separators=""><xsl:apply-templates select="*[position()=3]"/></mfenced> <!-- surround negative or complex things with brackets -->
       </xsl:when>
       <xsl:otherwise>
@@ -624,7 +624,7 @@
   <xsl:otherwise> <!-- unary -->
     <mo>-</mo>
     <xsl:choose>
-    <xsl:when test="((name(*[position()=2])='ci' or name(*[position()=2])='cn') and contains(*[position()=2]/text(),'-')) or (name(*[position()=2])='apply')">
+    <xsl:when test="(*[position()=2 and (self::m:ci or self::m:cn)] and contains(*[position()=2]/text(),'-')) or *[position()=2 and self::m:apply]">
       <mfenced separators=""><!-- surround negative or complex things with brackets -->
       <xsl:apply-templates select="*[position()=last()]"/>
       </mfenced>
@@ -639,12 +639,12 @@
 </xsl:template>
 
 <!-- addition -->
-<xsl:template match="m:apply[*[position()=1 and name()='plus']]">
+<xsl:template match="m:apply[*[position()=1 and self::m:plus]]">
   <xsl:choose>
   <xsl:when test="count(*)>=3">
     <mrow>
       <xsl:choose>
-        <xsl:when test="((name(*[position()=2])='ci' or name(*[position()=2])='cn') and contains(*[position()=2]/text(),'-')) or (*[position()=2 and self::m:apply and child::m:minus])">
+        <xsl:when test="(*[position()=2 and (self::m:ci or self::m:cn)] and contains(*[position()=2]/text(),'-')) or (*[position()=2 and self::m:apply and child::m:minus])">
           <mfenced separators=""><xsl:apply-templates select="*[position()=2]"/></mfenced> <!-- surround negative things with brackets -->
         </xsl:when>
         <xsl:otherwise>
@@ -653,7 +653,7 @@
       </xsl:choose>
       <xsl:for-each select="*[position()!=1 and position()!=2]">
         <xsl:choose>
-        <xsl:when test="((name(.)='ci' or name(.)='cn') and contains(./text(),'-')) or (self::m:apply and child::m:minus)"> <!-- surround negative things with brackets -->
+        <xsl:when test="((self::m:ci or self::m:cn) and contains(./text(),'-')) or (self::m:apply and child::m:minus)"> <!-- surround negative things with brackets -->
           <mo>+</mo><mfenced separators=""><xsl:apply-templates select="."/></mfenced>
         </xsl:when>
         <xsl:otherwise>
@@ -675,10 +675,10 @@
 </xsl:template>
 
 <!-- power -->
-<xsl:template match="m:apply[*[position()=1 and name()='power']]">
+<xsl:template match="m:apply[*[position()=1 and self::m:power]]">
   <msup>
     <xsl:choose>
-    <xsl:when test="name(*[position()=2])='apply'">
+    <xsl:when test="*[position()=2 and self::m:apply]">
       <mfenced separators=""><xsl:apply-templates select="*[position()=2]"/></mfenced>
     </xsl:when>
     <xsl:otherwise>
@@ -690,10 +690,10 @@
 </xsl:template>
 
 <!-- remainder -->
-<xsl:template match="m:apply[*[position()=1 and name()='rem']]">
+<xsl:template match="m:apply[*[position()=1 and self::m:rem]]">
   <mrow>
     <xsl:choose> <!-- surround with brackets if operands are composed-->
-    <xsl:when test="name(*[position()=2])='apply'">
+    <xsl:when test="*[position()=2 and self::m:apply]">
       <mfenced separators=""><xsl:apply-templates select="*[position()=2]"/></mfenced>
     </xsl:when>
     <xsl:otherwise>
@@ -702,7 +702,7 @@
     </xsl:choose>
     <mo>mod</mo>
     <xsl:choose>
-    <xsl:when test="name(*[position()=3])='apply'">
+    <xsl:when test="*[position()=3 and self::m:apply]">
       <mfenced separators=""><xsl:apply-templates select="*[position()=3]"/></mfenced>
     </xsl:when>
     <xsl:otherwise>
@@ -713,7 +713,7 @@
 </xsl:template>
 
 <!-- multiplication -->
-<xsl:template match="m:apply[*[position()=1 and name()='times']]">
+<xsl:template match="m:apply[*[position()=1 and self::m:times]]">
 <xsl:choose>
 <xsl:when test="count(*)>=3">
   <mrow>
@@ -725,7 +725,7 @@
       <xsl:when test="m:minus"> <!--add brackets around - children for priority purpose-->
         <mfenced separators=""><xsl:apply-templates select="."/></mfenced><mo><xsl:text disable-output-escaping="yes"><![CDATA[&InvisibleTimes;]]></xsl:text></mo>
       </xsl:when>
-      <xsl:when test="(name(.)='ci' or name(.)='cn') and contains(text(),'-')"> <!-- have to do it using contains because starts-with doesn't seem to work well in XT-->
+      <xsl:when test="(self::m:ci or self::m:cn) and contains(text(),'-')"> <!-- have to do it using contains because starts-with doesn't seem to work well in XT-->
         <mfenced separators=""><xsl:apply-templates select="."/></mfenced><mo><xsl:text disable-output-escaping="yes"><![CDATA[&InvisibleTimes;]]></xsl:text></mo>
       </xsl:when>
       <xsl:otherwise>
@@ -741,7 +741,7 @@
       <xsl:when test="m:minus">
         <mfenced separators=""><xsl:apply-templates select="."/></mfenced>
       </xsl:when>
-      <xsl:when test="(name(.)='ci' or name(.)='cn') and contains(text(),'-')"> <!-- have to do it using contains because starts-with doesn't seem to work well in  XT-->
+      <xsl:when test="(self::m:ci or self::m:cn) and contains(text(),'-')"> <!-- have to do it using contains because starts-with doesn't seem to work well in  XT-->
         <mfenced separators=""><xsl:apply-templates select="."/></mfenced>
       </xsl:when>
       <xsl:otherwise>
@@ -761,7 +761,7 @@
       <xsl:when test="m:minus">
         <mfenced separators=""><xsl:apply-templates select="*[position()=2]"/></mfenced>
       </xsl:when>
-      <xsl:when test="(*[position()=2 and self::m:ci] or *[position()=2 and self::m:cn]) and contains(*[position()=2]/text(),'-')">
+      <xsl:when test="*[position()=2 and (self::m:ci or self::m:cn)] and contains(*[position()=2]/text(),'-')">
         <mfenced separators=""><xsl:apply-templates select="*[position()=2]"/></mfenced>
       </xsl:when>
       <xsl:otherwise>
@@ -777,7 +777,7 @@
 </xsl:template>
 
 <!-- root -->
-<xsl:template match="m:apply[*[position()=1 and name()='root']]">
+<xsl:template match="m:apply[*[position()=1 and self::m:root]]">
   <xsl:choose>
   <xsl:when test="m:degree">
     <xsl:choose>
@@ -803,7 +803,7 @@
 </xsl:template>
 
 <!-- greatest common divisor -->
-<xsl:template match="m:apply[*[position()=1 and name()='gcd']]">
+<xsl:template match="m:apply[*[position()=1 and self::m:gcd]]">
   <mrow>
     <mi>gcd</mi><mo><xsl:text disable-output-escaping="yes"><![CDATA[&ApplyFunction;]]></xsl:text></mo>
     <mfenced>
@@ -813,7 +813,7 @@
 </xsl:template>
 
 <!-- AND -->
-<xsl:template match="m:apply[*[position()=1 and name()='and']]">
+<xsl:template match="m:apply[*[position()=1 and self::m:and]]">
 <mrow>
   <xsl:choose>
   <xsl:when test="count(*)>=3"> <!-- at least two operands (common case)-->
@@ -855,7 +855,7 @@
 </xsl:template>
 
 <!-- OR -->
-<xsl:template match="m:apply[*[position()=1 and name()='or']]">
+<xsl:template match="m:apply[*[position()=1 and self::m:or]]">
 <mrow>
   <xsl:choose>
   <xsl:when test="count(*)>=3">
@@ -875,7 +875,7 @@
 </xsl:template>
 
 <!-- XOR -->
-<xsl:template match="m:apply[*[position()=1 and name()='xor']]">
+<xsl:template match="m:apply[*[position()=1 and self::m:xor]]">
 <mrow>
   <xsl:choose>
   <xsl:when test="count(*)>=3">
@@ -895,7 +895,7 @@
 </xsl:template>
 
 <!-- NOT -->
-<xsl:template match="m:apply[*[position()=1 and name()='not']]">
+<xsl:template match="m:apply[*[position()=1 and self::m:not]]">
   <mrow>
     <mo><xsl:text disable-output-escaping="yes"><![CDATA[&Not;]]></xsl:text></mo>
     <xsl:choose>
@@ -912,7 +912,7 @@
 </xsl:template>
 
 <!-- implies -->
-<xsl:template match="m:apply[*[position()=1 and name()='implies']]">
+<xsl:template match="m:apply[*[position()=1 and self::m:implies]]">
   <mrow>
     <xsl:apply-templates select="*[position()=2]"/>
     <mo><xsl:text disable-output-escaping="yes"><![CDATA[&DoubleRightArrow;]]></xsl:text></mo>
@@ -920,7 +920,7 @@
   </mrow>
 </xsl:template>
 
-<xsl:template match="m:reln[*[position()=1 and name()='implies']]">
+<xsl:template match="m:reln[*[position()=1 and self::m:implies]]">
   <mrow>
     <xsl:apply-templates select="*[position()=2]"/>
     <mo><xsl:text disable-output-escaping="yes"><![CDATA[&DoubleRightArrow;]]></xsl:text></mo>
@@ -929,7 +929,7 @@
 </xsl:template>
 
 <!-- for all-->
-<xsl:template match="m:apply[*[position()=1 and name()='forall']]">
+<xsl:template match="m:apply[*[position()=1 and self::m:forall]]">
   <mrow>
     <mo><xsl:text disable-output-escaping="yes"><![CDATA[&ForAll;]]></xsl:text></mo>
     <mrow>
@@ -953,7 +953,7 @@
 </xsl:template>
 
 <!-- exist-->
-<xsl:template match="m:apply[*[position()=1 and name()='exists']]">
+<xsl:template match="m:apply[*[position()=1 and self::m:exists]]">
   <mrow>
     <mo><xsl:text disable-output-escaping="yes"><![CDATA[&Exists;]]></xsl:text></mo>
     <mrow>
@@ -977,12 +977,12 @@
 </xsl:template>
 
 <!-- absolute value -->
-<xsl:template match="m:apply[*[position()=1 and name()='abs']]">
+<xsl:template match="m:apply[*[position()=1 and self::m:abs]]">
   <mrow><mo>|</mo><xsl:apply-templates select="*[position()=last()]"/><mo>|</mo></mrow>
 </xsl:template>
 
 <!-- conjugate -->
-<xsl:template match="m:apply[*[position()=1 and name()='conjugate']]">
+<xsl:template match="m:apply[*[position()=1 and self::m:conjugate]]">
   <mover>
     <xsl:apply-templates select="*[position()=2]"/>
     <mo><xsl:text disable-output-escaping="yes"><![CDATA[&ovbar;]]></xsl:text></mo>  <!-- does not work, UNICODE x0233D  or perhaps OverBar-->
@@ -990,14 +990,14 @@
 </xsl:template>
 
 <!-- argument of complex number -->
-<xsl:template match="m:apply[*[position()=1 and name()='arg']]">
+<xsl:template match="m:apply[*[position()=1 and self::m:arg]]">
   <mrow>
     <mi>arg</mi><mo><xsl:text disable-output-escaping="yes"><![CDATA[&ApplyFunction;]]></xsl:text></mo><mfenced separators=""><xsl:apply-templates select="*[position()=2]"/></mfenced>
   </mrow>
 </xsl:template>
 
 <!-- real part of complex number -->
-<xsl:template match="m:apply[*[position()=1 and name()='real']]">
+<xsl:template match="m:apply[*[position()=1 and self::m:real]]">
   <mrow>
     <mi><xsl:text disable-output-escaping="yes">&amp;#x0211C;</xsl:text><!-- &Re; or &realpart; should work--></mi>
     <mo><xsl:text disable-output-escaping="yes"><![CDATA[&ApplyFunction;]]></xsl:text></mo>
@@ -1006,7 +1006,7 @@
 </xsl:template>
 
 <!-- imaginary part of complex number -->
-<xsl:template match="m:apply[*[position()=1 and name()='imaginary']]">
+<xsl:template match="m:apply[*[position()=1 and self::m:imaginary]]">
   <mrow>
     <mi><xsl:text disable-output-escaping="yes">&amp;#x02111;</xsl:text><!-- &Im; or &impartl should work--></mi>
     <mo><xsl:text disable-output-escaping="yes"><![CDATA[&ApplyFunction;]]></xsl:text></mo>
@@ -1015,7 +1015,7 @@
 </xsl:template>
 
 <!-- lowest common multiple -->
-<xsl:template match="m:apply[*[position()=1 and name()='lcm']]">
+<xsl:template match="m:apply[*[position()=1 and self::m:lcm]]">
   <mrow>
     <mi>lcm</mi><mo><xsl:text disable-output-escaping="yes"><![CDATA[&ApplyFunction;]]></xsl:text></mo>
     <mfenced>
@@ -1025,12 +1025,12 @@
 </xsl:template>
 
 <!-- floor -->
-<xsl:template match="m:apply[*[position()=1 and name()='floor']]">
+<xsl:template match="m:apply[*[position()=1 and self::m:floor]]">
   <mrow><mo><xsl:text disable-output-escaping="yes"><![CDATA[&LeftFloor;]]></xsl:text></mo><xsl:apply-templates select="*[position()=last()]"/><mo><xsl:text disable-output-escaping="yes"><![CDATA[&RightFloor;]]></xsl:text></mo></mrow>
 </xsl:template>
 
 <!-- ceiling -->
-<xsl:template match="m:apply[*[position()=1 and name()='ceiling']]">
+<xsl:template match="m:apply[*[position()=1 and self::m:ceiling]]">
   <mrow><mo><xsl:text disable-output-escaping="yes"><![CDATA[&LeftCeiling;]]></xsl:text></mo><xsl:apply-templates select="*[position()=last()]"/><mo><xsl:text disable-output-escaping="yes"><![CDATA[&RightCeiling;]]></xsl:text></mo></mrow>
 </xsl:template>
 
@@ -1058,16 +1058,16 @@
   </xsl:choose>
 </xsl:template>
 
-<xsl:template match="m:apply[*[position()=1 and name()='eq']]">
+<xsl:template match="m:apply[*[position()=1 and self::m:eq]]">
   <xsl:call-template name="eqRel"/>
 </xsl:template>
 
-<xsl:template match="m:reln[*[position()=1 and name()='eq']]">
+<xsl:template match="m:reln[*[position()=1 and self::m:eq]]">
   <xsl:call-template name="eqRel"/>
 </xsl:template>
 
 <!-- not equal to -->
-<xsl:template match="m:apply[*[position()=1 and name()='neq']]">
+<xsl:template match="m:apply[*[position()=1 and self::m:neq]]">
   <mrow>
     <xsl:apply-templates select="*[position()=2]"/>
     <mo><xsl:text disable-output-escaping="yes"><![CDATA[&NotEqual;]]></xsl:text></mo>
@@ -1075,7 +1075,7 @@
   </mrow>
 </xsl:template>
 
-<xsl:template match="m:reln[*[position()=1 and name()='neq']]">
+<xsl:template match="m:reln[*[position()=1 and self::m:neq]]">
   <mrow>
     <xsl:apply-templates select="*[position()=2]"/>
     <mo><xsl:text disable-output-escaping="yes"><![CDATA[&NotEqual;]]></xsl:text></mo>
@@ -1105,11 +1105,11 @@
   </xsl:choose>
 </xsl:template>
 
-<xsl:template match="m:apply[*[position()=1 and name()='gt']]">
+<xsl:template match="m:apply[*[position()=1 and self::m:gt]]">
   <xsl:call-template name="gtRel"/>
 </xsl:template>
 
-<xsl:template match="m:reln[*[position()=1 and name()='gt']]">
+<xsl:template match="m:reln[*[position()=1 and self::m:gt]]">
   <xsl:call-template name="gtRel"/>
 </xsl:template>
 
@@ -1135,11 +1135,11 @@
   </xsl:choose>
 </xsl:template>
 
-<xsl:template match="m:apply[*[position()=1 and name()='lt']]">
+<xsl:template match="m:apply[*[position()=1 and self::m:lt]]">
   <xsl:call-template name="ltRel"/>
 </xsl:template>
 
-<xsl:template match="m:reln[*[position()=1 and name()='lt']]">
+<xsl:template match="m:reln[*[position()=1 and self::m:lt]]">
   <xsl:call-template name="ltRel"/>
 </xsl:template>
 
@@ -1165,11 +1165,11 @@
   </xsl:choose>
 </xsl:template>
 
-<xsl:template match="m:apply[*[position()=1 and name()='geq']]">
+<xsl:template match="m:apply[*[position()=1 and self::m:geq]]">
   <xsl:call-template name="geqRel"/>
 </xsl:template>
 
-<xsl:template match="m:reln[*[position()=1 and name()='geq']]">
+<xsl:template match="m:reln[*[position()=1 and self::m:geq]]">
   <xsl:call-template name="geqRel"/>
 </xsl:template>
 
@@ -1195,11 +1195,11 @@
   </xsl:choose>
 </xsl:template>
 
-<xsl:template match="m:apply[*[position()=1 and name()='leq']]">
+<xsl:template match="m:apply[*[position()=1 and self::m:leq]]">
   <xsl:call-template name="leqRel"/>
 </xsl:template>
 
-<xsl:template match="m:reln[*[position()=1 and name()='leq']]">
+<xsl:template match="m:reln[*[position()=1 and self::m:leq]]">
   <xsl:call-template name="leqRel"/>
 </xsl:template>
 
@@ -1225,16 +1225,16 @@
   </xsl:choose>
 </xsl:template>
 
-<xsl:template match="m:apply[*[position()=1 and name()='equivalent']]">
+<xsl:template match="m:apply[*[position()=1 and self::m:equivalent]]">
   <xsl:call-template name="equivRel"/>
 </xsl:template>
 
-<xsl:template match="m:reln[*[position()=1 and name()='equivalent']]">
+<xsl:template match="m:reln[*[position()=1 and self::m:equivalent]]">
   <xsl:call-template name="equivRel"/>
 </xsl:template>
 
 <!-- approximately equal -->
-<xsl:template match="m:apply[*[position()=1 and name()='approx']]">
+<xsl:template match="m:apply[*[position()=1 and self::m:approx]]">
   <mrow>
     <xsl:apply-templates select="*[position()=2]"/>
     <mo><xsl:text disable-output-escaping='yes'>&amp;#x02248;</xsl:text><!-- &TildeTilde; or &approx; should work--></mo>
@@ -1242,7 +1242,7 @@
   </mrow>
 </xsl:template>
 
-<xsl:template match="m:reln[*[position()=1 and name()='approx']]">
+<xsl:template match="m:reln[*[position()=1 and self::m:approx]]">
   <mrow>
     <xsl:apply-templates select="*[position()=2]"/>
     <mo><xsl:text disable-output-escaping='yes'>&amp;#x02248;</xsl:text><!-- &TildeTilde; or &approx; should work--></mo>
@@ -1251,7 +1251,7 @@
 </xsl:template>
 
 <!-- factor of -->
-<xsl:template match="m:apply[*[position()=1 and name()='factorof']]">
+<xsl:template match="m:apply[*[position()=1 and self::m:factorof]]">
   <mrow>
     <xsl:apply-templates select="*[position()=2]"/>
     <mo>|</mo>
@@ -1262,7 +1262,7 @@
 <!-- #################### 4.4.5 #################### -->
 
 <!-- integral -->
-<xsl:template match="m:apply[*[position()=1 and name()='int']]">
+<xsl:template match="m:apply[*[position()=1 and self::m:int]]">
   <mrow>
     <xsl:choose>
     <xsl:when test="m:condition"> <!-- integration domain expressed by a condition-->
@@ -1312,7 +1312,7 @@
 </xsl:template>
 
 <!-- differentiation -->
-<xsl:template match="m:apply[*[position()=1 and name()='diff']]">
+<xsl:template match="m:apply[*[position()=1 and self::m:diff]]">
   <mrow>
   <xsl:choose>
   <xsl:when test="m:bvar/m:degree"> <!-- if the order of the derivative is specified-->
@@ -1320,7 +1320,7 @@
     <xsl:when test="contains(m:bvar/m:degree/m:cn/text(),'1') and string-length(normalize-space(m:bvar/m:degree/m:cn/text()))=1">
       <mfrac>
         <mo>d<!--DifferentialD does not work--></mo>
-	<mrow><mo>d<!--DifferentialD does not work--></mo><xsl:apply-templates select="m:bvar/*[name(.)!='degree']"/></mrow>
+	<mrow><mo>d<!--DifferentialD does not work--></mo><xsl:apply-templates select="m:bvar/*[not(self::m:degree)]"/></mrow>
       </mfrac>
       <mrow>
       <xsl:choose>
@@ -1336,7 +1336,7 @@
     <xsl:otherwise> <!-- if the order of the derivative is not 1-->
       <mfrac>
         <mrow><msup><mo>d<!--DifferentialD does not work--></mo><mrow><xsl:apply-templates select="m:bvar/m:degree"/></mrow></msup></mrow>
-	<mrow><mo>d<!--DifferentialD does not work--></mo><msup><mrow><xsl:apply-templates select="m:bvar/*[name(.)!='degree']"/></mrow><mrow><xsl:apply-templates select="m:bvar/m:degree"/></mrow></msup></mrow>
+	<mrow><mo>d<!--DifferentialD does not work--></mo><msup><mrow><xsl:apply-templates select="m:bvar/*[not(self::m:degree)]"/></mrow><mrow><xsl:apply-templates select="m:bvar/m:degree"/></mrow></msup></mrow>
       </mfrac>
       <mrow>
       <xsl:choose>
@@ -1382,7 +1382,7 @@
 <!-- the latest working draft sets the default rendering of the numerator
 to only one mfrac with one PartialD for the numerator, exponent being the sum
 of every partial diff's orders; not supported yet (I am not sure it is even possible with XSLT)-->
-<xsl:template match="m:apply[*[position()=1 and name()='partialdiff']]">
+<xsl:template match="m:apply[*[position()=1 and self::m:partialdiff]]">
 <mrow>
   <xsl:choose>
     <xsl:when test="m:list">
@@ -1390,7 +1390,7 @@
         <mo>D</mo>
         <mfenced separators="," open="" close=""><xsl:apply-templates select="m:list/*"/></mfenced>
       </msub>
-      <mfenced open="(" close=")"><xsl:apply-templates select="*[name()!='list']"/></mfenced>
+      <mfenced open="(" close=")"><xsl:apply-templates select="*[not(self::m:list)]"/></mfenced>
     </xsl:when>
     <xsl:otherwise>
       <xsl:for-each select="m:bvar">
@@ -1400,13 +1400,13 @@
         <xsl:when test="contains(m:degree/m:cn/text(),'1') and string-length(normalize-space(m:degree/m:cn/text()))=1">
           <mfrac>
             <mrow><mo><xsl:text disable-output-escaping="yes"><![CDATA[&PartialD;]]></xsl:text></mo></mrow>  
-	    <mrow><mo><xsl:text disable-output-escaping="yes"><![CDATA[&PartialD;]]></xsl:text></mo><xsl:apply-templates select="*[name(.)!='degree']"/></mrow>
+	    <mrow><mo><xsl:text disable-output-escaping="yes"><![CDATA[&PartialD;]]></xsl:text></mo><xsl:apply-templates select="*[not(self::m:degree)]"/></mrow>
           </mfrac>
         </xsl:when>
         <xsl:otherwise> <!-- if the order of the derivative is not 1-->
           <mfrac>
             <mrow><msup><mrow><mo><xsl:text disable-output-escaping="yes"><![CDATA[&PartialD;]]></xsl:text></mo></mrow><mrow><xsl:apply-templates select="m:degree"/></mrow></msup></mrow>
-  	    <mrow><mrow><mo><xsl:text disable-output-escaping="yes"><![CDATA[&PartialD;]]></xsl:text></mo></mrow><msup><mrow><xsl:apply-templates select="*[name(.)!='degree']"/></mrow><mrow><xsl:apply-templates select="m:degree"/></mrow></msup></mrow>
+  	    <mrow><mrow><mo><xsl:text disable-output-escaping="yes"><![CDATA[&PartialD;]]></xsl:text></mo></mrow><msup><mrow><xsl:apply-templates select="*[not(self::m:degree)]"/></mrow><mrow><xsl:apply-templates select="m:degree"/></mrow></msup></mrow>
           </mfrac>
         </xsl:otherwise>
         </xsl:choose>
@@ -1435,11 +1435,11 @@
 </xsl:template>
 
 <!-- divergence -->
-<xsl:template match="m:apply[*[position()=1 and name()='divergence']]">
+<xsl:template match="m:apply[*[position()=1 and self::m:divergence]]">
 <mrow>
   <mi>div</mi>
   <xsl:choose>
-  <xsl:when test="name(*[position()=2])='apply' or ((name(*[position()=2])='ci' or name(*[position()=2])='cn') and contains(*[position()=2]/text(),'-'))">
+  <xsl:when test="*[position()=2 and self::m:apply] or (*[position()=2 and (self::m:ci or self::m:cn)] and contains(*[position()=2]/text(),'-'))">
     <mfenced separators="">
       <xsl:apply-templates select="*[position()=2]"/>
     </mfenced>
@@ -1452,11 +1452,11 @@
 </xsl:template>
 
 <!-- gradient -->
-<xsl:template match="m:apply[*[position()=1 and name()='grad']]">
+<xsl:template match="m:apply[*[position()=1 and self::m:grad]]">
 <mrow>
   <mi>grad</mi>
   <xsl:choose>
-  <xsl:when test="name(*[position()=2])='apply' or ((name(*[position()=2])='ci' or name(*[position()=2])='cn') and contains(*[position()=2]/text(),'-'))">
+  <xsl:when test="*[position()=2 and self::m:apply] or (*[position()=2 and (self::m:ci or self::m:cn)] and contains(*[position()=2]/text(),'-'))">
     <mfenced separators="">
       <xsl:apply-templates select="*[position()=2]"/>
     </mfenced>
@@ -1469,11 +1469,11 @@
 </xsl:template>
 
 <!-- vector calculus curl -->
-<xsl:template match="m:apply[*[position()=1 and name()='curl']]">
+<xsl:template match="m:apply[*[position()=1 and self::m:curl]]">
 <mrow>
   <mi>curl</mi>
   <xsl:choose>
-  <xsl:when test="name(*[position()=2])='apply' or ((name(*[position()=2])='ci' or name(*[position()=2])='cn') and contains(*[position()=2]/text(),'-'))">
+  <xsl:when test="*[position()=2 and self::m:apply] or (*[position()=2 and (self::m:ci or self::m:cn)] and contains(*[position()=2]/text(),'-'))">
     <mfenced separators="">
       <xsl:apply-templates select="*[position()=2]"/>
     </mfenced>
@@ -1486,14 +1486,14 @@
 </xsl:template>
 
 <!-- laplacian -->
-<xsl:template match="m:apply[*[position()=1 and name()='laplacian']]">
+<xsl:template match="m:apply[*[position()=1 and self::m:laplacian]]">
 <mrow>
   <msup>
     <mo><xsl:text disable-output-escaping='yes'>&amp;#x02207;</xsl:text></mo>  <!-- Del or nabla should work-->
     <mn>2</mn>
   </msup>
   <xsl:choose>
-  <xsl:when test="name(*[position()=2])='apply' or ((name(*[position()=2])='ci' or name(*[position()=2])='cn') and contains(*[position()=2]/text(),'-'))">
+  <xsl:when test="*[position()=2 and self::m:apply] or (*[position()=2 and (self::m:ci or self::m:cn)] and contains(*[position()=2]/text(),'-'))">
     <mfenced separators="">
       <xsl:apply-templates select="*[position()=2]"/>
     </mfenced>
@@ -1543,7 +1543,7 @@
 </xsl:template>
 
 <!-- union -->
-<xsl:template match="m:apply[*[position()=1 and name()='union']]">
+<xsl:template match="m:apply[*[position()=1 and self::m:union]]">
 <mrow>
   <xsl:choose>
   <xsl:when test="count(*)>=3">
@@ -1563,7 +1563,7 @@
 </xsl:template>
 
 <!-- intersection -->
-<xsl:template match="m:apply[*[position()=1 and name()='intersect']]">
+<xsl:template match="m:apply[*[position()=1 and self::m:intersect]]">
 <mrow>
   <xsl:choose>
   <xsl:when test="count(*)>=3">
@@ -1590,7 +1590,7 @@
 </xsl:template>
 
 <!-- inclusion -->
-<xsl:template match="m:apply[*[position()=1 and name()='in']]">
+<xsl:template match="m:apply[*[position()=1 and self::m:in]]">
 <mrow>
   <xsl:apply-templates select="*[position()=2]"/>
   <mo><xsl:text disable-output-escaping="yes"><![CDATA[&isin;]]></xsl:text></mo>
@@ -1598,7 +1598,7 @@
 </mrow>
 </xsl:template>
 
-<xsl:template match="m:reln[*[position()=1 and name()='in']]">
+<xsl:template match="m:reln[*[position()=1 and self::m:in]]">
 <mrow>
   <xsl:apply-templates select="*[position()=2]"/>
   <mo><xsl:text disable-output-escaping="yes"><![CDATA[&isin;]]></xsl:text></mo>
@@ -1607,7 +1607,7 @@
 </xsl:template>
 
 <!-- exclusion -->
-<xsl:template match="m:apply[*[position()=1 and name()='notin']]">
+<xsl:template match="m:apply[*[position()=1 and self::m:notin]]">
 <mrow>
   <xsl:apply-templates select="*[position()=2]"/>
   <mo><xsl:text disable-output-escaping="yes"><![CDATA[&notin;]]></xsl:text></mo>
@@ -1615,7 +1615,7 @@
 </mrow>
 </xsl:template>
 
-<xsl:template match="m:reln[*[position()=1 and name()='notin']]">
+<xsl:template match="m:reln[*[position()=1 and self::m:notin]]">
 <mrow>
   <xsl:apply-templates select="*[position()=2]"/>
   <mo><xsl:text disable-output-escaping="yes"><![CDATA[&notin;]]></xsl:text></mo>
@@ -1643,11 +1643,11 @@
 </mrow>
 </xsl:template>
 
-<xsl:template match="m:apply[*[position()=1 and name()='subset']]">
+<xsl:template match="m:apply[*[position()=1 and self::m:subset]]">
   <xsl:call-template name="subsetRel"/>
 </xsl:template>
 
-<xsl:template match="m:reln[*[position()=1 and name()='subset']]">
+<xsl:template match="m:reln[*[position()=1 and self::m:subset]]">
   <xsl:call-template name="subsetRel"/>
 </xsl:template>
 
@@ -1671,18 +1671,18 @@
 </mrow>
 </xsl:template>
 
-<xsl:template match="m:apply[*[position()=1 and name()='prsubset']]">
+<xsl:template match="m:apply[*[position()=1 and self::m:prsubset]]">
   <xsl:call-template name="prsubsetRel"/>
 </xsl:template>
 
-<xsl:template match="m:reln[*[position()=1 and name()='prsubset']]">
+<xsl:template match="m:reln[*[position()=1 and self::m:prsubset]]">
   <xsl:call-template name="prsubsetRel"/>
 </xsl:template>
 
 <!-- perhaps Subset and SubsetEqual signs are used in place of one another ; not according to the spec -->
 
 <!-- containment (not subset of)-->
-<xsl:template match="m:apply[*[position()=1 and name()='notsubset']]">
+<xsl:template match="m:apply[*[position()=1 and self::m:notsubset]]">
 <mrow>
   <xsl:apply-templates select="*[position()=2]"/>
   <mo><xsl:text disable-output-escaping="yes"><![CDATA[&NotSubset;]]></xsl:text></mo>
@@ -1690,7 +1690,7 @@
 </mrow>
 </xsl:template>
 
-<xsl:template match="m:reln[*[position()=1 and name()='notsubset']]">
+<xsl:template match="m:reln[*[position()=1 and self::m:notsubset]]">
 <mrow>
   <xsl:apply-templates select="*[position()=2]"/>
   <mo><xsl:text disable-output-escaping="yes"><![CDATA[&NotSubset;]]></xsl:text></mo>
@@ -1699,7 +1699,7 @@
 </xsl:template>
 
 <!-- containment (not proper subset of) -->
-<xsl:template match="m:apply[*[position()=1 and name()='notprsubset']]">
+<xsl:template match="m:apply[*[position()=1 and self::m:notprsubset]]">
 <mrow>
   <xsl:apply-templates select="*[position()=2]"/>
   <mo><xsl:text disable-output-escaping="yes"><![CDATA[&NotSubsetEqual;]]></xsl:text></mo>  <!-- does not work, perhaps nsube, or nsubE, or nsubseteqq or nsubseteq, UNICODE x02288-->
@@ -1707,7 +1707,7 @@
 </mrow>
 </xsl:template>
 
-<xsl:template match="m:reln[*[position()=1 and name()='notprsubset']]">
+<xsl:template match="m:reln[*[position()=1 and self::m:notprsubset]]">
 <mrow>
   <xsl:apply-templates select="*[position()=2]"/>
   <mo><xsl:text disable-output-escaping="yes"><![CDATA[&NotSubsetEqual;]]></xsl:text></mo>  <!-- does not work, perhaps nsube, or nsubE, or nsubseteqq or nsubseteq, UNICODE x02288-->
@@ -1716,7 +1716,7 @@
 </xsl:template>
 
 <!-- difference of two sets -->
-<xsl:template match="m:apply[*[position()=1 and name()='setdiff']]">
+<xsl:template match="m:apply[*[position()=1 and self::m:setdiff]]">
 <mrow>
   <xsl:apply-templates select="*[position()=2]"/>
   <mo><xsl:text disable-output-escaping="yes"><![CDATA[&Backslash;]]></xsl:text></mo>
@@ -1725,12 +1725,12 @@
 </xsl:template>
 
 <!-- cardinality -->
-<xsl:template match="m:apply[*[position()=1 and name()='card']]">
+<xsl:template match="m:apply[*[position()=1 and self::m:card]]">
   <mrow><mo>|</mo><xsl:apply-templates select="*[position()=last()]"/><mo>|</mo></mrow>
 </xsl:template>
 
 <!-- cartesian product -->
-<xsl:template match="m:apply[*[position()=1 and name()='cartesianproduct']]">
+<xsl:template match="m:apply[*[position()=1 and self::m:cartesianproduct]]">
 <xsl:choose>
 <xsl:when test="count(*)>=3">
   <mrow>
@@ -1742,7 +1742,7 @@
       <xsl:when test="m:minus"> <!--add brackets around - children for priority purpose-->
         <mfenced separators=""><xsl:apply-templates select="."/></mfenced><mo><xsl:text disable-output-escaping="yes"><![CDATA[&times;]]></xsl:text></mo>
       </xsl:when>
-      <xsl:when test="(name(.)='ci' or name(.)='cn') and contains(text(),'-')"> <!-- have to do it using contains because starts-with doesn't seem to work well in XT-->
+      <xsl:when test="(self::m:ci or self::m:cn) and contains(text(),'-')"> <!-- have to do it using contains because starts-with doesn't seem to work well in XT-->
         <mfenced separators=""><xsl:apply-templates select="."/></mfenced><mo><xsl:text disable-output-escaping="yes"><![CDATA[&times;]]></xsl:text></mo>
       </xsl:when>
       <xsl:otherwise>
@@ -1758,7 +1758,7 @@
       <xsl:when test="m:minus">
         <mfenced separators=""><xsl:apply-templates select="."/></mfenced>
       </xsl:when>
-      <xsl:when test="(name(.)='ci' or name(.)='cn') and contains(text(),'-')"> <!-- have to do it using contains because starts-with doesn't seem to work well in  XT-->
+      <xsl:when test="(self::m:ci or self::m:cn) and contains(text(),'-')"> <!-- have to do it using contains because starts-with doesn't seem to work well in  XT-->
         <mfenced separators=""><xsl:apply-templates select="."/></mfenced>
       </xsl:when>
       <xsl:otherwise>
@@ -1778,7 +1778,7 @@
       <xsl:when test="m:minus">
         <mfenced separators=""><xsl:apply-templates select="*[position()=2]"/></mfenced>
       </xsl:when>
-      <xsl:when test="(*[position()=2 and self::m:ci] or *[position()=2 and self::m:cn]) and contains(*[position()=2]/text(),'-')">
+      <xsl:when test="*[position()=2 and (self::m:ci or self::m:cn)] and contains(*[position()=2]/text(),'-')">
         <mfenced separators=""><xsl:apply-templates select="*[position()=2]"/></mfenced>
       </xsl:when>
       <xsl:otherwise>
@@ -1796,7 +1796,7 @@
 <!-- #################### 4.4.7 #################### -->
 
 <!-- sum -->
-<xsl:template match="m:apply[*[position()=1 and name()='sum']]">
+<xsl:template match="m:apply[*[position()=1 and self::m:sum]]">
 <mrow>
   <xsl:choose>
   <xsl:when test="m:condition">  <!-- domain specified by a condition -->
@@ -1825,7 +1825,7 @@
 </xsl:template>
 
 <!-- product -->
-<xsl:template match="m:apply[*[position()=1 and name()='product']]">
+<xsl:template match="m:apply[*[position()=1 and self::m:product]]">
 <mrow>
   <xsl:choose>
   <xsl:when test="m:condition">   <!-- domain specified by a condition -->
@@ -1854,7 +1854,7 @@
 </xsl:template>
 
 <!-- limit -->
-<xsl:template match="m:apply[*[position()=1 and name()='limit']]">
+<xsl:template match="m:apply[*[position()=1 and self::m:limit]]">
 <mrow>
   <xsl:choose>
   <xsl:when test="m:condition">
@@ -1898,11 +1898,11 @@
 </mrow>
 </xsl:template>
 
-<xsl:template match="m:apply[*[position()=1 and name()='tendsto']]">
+<xsl:template match="m:apply[*[position()=1 and self::m:tendsto]]">
   <xsl:call-template name="tendstoRel"/>
 </xsl:template>
 
-<xsl:template match="m:reln[*[position()=1 and name()='tendsto']]">
+<xsl:template match="m:reln[*[position()=1 and self::m:tendsto]]">
   <xsl:call-template name="tendstoRel"/>
 </xsl:template>
 
@@ -1914,7 +1914,7 @@
   <xsl:param name="func">sin</xsl:param> <!-- provide sin as default function in case none is provided (this should never occur)-->
   <mi><xsl:value-of select="$func"/></mi><mo><xsl:text disable-output-escaping="yes"><![CDATA[&ApplyFunction;]]></xsl:text></mo>
   <xsl:choose>
-  <xsl:when test="name(*[position()=2])='apply' or ((name(*[position()=2])='ci' or name(*[position()=2])='cn') and contains(*[position()=2]/text(),'-'))">
+  <xsl:when test="*[position()=2 and self::m:apply] or (*[position()=2 and (self::m:ci or self::m:cn)] and contains(*[position()=2]/text(),'-'))">
     <mfenced separators="">
     <xsl:apply-templates select="*[position()=2]"/>
     </mfenced>
@@ -1927,287 +1927,287 @@
 </xsl:template>
 
 <!-- trigonometric function: sine -->
-<xsl:template match="m:apply[*[position()=1 and name()='sin']]">
+<xsl:template match="m:apply[*[position()=1 and self::m:sin]]">
   <xsl:call-template name="trigo">
     <xsl:with-param name="func">sin</xsl:with-param>
   </xsl:call-template>
 </xsl:template>
 
-<xsl:template match="m:sin[name(preceding-sibling::*[position()=last()])='compose' or name(preceding-sibling::*[position()=last()])='inverse']">
+<xsl:template match="m:sin[preceding-sibling::*[position()=last() and (self::m:compose or self::m:inverse)]]">
   <mi>sin</mi>  <!-- used with inverse or composition-->
 </xsl:template>
 
 <!-- trigonometric function: cosine -->
-<xsl:template match="m:apply[*[position()=1 and name()='cos']]">
+<xsl:template match="m:apply[*[position()=1 and self::m:cos]]">
   <xsl:call-template name="trigo">
     <xsl:with-param name="func">cos</xsl:with-param>
   </xsl:call-template>
 </xsl:template>
 
-<xsl:template match="m:cos[name(preceding-sibling::*[position()=last()])='compose' or name(preceding-sibling::*[position()=last()])='inverse']">
+<xsl:template match="m:cos[preceding-sibling::*[position()=last() and (self::m:compose or self::m:inverse)]]">
   <mi>cos</mi>   <!-- used with inverse or composition-->
 </xsl:template>
 
 <!-- trigonometric function: tan -->
-<xsl:template match="m:apply[*[position()=1 and name()='tan']]">
+<xsl:template match="m:apply[*[position()=1 and self::m:tan]]">
   <xsl:call-template name="trigo">
     <xsl:with-param name="func">tan</xsl:with-param>   
   </xsl:call-template>
 </xsl:template>
 
-<xsl:template match="m:tan[name(preceding-sibling::*[position()=last()])='compose' or name(preceding-sibling::*[position()=last()])='inverse']">
+<xsl:template match="m:tan[preceding-sibling::*[position()=last() and (self::m:compose or self::m:inverse)]]">
   <mi>tan</mi>   <!-- used with inverse or composition-->
 </xsl:template>
 
 <!-- trigonometric function: sec -->
-<xsl:template match="m:apply[*[position()=1 and name()='sec']]">
+<xsl:template match="m:apply[*[position()=1 and self::m:sec]]">
   <xsl:call-template name="trigo">
     <xsl:with-param name="func">sec</xsl:with-param>  
   </xsl:call-template>
 </xsl:template>
 
-<xsl:template match="m:sec[name(preceding-sibling::*[position()=last()])='compose' or name(preceding-sibling::*[position()=last()])='inverse']">
+<xsl:template match="m:sec[preceding-sibling::*[position()=last() and (self::m:compose or self::m:inverse)]]">
   <mi>sec</mi>   <!-- used with inverse or composition-->
 </xsl:template>
 
 <!-- trigonometric function: csc -->
-<xsl:template match="m:apply[*[position()=1 and name()='csc']]">
+<xsl:template match="m:apply[*[position()=1 and self::m:csc]]">
   <xsl:call-template name="trigo">
     <xsl:with-param name="func">csc</xsl:with-param>    
   </xsl:call-template>
 </xsl:template>
 
-<xsl:template match="m:csc[name(preceding-sibling::*[position()=last()])='compose' or name(preceding-sibling::*[position()=last()])='inverse']">
+<xsl:template match="m:csc[preceding-sibling::*[position()=last() and (self::m:compose or self::m:inverse)]]">
   <mi>csc</mi>   <!-- used with inverse or composition-->
 </xsl:template>
 
 <!-- trigonometric function: cotan -->
-<xsl:template match="m:apply[*[position()=1 and name()='cot']]">
+<xsl:template match="m:apply[*[position()=1 and self::m:cot]]">
   <xsl:call-template name="trigo">
     <xsl:with-param name="func">cot</xsl:with-param>    
   </xsl:call-template>
 </xsl:template>
 
-<xsl:template match="m:cot[name(preceding-sibling::*[position()=last()])='compose' or name(preceding-sibling::*[position()=last()])='inverse']">
+<xsl:template match="m:cot[preceding-sibling::*[position()=last() and (self::m:compose or self::m:inverse)]]">
   <mi>cot</mi>   <!-- used with inverse or composition-->
 </xsl:template>
 
 <!-- trigonometric function: hyperbolic sin -->
-<xsl:template match="m:apply[*[position()=1 and name()='sinh']]">
+<xsl:template match="m:apply[*[position()=1 and self::m:sinh]]">
   <xsl:call-template name="trigo">
     <xsl:with-param name="func">sinh</xsl:with-param>    
   </xsl:call-template>
 </xsl:template>
 
-<xsl:template match="m:sinh[name(preceding-sibling::*[position()=last()])='compose' or name(preceding-sibling::*[position()=last()])='inverse']">
+<xsl:template match="m:sinh[preceding-sibling::*[position()=last() and (self::m:compose or self::m:inverse)]]">
   <mi>sinh</mi>   <!-- used with inverse or composition-->
 </xsl:template>
 
 <!-- trigonometric function: hyperbolic cos -->
-<xsl:template match="m:apply[*[position()=1 and name()='cosh']]">
+<xsl:template match="m:apply[*[position()=1 and self::m:cosh]]">
   <xsl:call-template name="trigo">
     <xsl:with-param name="func">cosh</xsl:with-param>    
   </xsl:call-template>
 </xsl:template>
 
-<xsl:template match="m:cosh[name(preceding-sibling::*[position()=last()])='compose' or name(preceding-sibling::*[position()=last()])='inverse']">
+<xsl:template match="m:cosh[preceding-sibling::*[position()=last() and (self::m:compose or self::m:inverse)]]">
   <mi>cosh</mi>   <!-- used with inverse or composition-->
 </xsl:template>
 
 <!-- trigonometric function: hyperbolic tan -->
-<xsl:template match="m:apply[*[position()=1 and name()='tanh']]">
+<xsl:template match="m:apply[*[position()=1 and self::m:tanh]]">
   <xsl:call-template name="trigo">
     <xsl:with-param name="func">tanh</xsl:with-param>    
   </xsl:call-template>
 </xsl:template>
 
-<xsl:template match="m:tanh[name(preceding-sibling::*[position()=last()])='compose' or name(preceding-sibling::*[position()=last()])='inverse']">
+<xsl:template match="m:tanh[preceding-sibling::*[position()=last() and (self::m:compose or self::m:inverse)]]">
   <mi>tanh</mi>   <!-- used with inverse or composition-->
 </xsl:template>
 
 <!-- trigonometric function: hyperbolic sec -->
-<xsl:template match="m:apply[*[position()=1 and name()='sech']]">
+<xsl:template match="m:apply[*[position()=1 and self::m:sech]]">
   <xsl:call-template name="trigo">
     <xsl:with-param name="func">sech</xsl:with-param>    
   </xsl:call-template>
 </xsl:template>
 
-<xsl:template match="m:sech[name(preceding-sibling::*[position()=last()])='compose' or name(preceding-sibling::*[position()=last()])='inverse']">
+<xsl:template match="m:sech[preceding-sibling::*[position()=last() and (self::m:compose or self::m:inverse)]]">
   <mi>sech</mi>   <!-- used with inverse or composition-->
 </xsl:template>
 
 <!-- trigonometric function: hyperbolic csc -->
-<xsl:template match="m:apply[*[position()=1 and name()='csch']]">
+<xsl:template match="m:apply[*[position()=1 and self::m:csch]]">
   <xsl:call-template name="trigo">
     <xsl:with-param name="func">csch</xsl:with-param>   
   </xsl:call-template>
 </xsl:template>
 
-<xsl:template match="m:csch[name(preceding-sibling::*[position()=last()])='compose' or name(preceding-sibling::*[position()=last()])='inverse']">
+<xsl:template match="m:csch[preceding-sibling::*[position()=last() and (self::m:compose or self::m:inverse)]]">
   <mi>csch</mi>   <!-- used with inverse or composition-->
 </xsl:template>
 
 <!-- trigonometric function: hyperbolic cotan -->
-<xsl:template match="m:apply[*[position()=1 and name()='coth']]">
+<xsl:template match="m:apply[*[position()=1 and self::m:coth]]">
   <xsl:call-template name="trigo">
     <xsl:with-param name="func">coth</xsl:with-param>   
   </xsl:call-template>
 </xsl:template>
 
-<xsl:template match="m:coth[name(preceding-sibling::*[position()=last()])='compose' or name(preceding-sibling::*[position()=last()])='inverse']">
+<xsl:template match="m:coth[preceding-sibling::*[position()=last() and (self::m:compose or self::m:inverse)]]">
   <mi>coth</mi>   <!-- used with inverse or composition-->
 </xsl:template>
 
 <!-- trigonometric function: arc sine -->
-<xsl:template match="m:apply[*[position()=1 and name()='arcsin']]">
+<xsl:template match="m:apply[*[position()=1 and self::m:arcsin]]">
   <xsl:call-template name="trigo">
     <xsl:with-param name="func">arcsin</xsl:with-param>    
   </xsl:call-template>
 </xsl:template>
 
-<xsl:template match="m:arcsin[name(preceding-sibling::*[position()=last()])='compose' or name(preceding-sibling::*[position()=last()])='inverse']">
+<xsl:template match="m:arcsin[preceding-sibling::*[position()=last() and (self::m:compose or self::m:inverse)]]">
   <mi>arcsin</mi>   <!-- used with inverse or composition-->
 </xsl:template>
 
 <!-- trigonometric function: arc cosine -->
-<xsl:template match="m:apply[*[position()=1 and name()='arccos']]">
+<xsl:template match="m:apply[*[position()=1 and self::m:arccos]]">
   <xsl:call-template name="trigo">
     <xsl:with-param name="func">arccos</xsl:with-param>    
   </xsl:call-template>
 </xsl:template>
 
-<xsl:template match="m:arccos[name(preceding-sibling::*[position()=last()])='compose' or name(preceding-sibling::*[position()=last()])='inverse']">
+<xsl:template match="m:arccos[preceding-sibling::*[position()=last() and (self::m:compose or self::m:inverse)]]">
   <mi>arccos</mi>   <!-- used with inverse or composition-->
 </xsl:template>
 
 <!-- trigonometric function: arc tan -->
-<xsl:template match="m:apply[*[position()=1 and name()='arctan']]">
+<xsl:template match="m:apply[*[position()=1 and self::m:arctan]]">
   <xsl:call-template name="trigo">
     <xsl:with-param name="func">arctan</xsl:with-param>    
   </xsl:call-template>
 </xsl:template>
 
-<xsl:template match="m:arctan[name(preceding-sibling::*[position()=last()])='compose' or name(preceding-sibling::*[position()=last()])='inverse']">
+<xsl:template match="m:arctan[preceding-sibling::*[position()=last() and (self::m:compose or self::m:inverse)]]">
   <mi>arctan</mi>   <!-- used with inverse or composition-->
 </xsl:template>
 
 <!-- trigonometric function: arc sec -->
-<xsl:template match="m:apply[*[position()=1 and name()='arcsec']]">
+<xsl:template match="m:apply[*[position()=1 and self::m:arcsec]]">
   <xsl:call-template name="trigo">
     <xsl:with-param name="func">arcsec</xsl:with-param>    
   </xsl:call-template>
 </xsl:template>
 
-<xsl:template match="m:arcsec[name(preceding-sibling::*[position()=last()])='compose' or name(preceding-sibling::*[position()=last()])='inverse']">
+<xsl:template match="m:arcsec[preceding-sibling::*[position()=last() and (self::m:compose or self::m:inverse)]]">
   <mi>arcsec</mi>   <!-- used with inverse or composition-->
 </xsl:template>
 
 <!-- trigonometric function: arc csc -->
-<xsl:template match="m:apply[*[position()=1 and name()='arccsc']]">
+<xsl:template match="m:apply[*[position()=1 and self::m:arccsc]]">
   <xsl:call-template name="trigo">
     <xsl:with-param name="func">arccsc</xsl:with-param>    
   </xsl:call-template>
 </xsl:template>
 
-<xsl:template match="m:arccsc[name(preceding-sibling::*[position()=last()])='compose' or name(preceding-sibling::*[position()=last()])='inverse']">
+<xsl:template match="m:arccsc[preceding-sibling::*[position()=last() and (self::m:compose or self::m:inverse)]]">
   <mi>arccsc</mi>   <!-- used with inverse or composition-->
 </xsl:template>
 
 <!-- trigonometric function: arc cotan -->
-<xsl:template match="m:apply[*[position()=1 and name()='arccot']]">
+<xsl:template match="m:apply[*[position()=1 and self::m:arccot]]">
   <xsl:call-template name="trigo">
     <xsl:with-param name="func">arccot</xsl:with-param>    
   </xsl:call-template>
 </xsl:template>
 
-<xsl:template match="m:arccot[name(preceding-sibling::*[position()=last()])='compose' or name(preceding-sibling::*[position()=last()])='inverse']">
+<xsl:template match="m:arccot[preceding-sibling::*[position()=last() and (self::m:compose or self::m:inverse)]]">
   <mi>arccot</mi>   <!-- used with inverse or composition-->
 </xsl:template>
 
 <!-- trigonometric function: arc sinh -->
-<xsl:template match="m:apply[*[position()=1 and name()='arcsinh']]">
+<xsl:template match="m:apply[*[position()=1 and self::m:arcsinh]]">
   <xsl:call-template name="trigo">
     <xsl:with-param name="func">arcsinh</xsl:with-param>
   </xsl:call-template>
 </xsl:template>
 
-<xsl:template match="m:arcsinh[name(preceding-sibling::*[position()=last()])='compose' or name(preceding-sibling::*[position()=last()])='inverse']">
+<xsl:template match="m:arcsinh[preceding-sibling::*[position()=last() and (self::m:compose or self::m:inverse)]]">
   <mi>arcsinh</mi>   <!-- used with inverse or composition-->
 </xsl:template>
 
 <!-- trigonometric function: arc cosh -->
-<xsl:template match="m:apply[*[position()=1 and name()='arccosh']]">
+<xsl:template match="m:apply[*[position()=1 and self::m:arccosh]]">
   <xsl:call-template name="trigo">
     <xsl:with-param name="func">arccosh</xsl:with-param>    
   </xsl:call-template>
 </xsl:template>
 
-<xsl:template match="m:arccosh[name(preceding-sibling::*[position()=last()])='compose' or name(preceding-sibling::*[position()=last()])='inverse']">
+<xsl:template match="m:arccosh[preceding-sibling::*[position()=last() and (self::m:compose or self::m:inverse)]]">
   <mi>arccosh</mi>   <!-- used with inverse or composition-->
 </xsl:template>
 
 <!-- trigonometric function: arc tanh -->
-<xsl:template match="m:apply[*[position()=1 and name()='arctanh']]">
+<xsl:template match="m:apply[*[position()=1 and self::m:arctanh]]">
   <xsl:call-template name="trigo">
     <xsl:with-param name="func">arctanh</xsl:with-param>    
   </xsl:call-template>
 </xsl:template>
 
-<xsl:template match="m:arctanh[name(preceding-sibling::*[position()=last()])='compose' or name(preceding-sibling::*[position()=last()])='inverse']">
+<xsl:template match="m:arctanh[preceding-sibling::*[position()=last() and (self::m:compose or self::m:inverse)]]">
   <mi>arctanh</mi>   <!-- used with inverse or composition-->
 </xsl:template>
 
 <!-- trigonometric function: arc sech -->
-<xsl:template match="m:apply[*[position()=1 and name()='arcsech']]">
+<xsl:template match="m:apply[*[position()=1 and self::m:arcsech]]">
   <xsl:call-template name="trigo">
     <xsl:with-param name="func">arcsech</xsl:with-param>    
   </xsl:call-template>
 </xsl:template>
 
-<xsl:template match="m:arcsech[name(preceding-sibling::*[position()=last()])='compose' or name(preceding-sibling::*[position()=last()])='inverse']">
+<xsl:template match="m:arcsech[preceding-sibling::*[position()=last() and (self::m:compose or self::m:inverse)]]">
   <mi>arcsech</mi>   <!-- used with inverse or composition-->
 </xsl:template>
 
 <!-- trigonometric function: arc csch -->
-<xsl:template match="m:apply[*[position()=1 and name()='arccsch']]">
+<xsl:template match="m:apply[*[position()=1 and self::m:arccsch]]">
   <xsl:call-template name="trigo">
     <xsl:with-param name="func">arccsch</xsl:with-param>    
   </xsl:call-template>
 </xsl:template>
 
-<xsl:template match="m:arccsch[name(preceding-sibling::*[position()=last()])='compose' or name(preceding-sibling::*[position()=last()])='inverse']">
+<xsl:template match="m:arccsch[preceding-sibling::*[position()=last() and (self::m:compose or self::m:inverse)]]">
   <mi>arccsch</mi>   <!-- used with inverse or composition-->
 </xsl:template>
 
 <!-- trigonometric function: arc coth -->
-<xsl:template match="m:apply[*[position()=1 and name()='arccoth']]">
+<xsl:template match="m:apply[*[position()=1 and self::m:arccoth]]">
   <xsl:call-template name="trigo">
     <xsl:with-param name="func">arccoth</xsl:with-param>   
   </xsl:call-template>
 </xsl:template>
 
-<xsl:template match="m:arccoth[name(preceding-sibling::*[position()=last()])='compose' or name(preceding-sibling::*[position()=last()])='inverse']">
+<xsl:template match="m:arccoth[preceding-sibling::*[position()=last() and (self::m:compose or self::m:inverse)]]">
   <mi>arccoth</mi>   <!-- used with inverse or composition-->
 </xsl:template>
 
 <!-- exponential -->
-<xsl:template match="m:apply[*[position()=1 and name()='exp']]">
+<xsl:template match="m:apply[*[position()=1 and self::m:exp]]">
   <msup>
     <mi><xsl:text disable-output-escaping="yes"><![CDATA[&ee;]]></xsl:text></mi>   <!-- ExponentialE does not work yet -->
     <xsl:apply-templates select="*[position()=2]"/>
   </msup>
 </xsl:template>
 
-<xsl:template match="m:exp[name(preceding-sibling::*[position()=last()])='compose' or name(preceding-sibling::*[position()=last()])='inverse']">
+<xsl:template match="m:exp[preceding-sibling::*[position()=last() and (self::m:compose or self::m:inverse)]]">
   <mi><xsl:text disable-output-escaping="yes"><![CDATA[&ExponentialE;]]></xsl:text></mi>   <!-- used with inverse or composition; not sure it is appropriate for exponential-->
 </xsl:template>
 
 <!-- natural logarithm -->
-<xsl:template match="m:apply[*[position()=1 and name()='ln']]">
+<xsl:template match="m:apply[*[position()=1 and self::m:ln]]">
 <mrow>
   <mi>ln</mi><mo><xsl:text disable-output-escaping="yes"><![CDATA[&ApplyFunction;]]></xsl:text></mo>
   <xsl:choose>
-  <xsl:when test="name(*[position()=2])='apply' or ((name(*[position()=2])='ci' or name(*[position()=2])='cn') and contains(*[position()=2]/text(),'-'))">
+  <xsl:when test="*[position()=2 and self::m:apply] or (*[position()=2 and (self::m:ci or self::m:cn)] and contains(*[position()=2]/text(),'-'))">
     <mfenced separators="">
       <xsl:apply-templates select="*[position()=2]"/>
     </mfenced>
@@ -2219,12 +2219,12 @@
 </mrow>
 </xsl:template>
 
-<xsl:template match="m:ln[name(preceding-sibling::*[position()=last()])='compose' or name(preceding-sibling::*[position()=last()])='inverse']">
+<xsl:template match="m:ln[preceding-sibling::*[position()=last() and (self::m:compose or self::m:inverse)]]">
   <mi>ln</mi>   <!-- used with inverse or composition-->
 </xsl:template>
 
 <!-- logarithm to a given base (default 10)-->
-<xsl:template match="m:apply[*[position()=1 and name()='log']]">
+<xsl:template match="m:apply[*[position()=1 and self::m:log]]">
 <mrow>
   <xsl:choose>
   <xsl:when test="m:logbase">
@@ -2234,7 +2234,7 @@
     </msub>
     <mo><xsl:text disable-output-escaping="yes"><![CDATA[&ApplyFunction;]]></xsl:text></mo>
     <xsl:choose>
-    <xsl:when test="name(*[position()=3])='apply' or ((name(*[position()=3])='ci' or name(*[position()=3])='cn') and contains(*[position()=3]/text(),'-'))">
+    <xsl:when test="*[position()=3 and self::m:apply] or (*[position()=3 and (self::m:ci or self::m:cn)] and contains(*[position()=3]/text(),'-'))">
       <mfenced separators="">
         <xsl:apply-templates select="*[position()=3]"/>
       </mfenced>
@@ -2251,7 +2251,7 @@
     </msub>
     <mo><xsl:text disable-output-escaping="yes"><![CDATA[&ApplyFunction;]]></xsl:text></mo>
     <xsl:choose>
-    <xsl:when test="name(*[position()=2])='apply' or ((name(*[position()=2])='ci' or name(*[position()=2])='cn') and contains(*[position()=2]/text(),'-'))">
+    <xsl:when test="*[position()=2 and self::m:apply] or (*[position()=2 and (self::m:ci or self::m:cn)] and contains(*[position()=2]/text(),'-'))">
       <mfenced separators="">
         <xsl:apply-templates select="*[position()=2]"/>
       </mfenced>
@@ -2265,7 +2265,7 @@
 </mrow>
 </xsl:template>
 
-<xsl:template match="m:log[name(preceding-sibling::*[position()=last()])='compose' or name(preceding-sibling::*[position()=last()])='inverse']">
+<xsl:template match="m:log[preceding-sibling::*[position()=last() and (self::m:compose or self::m:inverse)]]">
 <mrow>  <!-- used with inverse or composition-->
   <xsl:choose>
   <xsl:when test="m:logbase">
@@ -2288,7 +2288,7 @@
 
 <!-- mean -->
 <!-- not sure we handle the n-ary thing correctly as far as display is concerned-->
-<xsl:template match="m:apply[*[position()=1 and name()='mean']]">
+<xsl:template match="m:apply[*[position()=1 and self::m:mean]]">
 <mrow>
   <xsl:choose>
   <xsl:when test="count(*)>2">  <!-- if more than one element use angle bracket notation-->
@@ -2311,7 +2311,7 @@
 
 <!-- standard deviation -->
 <!-- not sure we handle the n-ary thing correctly as far as display is concerned-->
-<xsl:template match="m:apply[*[position()=1 and name()='sdev']]">
+<xsl:template match="m:apply[*[position()=1 and self::m:sdev]]">
 <mrow>
   <mi><xsl:text disable-output-escaping="yes"><![CDATA[&sigma;]]></xsl:text></mi>
   <mfenced>
@@ -2322,7 +2322,7 @@
 
 <!-- statistical variance -->
 <!-- not sure we handle the n-ary thing correctly as far as display is concerned-->
-<xsl:template match="m:apply[*[position()=1 and name()='variance']]">
+<xsl:template match="m:apply[*[position()=1 and self::m:variance]]">
 <mrow>
   <mi><xsl:text disable-output-escaping="yes"><![CDATA[&sigma;]]></xsl:text></mi>
   <msup> 
@@ -2336,7 +2336,7 @@
 
 <!-- median -->
 <!-- not sure we handle the n-ary thing correctly as far as display is concerned-->
-<xsl:template match="m:apply[*[position()=1 and name()='median']]">
+<xsl:template match="m:apply[*[position()=1 and self::m:median]]">
 <mrow>
   <mi>median</mi>
   <mfenced>
@@ -2347,7 +2347,7 @@
 
 <!-- statistical mode -->
 <!-- not sure we handle the n-ary thing correctly as far as display is concerned-->
-<xsl:template match="m:apply[*[position()=1 and name()='mode']]">
+<xsl:template match="m:apply[*[position()=1 and self::m:mode]]">
 <mrow>
   <mi>mode</mi>
   <mfenced>
@@ -2358,10 +2358,10 @@
 
 <!-- statistical moment -->
 <!-- not sure we handle the n-ary thing correctly as far as display is concerned-->
-<xsl:template match="m:apply[*[position()=1 and name()='moment']]">
+<xsl:template match="m:apply[*[position()=1 and self::m:moment]]">
 <mrow>
   <mo><xsl:text disable-output-escaping="yes"><![CDATA[&lang;]]></xsl:text></mo>
-  <xsl:for-each select="*[position()!=1 and position()!=2 and position()!=last() and name()!='momentabout']">
+  <xsl:for-each select="*[position()!=1 and position()!=2 and position()!=last() and not(self::m:momentabout)]">
     <msup>
       <xsl:apply-templates select="."/>
       <xsl:apply-templates select="../m:degree"/>
@@ -2421,7 +2421,7 @@
 </xsl:template>
 
 <!-- determinant -->
-<xsl:template match="m:apply[*[position()=1 and name()='determinant']]">
+<xsl:template match="m:apply[*[position()=1 and self::m:determinant]]">
   <mrow>
     <mo>det</mo>
     <xsl:choose>
@@ -2436,7 +2436,7 @@
 </xsl:template>
 
 <!-- transpose -->
-<xsl:template match="m:apply[*[position()=1 and name()='transpose']]">
+<xsl:template match="m:apply[*[position()=1 and self::m:transpose]]">
   <msup>
     <xsl:choose>
     <xsl:when test="m:apply">
@@ -2451,10 +2451,10 @@
 </xsl:template>
 
 <!-- selector-->
-<xsl:template match="m:apply[*[position()=1 and name()='selector']]">
+<xsl:template match="m:apply[*[position()=1 and self::m:selector]]">
   <mrow>
   <xsl:choose>
-  <xsl:when test="name(*[position()=2])='m:matrix'"> <!-- select in a matrix defined inside the selector -->
+  <xsl:when test="*[position()=2 and self::m:matrix]"> <!-- select in a matrix defined inside the selector -->
     <xsl:choose>
     <xsl:when test="count(*)=4"> <!-- matrix element-->
       <xsl:variable name="i"><xsl:value-of select="*[position()=3]"/></xsl:variable>  <!--extract row-->
@@ -2470,7 +2470,7 @@
     </xsl:otherwise>
     </xsl:choose>
   </xsl:when>
-  <xsl:when test="name(*[position()=2])='vector' or name(*[position()=2])='list'"> <!-- select in a vector or list defined inside the selector -->
+  <xsl:when test="*[position()=2 and (self::m:vector or self::m:list)]"> <!-- select in a vector or list defined inside the selector -->
     <xsl:choose>
     <xsl:when test="count(*)=3">  <!-- list/vector element -->
       <xsl:variable name="i"><xsl:value-of select="*[position()=3]"/></xsl:variable>  <!--extract index-->
@@ -2509,7 +2509,7 @@
 </xsl:template>
 
 <!-- vector product = A x B x sin(teta) -->
-<xsl:template match="m:apply[*[position()=1 and name()='vectorproduct']]">
+<xsl:template match="m:apply[*[position()=1 and self::m:vectorproduct]]">
 <mrow>
   <xsl:apply-templates select="*[position()=2]"/>
   <mo><xsl:text disable-output-escaping="yes"><![CDATA[&times;]]></xsl:text></mo>
@@ -2518,7 +2518,7 @@
 </xsl:template>
 
 <!-- scalar product = A x B x cos(teta) -->
-<xsl:template match="m:apply[*[position()=1 and name()='scalarproduct']]">
+<xsl:template match="m:apply[*[position()=1 and self::m:scalarproduct]]">
 <mrow>
   <xsl:apply-templates select="*[position()=2]"/>
   <mo>.</mo>
@@ -2527,7 +2527,7 @@
 </xsl:template>
 
 <!-- outer product = A x B x cos(teta) -->
-<xsl:template match="m:apply[*[position()=1 and name()='outerproduct']]">
+<xsl:template match="m:apply[*[position()=1 and self::m:outerproduct]]">
 <mrow>
   <xsl:apply-templates select="*[position()=2]"/>
   <mo>.</mo>

