home *** CD-ROM | disk | FTP | other *** search
/ ftp.tcs3.com / ftp.tcs3.com.tar / ftp.tcs3.com / DRIVERS / Audio / Office2010 / ProPlus.WW / ProPsWW.cab / OMML2MML.XSL < prev    next >
Extensible Markup Language  |  2009-06-05  |  95KB  |  2,069 lines

  1. <?xml version="1.0" encoding="UTF-8" ?>
  2. <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:mml="http://www.w3.org/1998/Math/MathML"
  3.     xmlns:m="http://schemas.openxmlformats.org/officeDocument/2006/math">
  4.   <xsl:output method="xml" encoding="UTF-16" />
  5.  
  6.   <!-- %% Global Definitions -->
  7.  
  8.   <!-- Every single unicode character that is recognized by OMML as an operator -->
  9.   <xsl:variable name="sOperators"
  10.         select="concat(
  11.           '¨!"#&()+,-./:',
  12.           ';<=>?@[\]^_`{',
  13.           '|}~¡¦¬¯°±²³´·¹¿',
  14.           '×~÷ˇ˘˙˜˝̀́̂̃̄̅̆̇̈̉',
  15.           '̊̋̌̍̎̏̐̑̒̓̔̕',
  16.           '̡̛̖̗̘̙̜̝̞̟̠̚',
  17.           '̢̧̨̣̤̥̦̩̪̫̬̭',
  18.           '̴̵̶̷̸̮̯̰̱̲̳̿',
  19.           '         ‐‒–',
  20.           '—‖†‡•․‥…′″‴‼',
  21.           '⁀⁄⁎⁏⁐⁗⁡⁢⁣⁰⁴⁵',
  22.           '⁶⁷⁸⁹⁺⁻⁼⁽⁾₀₁₂',
  23.           '₃₄₅₆₇₈₉₊₋₌₍₎',
  24.           '⃒⃓⃘⃙⃚⃐⃑⃔⃕⃖⃗⃛',
  25.           '⃜⃝⃞⃟⃠⃡⃤⃥⃦⃨⃧⃩',
  26.           '⃪⅀ⅆ←↑→↓↔↕↖↗↘↙',
  27.           '↚↛↜↝↞↟↠↡↢↣↤↥',
  28.           '↦↧↨↩↪↫↬↭↮↯↰↱',
  29.           '↲↳↶↷↺↻↼↽↾↿⇀⇁',
  30.           '⇂⇃⇄⇅⇆⇇⇈⇉⇊⇋⇌⇍',
  31.           '⇎⇏⇐⇑⇒⇓⇔⇕⇖⇗⇘⇙',
  32.           '⇚⇛⇜⇝⇞⇟⇠⇡⇢⇣⇤⇥',
  33.           '⇦⇧⇨⇩⇳⇴⇵⇶⇷⇸⇹⇺',
  34.           '⇻⇼⇽⇾⇿∀∁∂∃∄∆∇',
  35.           '∈∉∊∋∌∍∏∐∑−∓∔',
  36.           '∕∖∗∘∙√∛∜∝∣∤∥',
  37.           '∦∧∨∩∪∫∬∭∮∯∰∱',
  38.           '∲∳∴∵∶∷∸∹∺∻∼∽',
  39.           '∾≀≁≂≃≄≅≆≇≈≉≊',
  40.           '≋≌≍≎≏≐≑≒≓≔≕≖',
  41.           '≗≘≙≚≛≜≝≞≟≠≡≢',
  42.           '≣≤≥≦≧≨≩≪≫≬≭≮',
  43.           '≯≰≱≲≳≴≵≶≷≸≹≺',
  44.           '≻≼≽≾≿⊀⊁⊂⊃⊄⊅⊆',
  45.           '⊇⊈⊉⊊⊋⊌⊍⊎⊏⊐⊑⊒',
  46.           '⊓⊔⊕⊖⊗⊘⊙⊚⊛⊜⊝⊞',
  47.           '⊟⊠⊡⊢⊣⊥⊦⊧⊨⊩⊪⊫',
  48.           '⊬⊭⊮⊯⊰⊱⊲⊳⊴⊵⊶⊷',
  49.           '⊸⊹⊺⊻⊼⊽⋀⋁⋂⋃⋄⋅',
  50.           '⋆⋇⋈⋉⋊⋋⋌⋍⋎⋏⋐⋑',
  51.           '⋒⋓⋔⋕⋖⋗⋘⋙⋚⋛⋜⋝',
  52.           '⋞⋟⋠⋡⋢⋣⋤⋥⋦⋧⋨⋩',
  53.           '⋪⋫⋬⋭⋮⋯⋰⋱⋲⋳⋴⋵',
  54.           '⋶⋷⋸⋹⋺⋻⋼⋽⋾⋿⌅⌆',
  55.           '⌈⌉⌊⌋⌜⌝⌞⌟⌢⌣〈〉',
  56.           '⌽⌿⎰⎱⏜⏝⏞⏟⏠│├┤',
  57.           '┬┴▁█▒■□▭▲△▴▵',
  58.           '▶▷▸▹▼▽▾▿◀◁◂◃',
  59.           '◄◅◊○◦◫◬◸◹◺◻◼',
  60.           '◽◾◿★☆❲❳⟑⟒⟓⟔⟕',
  61.           '⟖⟗⟘⟙⟚⟛⟜⟝⟞⟟⟠⟡',
  62.           '⟢⟣⟤⟥⟦⟧⟨⟩⟪⟫⟰⟱',
  63.           '⟲⟳⟴⟵⟶⟷⟸⟹⟺⟻⟼⟽',
  64.           '⟾⟿⤀⤁⤂⤃⤄⤅⤆⤇⤈⤉',
  65.           '⤊⤋⤌⤍⤎⤏⤐⤑⤒⤓⤔⤕',
  66.           '⤖⤗⤘⤙⤚⤛⤜⤝⤞⤟⤠⤡',
  67.           '⤢⤣⤤⤥⤦⤧⤨⤩⤪⤫⤬⤭',
  68.           '⤮⤯⤰⤱⤲⤳⤴⤵⤶⤷⤸⤹',
  69.           '⤺⤻⤼⤽⤾⤿⥀⥁⥂⥃⥄⥅',
  70.           '⥆⥇⥈⥉⥊⥋⥌⥍⥎⥏⥐⥑',
  71.           '⥒⥓⥔⥕⥖⥗⥘⥙⥚⥛⥜⥝',
  72.           '⥞⥟⥠⥡⥢⥣⥤⥥⥦⥧⥨⥩',
  73.           '⥪⥫⥬⥭⥮⥯⥰⥱⥲⥳⥴⥵',
  74.           '⥶⥷⥸⥹⥺⥻⥼⥽⥾⥿⦀⦂',
  75.           '⦃⦄⦅⦆⦇⦈⦉⦊⦋⦌⦍⦎',
  76.           '⦏⦐⦑⦒⦓⦔⦕⦖⦗⦘⦙⦚',
  77.           '⦶⦷⦸⦹⧀⧁⧄⧅⧆⧇⧈⧎',
  78.           '⧏⧐⧑⧒⧓⧔⧕⧖⧗⧘⧙⧚',
  79.           '⧛⧟⧡⧢⧣⧤⧥⧦⧫⧴⧵⧶',
  80.           '⧷⧸⧹⧺⧻⧼⧽⧾⧿⨀⨁⨂',
  81.           '⨃⨄⨅⨆⨇⨈⨉⨊⨋⨌⨍⨎',
  82.           '⨏⨐⨑⨒⨓⨔⨕⨖⨗⨘⨙⨚',
  83.           '⨛⨜⨝⨞⨟⨠⨡⨢⨣⨤⨥⨦',
  84.           '⨧⨨⨩⨪⨫⨬⨭⨮⨯⨰⨱⨲',
  85.           '⨳⨴⨵⨶⨷⨸⨹⨺⨻⨼⨽⨾',
  86.           '⨿⩀⩁⩂⩃⩄⩅⩆⩇⩈⩉⩊',
  87.           '⩋⩌⩍⩎⩏⩐⩑⩒⩓⩔⩕⩖',
  88.           '⩗⩘⩙⩚⩛⩜⩝⩞⩟⩠⩡⩢',
  89.           '⩣⩤⩥⩦⩧⩨⩩⩪⩫⩬⩭⩮',
  90.           '⩯⩰⩱⩲⩳⩴⩵⩶⩷⩸⩹⩺',
  91.           '⩻⩼⩽⩾⩿⪀⪁⪂⪃⪄⪅⪆',
  92.           '⪇⪈⪉⪊⪋⪌⪍⪎⪏⪐⪑⪒',
  93.           '⪓⪔⪕⪖⪗⪘⪙⪚⪛⪜⪝⪞',
  94.           '⪟⪠⪡⪢⪣⪤⪥⪦⪧⪨⪩⪪',
  95.           '⪫⪬⪭⪮⪯⪰⪱⪲⪳⪴⪵⪶',
  96.           '⪷⪸⪹⪺⪻⪼⪽⪾⪿⫀⫁⫂',
  97.           '⫃⫄⫅⫆⫇⫈⫉⫊⫋⫌⫍⫎',
  98.           '⫏⫐⫑⫒⫓⫔⫕⫖⫗⫘⫙⫚',
  99.           '⫛⫝̸⫝⫞⫟⫠⫢⫣⫤⫥⫦⫧',
  100.           '⫨⫩⫪⫫⫬⫭⫮⫯⫰⫲⫳⫴',
  101.           '⫵⫶⫷⫸⫹⫺⫻⫼⫽⫾⫿⬄',
  102.           '⬆⬇⬌⬍〔〕〖〗〘〙!&',
  103.           '()+,-./:;<=>',
  104.           '?@[\]^_{|}')" />
  105.  
  106.   <!-- A string of '-'s repeated exactly as many times as the operators above -->
  107.   <xsl:variable name="sMinuses">
  108.     <xsl:call-template name="SRepeatChar">
  109.       <xsl:with-param name="cchRequired" select="string-length($sOperators)" />
  110.       <xsl:with-param name="ch" select="'-'" />
  111.     </xsl:call-template>
  112.   </xsl:variable>
  113.  
  114.   <!-- Every single unicode character that is recognized by OMML as a number -->
  115.   <xsl:variable name="sNumbers" select="'0123456789'" />
  116.  
  117.   <!-- A string of '0's repeated exactly as many times as the list of numbers above -->
  118.   <xsl:variable name="sZeros">
  119.     <xsl:call-template name="SRepeatChar">
  120.       <xsl:with-param name="cchRequired" select="string-length($sNumbers)" />
  121.       <xsl:with-param name="ch" select="'0'" />
  122.     </xsl:call-template>
  123.   </xsl:variable>
  124.  
  125.   <!-- %%Template: SReplace
  126.  
  127.         Replace all occurences of sOrig in sInput with sReplacement
  128.         and return the resulting string. -->
  129.   <xsl:template name="SReplace">
  130.     <xsl:param name="sInput" />
  131.     <xsl:param name="sOrig" />
  132.     <xsl:param name="sReplacement" />
  133.  
  134.     <xsl:choose>
  135.       <xsl:when test="not(contains($sInput, $sOrig))">
  136.         <xsl:value-of select="$sInput" />
  137.       </xsl:when>
  138.       <xsl:otherwise>
  139.         <xsl:variable name="sBefore" select="substring-before($sInput, $sOrig)" />
  140.         <xsl:variable name="sAfter" select="substring-after($sInput, $sOrig)" />
  141.         <xsl:variable name="sAfterProcessed">
  142.           <xsl:call-template name="SReplace">
  143.             <xsl:with-param name="sInput" select="$sAfter" />
  144.             <xsl:with-param name="sOrig" select="$sOrig" />
  145.             <xsl:with-param name="sReplacement" select="$sReplacement" />
  146.           </xsl:call-template>
  147.         </xsl:variable>
  148.  
  149.         <xsl:value-of select="concat($sBefore, concat($sReplacement, $sAfterProcessed))" />
  150.       </xsl:otherwise>
  151.     </xsl:choose>
  152.   </xsl:template>
  153.  
  154.   <!-- Templates -->
  155.   <xsl:template match="/">
  156.     <mml:math>
  157.       <xsl:apply-templates select="*" />
  158.     </mml:math>
  159.   </xsl:template>
  160.  
  161.   <xsl:template match="m:borderBox">
  162.  
  163.     <!-- Get Lowercase versions of properties -->
  164.     <xsl:variable name="sLowerCaseHideTop" select="translate(m:borderBoxPr[last()]/m:hideTop[last()]/@m:val, 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 
  165.                                                                      'abcdefghijklmnopqrstuvwxyz')" />
  166.     <xsl:variable name="sLowerCaseHideBot" select="translate(m:borderBoxPr[last()]/m:hideBot[last()]/@m:val, 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 
  167.                                                                      'abcdefghijklmnopqrstuvwxyz')" />
  168.     <xsl:variable name="sLowerCaseHideLeft" select="translate(m:borderBoxPr[last()]/m:hideLeft[last()]/@m:val, 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 
  169.                                                                      'abcdefghijklmnopqrstuvwxyz')" />
  170.     <xsl:variable name="sLowerCaseHideRight" select="translate(m:borderBoxPr[last()]/m:hideRight[last()]/@m:val, 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 
  171.                                                                      'abcdefghijklmnopqrstuvwxyz')" />
  172.     <xsl:variable name="sLowerCaseStrikeH" select="translate(m:borderBoxPr[last()]/m:strikeH[last()]/@m:val, 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 
  173.                                                                      'abcdefghijklmnopqrstuvwxyz')" />
  174.     <xsl:variable name="sLowerCaseStrikeV" select="translate(m:borderBoxPr[last()]/m:strikeV[last()]/@m:val, 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 
  175.                                                                      'abcdefghijklmnopqrstuvwxyz')" />
  176.     <xsl:variable name="sLowerCaseStrikeBLTR" select="translate(m:borderBoxPr[last()]/m:strikeBLTR[last()]/@m:val, 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 
  177.                                                                      'abcdefghijklmnopqrstuvwxyz')" />
  178.     <xsl:variable name="sLowerCaseStrikeTLBR" select="translate(m:borderBoxPr[last()]/m:strikeTLBR[last()]/@m:val, 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 
  179.                                                                      'abcdefghijklmnopqrstuvwxyz')" />
  180.     <xsl:variable name="fHideTop">
  181.       <xsl:call-template name="ForceTrueStrVal">
  182.         <xsl:with-param name="str" select="$sLowerCaseHideTop" />
  183.       </xsl:call-template>
  184.     </xsl:variable>
  185.     <xsl:variable name="fHideBot">
  186.       <xsl:call-template name="ForceTrueStrVal">
  187.         <xsl:with-param name="str" select="$sLowerCaseHideBot" />
  188.       </xsl:call-template>
  189.     </xsl:variable>
  190.     <xsl:variable name="fHideLeft">
  191.       <xsl:call-template name="ForceTrueStrVal">
  192.         <xsl:with-param name="str" select="$sLowerCaseHideLeft" />
  193.       </xsl:call-template>
  194.     </xsl:variable>
  195.     <xsl:variable name="fHideRight">
  196.       <xsl:call-template name="ForceTrueStrVal">
  197.         <xsl:with-param name="str" select="$sLowerCaseHideRight" />
  198.       </xsl:call-template>
  199.     </xsl:variable>
  200.     <xsl:variable name="fStrikeH">
  201.       <xsl:call-template name="ForceTrueStrVal">
  202.         <xsl:with-param name="str" select="$sLowerCaseStrikeH" />
  203.       </xsl:call-template>
  204.     </xsl:variable>
  205.     <xsl:variable name="fStrikeV">
  206.       <xsl:call-template name="ForceTrueStrVal">
  207.         <xsl:with-param name="str" select="$sLowerCaseStrikeV" />
  208.       </xsl:call-template>
  209.     </xsl:variable>
  210.     <xsl:variable name="fStrikeBLTR">
  211.       <xsl:call-template name="ForceTrueStrVal">
  212.         <xsl:with-param name="str" select="$sLowerCaseStrikeBLTR" />
  213.       </xsl:call-template>
  214.     </xsl:variable>
  215.     <xsl:variable name="fStrikeTLBR">
  216.       <xsl:call-template name="ForceTrueStrVal">
  217.         <xsl:with-param name="str" select="$sLowerCaseStrikeTLBR" />
  218.       </xsl:call-template>
  219.     </xsl:variable>
  220.  
  221.     <xsl:choose>
  222.       <xsl:when test="$fHideTop=1 
  223.                       and $fHideBot=1 
  224.                       and $fHideLeft=1 
  225.                       and $fHideRight=1 
  226.                       and $fStrikeH=0 
  227.                       and $fStrikeV=0 
  228.                       and $fStrikeBLTR=0 
  229.                       and $fStrikeTLBR=0">
  230.         <mml:mrow>
  231.           <xsl:apply-templates select="m:e[1]" />
  232.         </mml:mrow>
  233.       </xsl:when>
  234.       <xsl:otherwise>
  235.         <mml:menclose>
  236.           <xsl:call-template name="CreateMencloseNotationAttrFromBorderBoxAttr">
  237.             <xsl:with-param name="fHideTop" select="$fHideTop" />
  238.             <xsl:with-param name="fHideBot" select="$fHideBot" />
  239.             <xsl:with-param name="fHideLeft" select="$fHideLeft" />
  240.             <xsl:with-param name="fHideRight" select="$fHideRight" />
  241.             <xsl:with-param name="fStrikeH" select="$fStrikeH" />
  242.             <xsl:with-param name="fStrikeV" select="$fStrikeV" />
  243.             <xsl:with-param name="fStrikeBLTR" select="$fStrikeBLTR" />
  244.             <xsl:with-param name="fStrikeTLBR" select="$fStrikeTLBR" />
  245.           </xsl:call-template>
  246.           <xsl:apply-templates select="m:e[1]" />
  247.         </mml:menclose>
  248.       </xsl:otherwise>
  249.     </xsl:choose>
  250.   </xsl:template>
  251.  
  252.   <xsl:template match="*">
  253.     <xsl:apply-templates select="*" />
  254.   </xsl:template>
  255.  
  256.   <!--
  257.       { Non-combining, Upper-combining, Lower-combining }
  258.       {U+02D8, U+0306, U+032E}, // BREVE
  259.       {U+00B8, U+0312, U+0327}, // CEDILLA
  260.       {U+0060, U+0300, U+0316}, // GRAVE ACCENT
  261.       {U+002D, U+0305, U+0332}, // HYPHEN-MINUS/OVERLINE
  262.       {U+2212, U+0305, U+0332}, // MINUS SIGN/OVERLINE
  263.       {U+002E, U+0305, U+0323}, // FULL STOP/DOT ABOVE
  264.       {U+02D9, U+0307, U+0323}, // DOT ABOVE
  265.       {U+02DD, U+030B, U+02DD}, // DOUBLE ACUTE ACCENT
  266.       {U+00B4, U+0301, U+0317}, // ACUTE ACCENT
  267.       {U+007E, U+0303, U+0330}, // TILDE
  268.       {U+02DC, U+0303, U+0330}, // SMALL TILDE
  269.       {U+00A8, U+0308, U+0324}, // DIAERESIS
  270.       {U+02C7, U+030C, U+032C}, // CARON
  271.       {U+005E, U+0302, U+032D}, // CIRCUMFLEX ACCENT
  272.       {U+00AF, U+0305, ::::::}, // MACRON
  273.       {U+005F, ::::::, U+0332}, // LOW LINE
  274.       {U+2192, U+20D7, U+20EF}, // RIGHTWARDS ARROW
  275.       {U+27F6, U+20D7, U+20EF}, // LONG RIGHTWARDS ARROW
  276.       {U+2190, U+20D6, U+20EE}, // LEFT ARROW
  277.   -->
  278.   <xsl:template name="ToNonCombining">
  279.     <xsl:param name="ch" />
  280.     <xsl:choose>
  281.       <!-- BREVE -->
  282.       <xsl:when test="$ch='̆' or $ch='̮'">˘</xsl:when>
  283.       <!-- CEDILLA -->
  284.       <xsl:when test="$ch='̒' or $ch='̧'">¸</xsl:when>
  285.       <!-- GRAVE ACCENT -->
  286.       <xsl:when test="$ch='̀' or $ch='̖'">`</xsl:when>
  287.       <!-- HYPHEN-MINUS/OVERLINE -->
  288.       <xsl:when test="$ch='̅' or $ch='̲'">-</xsl:when>
  289.       <!-- MINUS SIGN/OVERLINE -->
  290.       <xsl:when test="$ch='̅' or $ch='̲'">−</xsl:when>
  291.       <!-- FULL STOP/DOT ABOVE -->
  292.       <xsl:when test="$ch='̅' or $ch='̣'">.</xsl:when>
  293.       <!-- DOT ABOVE -->
  294.       <xsl:when test="$ch='̇' or $ch='̣'">˙</xsl:when>
  295.       <!-- DOUBLE ACUTE ACCENT -->
  296.       <xsl:when test="$ch='̋' or $ch='˝'">˝</xsl:when>
  297.       <!-- ACUTE ACCENT -->
  298.       <xsl:when test="$ch='́' or $ch='̗'">´</xsl:when>
  299.       <!-- TILDE -->
  300.       <xsl:when test="$ch='̃' or $ch='̰'">~</xsl:when>
  301.       <!-- SMALL TILDE -->
  302.       <xsl:when test="$ch='̃' or $ch='̰'">˜</xsl:when>
  303.       <!-- DIAERESIS -->
  304.       <xsl:when test="$ch='̈' or $ch='̤'">¨</xsl:when>
  305.       <!-- CARON -->
  306.       <xsl:when test="$ch='̌' or $ch='̬'">ˇ</xsl:when>
  307.       <!-- CIRCUMFLEX ACCENT -->
  308.       <xsl:when test="$ch='̂' or $ch='̭'">^</xsl:when>
  309.       <!-- MACRON -->
  310.       <xsl:when test="$ch='̅'                   ">¯</xsl:when>
  311.       <!-- LOW LINE -->
  312.       <xsl:when test="                   $ch='̲'">_</xsl:when>
  313.       <!-- RIGHTWARDS ARROW -->
  314.       <xsl:when test="$ch='⃗' or $ch='⃯'">→</xsl:when>
  315.       <!-- LONG RIGHTWARDS ARROW -->
  316.       <xsl:when test="$ch='⃗' or $ch='⃯'">⟶</xsl:when>
  317.       <!-- LEFT ARROW -->
  318.       <xsl:when test="$ch='⃖' or $ch='⃮'">←</xsl:when>
  319.       <xsl:otherwise>
  320.         <xsl:value-of select="$ch"/>
  321.       </xsl:otherwise>
  322.     </xsl:choose>
  323.   </xsl:template>
  324.  
  325.   <xsl:template match="m:acc">
  326.     <mml:mover>
  327.       <xsl:attribute name="accent">true</xsl:attribute>
  328.       <mml:mrow>
  329.         <xsl:apply-templates select="m:e[1]" />
  330.       </mml:mrow>
  331.       <xsl:variable name="chAcc">
  332.         <xsl:choose>
  333.           <xsl:when test="not(m:accPr[last()]/m:chr)">
  334.             <xsl:value-of select="'̂'" />
  335.           </xsl:when>
  336.           <xsl:otherwise>
  337.             <xsl:value-of select="substring(m:accPr/m:chr/@m:val,1,1)" />
  338.           </xsl:otherwise>
  339.         </xsl:choose>
  340.       </xsl:variable>
  341.       <xsl:variable name="chNonComb">
  342.         <xsl:call-template name="ToNonCombining">
  343.           <xsl:with-param name="ch" select="$chAcc" />
  344.         </xsl:call-template>
  345.       </xsl:variable>
  346.       <xsl:choose>
  347.         <xsl:when test="string-length($chAcc)=0">
  348.           <mml:mo/>
  349.         </xsl:when>
  350.         <xsl:otherwise>
  351.           <xsl:call-template name="ParseMt">
  352.             <xsl:with-param name="sToParse" select="$chNonComb" />
  353.             <xsl:with-param name="scr" select="m:e[1]/*/m:rPr[last()]/m:scr/@m:val" />
  354.             <xsl:with-param name="sty" select="m:e[1]/*/m:rPr[last()]/m:sty/@m:val" />
  355.             <xsl:with-param name="nor">
  356.               <xsl:choose>
  357.                 <xsl:when test="count(m:e[1]/*/m:rPr[last()]/m:nor) = 0">0</xsl:when>
  358.                 <xsl:otherwise>
  359.                   <xsl:call-template name="ForceFalseStrVal">
  360.                     <xsl:with-param name="str" select="translate(m:e[1]/*/m:rPr[last()]/m:nor/@m:val, 
  361.                                                                      'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 
  362.                                                                          'abcdefghijklmnopqrstuvwxyz')" />
  363.                   </xsl:call-template>
  364.                 </xsl:otherwise>
  365.               </xsl:choose>
  366.             </xsl:with-param>
  367.           </xsl:call-template>
  368.         </xsl:otherwise>
  369.       </xsl:choose>
  370.     </mml:mover>
  371.   </xsl:template>
  372.  
  373.   <xsl:template name="OutputScript">
  374.     <xsl:param name="ndCur" select="." />
  375.     <xsl:choose>
  376.       <!-- Only output contents of $ndCur if $ndCur exists
  377.            and $ndCur has children -->
  378.       <xsl:when test="count($ndCur/*) > 0">
  379.         <mml:mrow>
  380.           <xsl:apply-templates select="$ndCur" />
  381.         </mml:mrow>
  382.       </xsl:when>
  383.       <xsl:otherwise>
  384.         <mml:none />
  385.       </xsl:otherwise>
  386.     </xsl:choose>
  387.   </xsl:template>
  388.  
  389.   <xsl:template match="m:sPre">
  390.     <mml:mmultiscripts>
  391.       <mml:mrow>
  392.         <xsl:apply-templates select="m:e[1]" />
  393.       </mml:mrow>
  394.       <mml:mprescripts />
  395.       <xsl:call-template name="OutputScript">
  396.         <xsl:with-param name="ndCur" select="m:sub[1]"/>
  397.       </xsl:call-template>
  398.       <xsl:call-template name="OutputScript">
  399.         <xsl:with-param name="ndCur" select="m:sup[1]" />
  400.       </xsl:call-template>
  401.     </mml:mmultiscripts>
  402.   </xsl:template>
  403.  
  404.   <xsl:template match="m:m">
  405.     <mml:mtable>
  406.       <xsl:call-template name="CreateMathMLMatrixAttr">
  407.         <xsl:with-param name="mcJc" select="m:mPr[last()]/m:mcs/m:mc/m:mcPr[last()]/m:mcJc/@m:val" />
  408.       </xsl:call-template>
  409.       <xsl:for-each select="m:mr">
  410.         <mml:mtr>
  411.           <xsl:for-each select="m:e">
  412.             <mml:mtd>
  413.               <xsl:apply-templates select="." />
  414.             </mml:mtd>
  415.           </xsl:for-each>
  416.         </mml:mtr>
  417.       </xsl:for-each>
  418.     </mml:mtable>
  419.   </xsl:template>
  420.  
  421.   <xsl:template name="CreateMathMLMatrixAttr">
  422.     <xsl:param name="mcJc" />
  423.     <xsl:variable name="sLowerCaseMcjc" select="translate($mcJc, 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 
  424.                                                                      'abcdefghijklmnopqrstuvwxyz')" />
  425.     <xsl:choose>
  426.       <xsl:when test="$sLowerCaseMcjc='left'">
  427.         <xsl:attribute name="columnalign">left</xsl:attribute>
  428.       </xsl:when>
  429.       <xsl:when test="$sLowerCaseMcjc='right'">
  430.         <xsl:attribute name="columnalign">right</xsl:attribute>
  431.       </xsl:when>
  432.     </xsl:choose>
  433.   </xsl:template>
  434.  
  435.   <xsl:template match="m:phant">
  436.     <xsl:variable name="sLowerCaseZeroWidVal" select="translate(m:phantPr[last()]/m:zeroWid[last()]/@m:val, 
  437.                                                                'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 
  438.                                                                'abcdefghijklmnopqrstuvwxyz')" />
  439.     <xsl:variable name="sLowerCaseZeroAscVal" select="translate(m:phantPr[last()]/m:zeroAsc[last()]/@m:val, 
  440.                                                              'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 
  441.                                                              'abcdefghijklmnopqrstuvwxyz')" />
  442.     <xsl:variable name="sLowerCaseZeroDescVal" select="translate(m:phantPr[last()]/m:zeroDesc[last()]/@m:val, 
  443.                                                              'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 
  444.                                                              'abcdefghijklmnopqrstuvwxyz')" />
  445.     <xsl:variable name="sLowerCaseShowVal" select="translate(m:phantPr[last()]/m:show[last()]/@m:val, 
  446.                                                              'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 
  447.                                                              'abcdefghijklmnopqrstuvwxyz')" />
  448.  
  449.  
  450.     <!-- The following properties default to 'yes' unless the last value equals 'no' or there isn't any node for 
  451.          the property -->
  452.  
  453.     <xsl:variable name="fZeroWid">
  454.       <xsl:choose>
  455.         <xsl:when test="count(m:phantPr[last()]/m:zeroWid[last()]) = 0">0</xsl:when>
  456.         <xsl:otherwise>
  457.           <xsl:call-template name="ForceFalseStrVal">
  458.             <xsl:with-param name="str" select="$sLowerCaseZeroWidVal" />
  459.           </xsl:call-template>
  460.         </xsl:otherwise>
  461.       </xsl:choose>
  462.     </xsl:variable>
  463.     <xsl:variable name="fZeroAsc">
  464.       <xsl:choose>
  465.         <xsl:when test="count(m:phantPr[last()]/m:zeroAsc[last()]) = 0">0</xsl:when>
  466.         <xsl:otherwise>
  467.           <xsl:call-template name="ForceFalseStrVal">
  468.             <xsl:with-param name="str" select="$sLowerCaseZeroAscVal" />
  469.           </xsl:call-template>
  470.         </xsl:otherwise>
  471.       </xsl:choose>
  472.     </xsl:variable>
  473.     <xsl:variable name="fZeroDesc">
  474.       <xsl:choose>
  475.         <xsl:when test="count(m:phantPr[last()]/m:zeroDesc[last()]) = 0">0</xsl:when>
  476.         <xsl:otherwise>
  477.           <xsl:call-template name="ForceFalseStrVal">
  478.             <xsl:with-param name="str" select="$sLowerCaseZeroDescVal" />
  479.           </xsl:call-template>
  480.         </xsl:otherwise>
  481.       </xsl:choose>
  482.     </xsl:variable>
  483.  
  484.     <!-- The show property defaults to 'on' unless there exists a show property and its value is 'off' -->
  485.  
  486.     <xsl:variable name="fShow">
  487.       <xsl:call-template name="ForceFalseStrVal">
  488.         <xsl:with-param name="str" select="$sLowerCaseShowVal" />
  489.       </xsl:call-template>
  490.     </xsl:variable>
  491.  
  492.     <xsl:choose>
  493.       <!-- Show the phantom contents, therefore, just use mpadded. -->
  494.       <xsl:when test="$fShow = 1">
  495.         <xsl:element name="mml:mpadded">
  496.           <xsl:call-template name="CreateMpaddedAttributes">
  497.             <xsl:with-param name="fZeroWid" select="$fZeroWid" />
  498.             <xsl:with-param name="fZeroAsc" select="$fZeroAsc" />
  499.             <xsl:with-param name="fZeroDesc" select="$fZeroDesc" />
  500.           </xsl:call-template>
  501.           <mml:mrow>
  502.             <xsl:apply-templates select="m:e" />
  503.           </mml:mrow>
  504.         </xsl:element>
  505.       </xsl:when>
  506.       <!-- Don't show phantom contents, but don't smash anything, therefore, just 
  507.            use mphantom -->
  508.       <xsl:when test="$fZeroWid=0 and $fZeroAsc=0 and $fZeroDesc=0">
  509.         <xsl:element name="mml:mphantom">
  510.           <mml:mrow>
  511.             <xsl:apply-templates select="m:e" />
  512.           </mml:mrow>
  513.         </xsl:element>
  514.       </xsl:when>
  515.       <!-- Combination -->
  516.       <xsl:otherwise>
  517.         <xsl:element name="mml:mphantom">
  518.           <xsl:element name="mml:mpadded">
  519.             <xsl:call-template name="CreateMpaddedAttributes">
  520.               <xsl:with-param name="fZeroWid" select="$fZeroWid" />
  521.               <xsl:with-param name="fZeroAsc" select="$fZeroAsc" />
  522.               <xsl:with-param name="fZeroDesc" select="$fZeroDesc" />
  523.             </xsl:call-template>
  524.             <mml:mrow>
  525.               <xsl:apply-templates select="m:e" />
  526.             </mml:mrow>
  527.           </xsl:element>
  528.         </xsl:element>
  529.       </xsl:otherwise>
  530.     </xsl:choose>
  531.   </xsl:template>
  532.  
  533.   <xsl:template name="CreateMpaddedAttributes">
  534.     <xsl:param name="fZeroWid" />
  535.     <xsl:param name="fZeroAsc" />
  536.     <xsl:param name="fZeroDesc" />
  537.  
  538.     <xsl:if test="$fZeroWid=1">
  539.       <xsl:attribute name="width">0in</xsl:attribute>
  540.     </xsl:if>
  541.     <xsl:if test="$fZeroAsc=1">
  542.       <xsl:attribute name="height">0in</xsl:attribute>
  543.     </xsl:if>
  544.     <xsl:if test="$fZeroDesc=1">
  545.       <xsl:attribute name="depth">0in</xsl:attribute>
  546.     </xsl:if>
  547.   </xsl:template>
  548.  
  549.  
  550.  
  551.   <xsl:template match="m:rad">
  552.     <xsl:variable name="fDegHide">
  553.       <xsl:choose>
  554.         <xsl:when test="count(m:radPr[last()]/m:degHide)=0">0</xsl:when>
  555.         <xsl:otherwise>
  556.           <xsl:call-template name="ForceFalseStrVal">
  557.             <xsl:with-param name="str" select="translate(m:radPr[last()]/m:degHide/@m:val, 
  558.                                                                   'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 
  559.                                                                   'abcdefghijklmnopqrstuvwxyz')" />
  560.           </xsl:call-template>
  561.         </xsl:otherwise>
  562.       </xsl:choose>
  563.     </xsl:variable>
  564.     <xsl:choose>
  565.       <xsl:when test="$fDegHide=1">
  566.         <mml:msqrt>
  567.           <xsl:apply-templates select="m:e[1]" />
  568.         </mml:msqrt>
  569.       </xsl:when>
  570.       <xsl:otherwise>
  571.         <mml:mroot>
  572.           <mml:mrow>
  573.             <xsl:apply-templates select="m:e[1]" />
  574.           </mml:mrow>
  575.           <mml:mrow>
  576.             <xsl:apply-templates select="m:deg[1]" />
  577.           </mml:mrow>
  578.         </mml:mroot>
  579.       </xsl:otherwise>
  580.     </xsl:choose>
  581.   </xsl:template>
  582.  
  583.   <xsl:template name="OutputNaryMo">
  584.     <xsl:param name="ndCur" select="." />
  585.     <xsl:param name="fGrow" select="0" />
  586.     <mml:mo>
  587.       <xsl:choose>
  588.         <xsl:when test="$fGrow=1">
  589.           <xsl:attribute name="stretchy">true</xsl:attribute>
  590.         </xsl:when>
  591.         <xsl:otherwise>
  592.           <xsl:attribute name="stretchy">false</xsl:attribute>
  593.         </xsl:otherwise>
  594.       </xsl:choose>
  595.       <xsl:choose>
  596.         <xsl:when test="not($ndCur/m:naryPr[last()]/m:chr/@m:val) or
  597.                                         $ndCur/m:naryPr[last()]/m:chr/@m:val=''">
  598.           <xsl:text>∫</xsl:text>
  599.         </xsl:when>
  600.         <xsl:otherwise>
  601.           <xsl:value-of select="$ndCur/m:naryPr[last()]/m:chr/@m:val" />
  602.         </xsl:otherwise>
  603.       </xsl:choose>
  604.     </mml:mo>
  605.   </xsl:template>
  606.  
  607.   <!-- %%Template match m:nary 
  608.         Process an n-ary. 
  609.         
  610.         Decides, based on which arguments are supplied, between
  611.         using an mo, msup, msub, or msubsup for the n-ary operator        
  612.     -->
  613.   <xsl:template match="m:nary">
  614.     <xsl:variable name="sLowerCaseSubHide">
  615.       <xsl:choose>
  616.         <xsl:when test="count(m:naryPr[last()]/m:subHide) = 0">
  617.           <xsl:text>off</xsl:text>
  618.         </xsl:when>
  619.         <xsl:otherwise>
  620.           <xsl:value-of select="translate(m:naryPr[last()]/m:subHide/@m:val, 
  621.                                       'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 
  622.                                       'abcdefghijklmnopqrstuvwxyz')" />
  623.         </xsl:otherwise>
  624.       </xsl:choose>
  625.     </xsl:variable>
  626.  
  627.     <xsl:variable name="sLowerCaseSupHide">
  628.       <xsl:choose>
  629.         <xsl:when test="count(m:naryPr[last()]/m:supHide) = 0">
  630.           <xsl:text>off</xsl:text>
  631.         </xsl:when>
  632.         <xsl:otherwise>
  633.           <xsl:value-of select="translate(m:naryPr[last()]/m:supHide/@m:val, 
  634.                                       'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 
  635.                                       'abcdefghijklmnopqrstuvwxyz')" />
  636.         </xsl:otherwise>
  637.       </xsl:choose>
  638.     </xsl:variable>
  639.  
  640.     <xsl:variable name="sLowerCaseLimLoc">
  641.       <xsl:value-of select="translate(m:naryPr[last()]/m:limLoc/@m:val, 
  642.                                       'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 
  643.                                       'abcdefghijklmnopqrstuvwxyz')" />
  644.     </xsl:variable>
  645.  
  646.     <xsl:variable name="sLowerGrow">
  647.       <xsl:choose>
  648.         <xsl:when test="count(m:naryPr[last()]/m:grow)=0">off</xsl:when>
  649.         <xsl:otherwise>
  650.           <xsl:value-of select="translate(m:naryPr[last()]/m:grow/@m:val, 
  651.                                       'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 
  652.                                       'abcdefghijklmnopqrstuvwxyz')" />
  653.         </xsl:otherwise>
  654.       </xsl:choose>
  655.     </xsl:variable>
  656.  
  657.     <xsl:variable name="fLimLocSubSup">
  658.       <xsl:choose>
  659.         <xsl:when test="count(m:naryPr[last()]/m:limLoc)=0 or $sLowerCaseLimLoc='subsup'">1</xsl:when>
  660.         <xsl:otherwise>0</xsl:otherwise>
  661.       </xsl:choose>
  662.     </xsl:variable>
  663.  
  664.     <xsl:variable name="fGrow">
  665.       <xsl:call-template name="ForceFalseStrVal">
  666.         <xsl:with-param name="str" select="$sLowerGrow" />
  667.       </xsl:call-template>
  668.     </xsl:variable>
  669.  
  670.     <xsl:variable name="fSupHide">
  671.       <xsl:call-template name="ForceFalseStrVal">
  672.         <xsl:with-param name="str" select="$sLowerCaseSupHide" />
  673.       </xsl:call-template>
  674.     </xsl:variable>
  675.  
  676.     <xsl:variable name="fSubHide">
  677.       <xsl:call-template name="ForceFalseStrVal">
  678.         <xsl:with-param name="str" select="$sLowerCaseSubHide" />
  679.       </xsl:call-template>
  680.     </xsl:variable>
  681.  
  682.     <mml:mrow>
  683.       <xsl:choose>
  684.         <xsl:when test="$fSupHide=1 and $fSubHide=1">
  685.           <xsl:call-template name="OutputNaryMo">
  686.             <xsl:with-param name="ndCur" select="." />
  687.             <xsl:with-param name="fGrow" select="$fGrow" />
  688.           </xsl:call-template>
  689.         </xsl:when>
  690.         <xsl:when test="$fSubHide=1">
  691.           <xsl:choose>
  692.             <xsl:when test="$fLimLocSubSup=1">
  693.               <mml:msup>
  694.                 <xsl:call-template name="OutputNaryMo">
  695.                   <xsl:with-param name="ndCur" select="." />
  696.                   <xsl:with-param name="fGrow" select="$fGrow" />
  697.                 </xsl:call-template>
  698.                 <mml:mrow>
  699.                   <xsl:apply-templates select="m:sup[1]" />
  700.                 </mml:mrow>
  701.               </mml:msup>
  702.             </xsl:when>
  703.             <xsl:otherwise>
  704.               <mml:mover>
  705.                 <xsl:call-template name="OutputNaryMo">
  706.                   <xsl:with-param name="ndCur" select="." />
  707.                   <xsl:with-param name="fGrow" select="$fGrow" />
  708.                 </xsl:call-template>
  709.                 <mml:mrow>
  710.                   <xsl:apply-templates select="m:sup[1]" />
  711.                 </mml:mrow>
  712.               </mml:mover>
  713.             </xsl:otherwise>
  714.           </xsl:choose>
  715.         </xsl:when>
  716.         <xsl:when test="$fSupHide=1">
  717.           <xsl:choose>
  718.             <xsl:when test="$fLimLocSubSup=1">
  719.               <mml:msub>
  720.                 <xsl:call-template name="OutputNaryMo">
  721.                   <xsl:with-param name="ndCur" select="." />
  722.                   <xsl:with-param name="fGrow" select="$fGrow" />
  723.                 </xsl:call-template>
  724.                 <mml:mrow>
  725.                   <xsl:apply-templates select="m:sub[1]" />
  726.                 </mml:mrow>
  727.               </mml:msub>
  728.             </xsl:when>
  729.             <xsl:otherwise>
  730.               <mml:munder>
  731.                 <xsl:call-template name="OutputNaryMo">
  732.                   <xsl:with-param name="ndCur" select="." />
  733.                   <xsl:with-param name="fGrow" select="$fGrow" />
  734.                 </xsl:call-template>
  735.                 <mml:mrow>
  736.                   <xsl:apply-templates select="m:sub[1]" />
  737.                 </mml:mrow>
  738.               </mml:munder>
  739.             </xsl:otherwise>
  740.           </xsl:choose>
  741.         </xsl:when>
  742.         <xsl:otherwise>
  743.           <xsl:choose>
  744.             <xsl:when test="$fLimLocSubSup=1">
  745.               <mml:msubsup>
  746.                 <xsl:call-template name="OutputNaryMo">
  747.                   <xsl:with-param name="ndCur" select="." />
  748.                   <xsl:with-param name="fGrow" select="$fGrow" />
  749.                 </xsl:call-template>
  750.                 <mml:mrow>
  751.                   <xsl:apply-templates select="m:sub[1]" />
  752.                 </mml:mrow>
  753.                 <mml:mrow>
  754.                   <xsl:apply-templates select="m:sup[1]" />
  755.                 </mml:mrow>
  756.               </mml:msubsup>
  757.             </xsl:when>
  758.             <xsl:otherwise>
  759.               <mml:munderover>
  760.                 <xsl:call-template name="OutputNaryMo">
  761.                   <xsl:with-param name="ndCur" select="." />
  762.                   <xsl:with-param name="fGrow" select="$fGrow" />
  763.                 </xsl:call-template>
  764.                 <mml:mrow>
  765.                   <xsl:apply-templates select="m:sub[1]" />
  766.                 </mml:mrow>
  767.                 <mml:mrow>
  768.                   <xsl:apply-templates select="m:sup[1]" />
  769.                 </mml:mrow>
  770.               </mml:munderover>
  771.             </xsl:otherwise>
  772.           </xsl:choose>
  773.         </xsl:otherwise>
  774.       </xsl:choose>
  775.       <mml:mrow>
  776.         <xsl:apply-templates select="m:e[1]" />
  777.       </mml:mrow>
  778.     </mml:mrow>
  779.   </xsl:template>
  780.  
  781.   <xsl:template match="m:limLow">
  782.     <mml:munder>
  783.       <mml:mrow>
  784.         <xsl:apply-templates select="m:e[1]" />
  785.       </mml:mrow>
  786.       <mml:mrow>
  787.         <xsl:apply-templates select="m:lim[1]" />
  788.       </mml:mrow>
  789.     </mml:munder>
  790.   </xsl:template>
  791.  
  792.   <xsl:template match="m:limUpp">
  793.     <mml:mover>
  794.       <mml:mrow>
  795.         <xsl:apply-templates select="m:e[1]" />
  796.       </mml:mrow>
  797.       <mml:mrow>
  798.         <xsl:apply-templates select="m:lim[1]" />
  799.       </mml:mrow>
  800.     </mml:mover>
  801.   </xsl:template>
  802.  
  803.   <xsl:template match="m:sSub">
  804.     <mml:msub>
  805.       <mml:mrow>
  806.         <xsl:apply-templates select="m:e[1]" />
  807.       </mml:mrow>
  808.       <mml:mrow>
  809.         <xsl:apply-templates select="m:sub[1]" />
  810.       </mml:mrow>
  811.     </mml:msub>
  812.   </xsl:template>
  813.  
  814.   <xsl:template match="m:sSup">
  815.     <mml:msup>
  816.       <mml:mrow>
  817.         <xsl:apply-templates select="m:e[1]" />
  818.       </mml:mrow>
  819.       <mml:mrow>
  820.         <xsl:apply-templates select="m:sup[1]" />
  821.       </mml:mrow>
  822.     </mml:msup>
  823.   </xsl:template>
  824.  
  825.   <xsl:template match="m:sSubSup">
  826.     <mml:msubsup>
  827.       <mml:mrow>
  828.         <xsl:apply-templates select="m:e[1]" />
  829.       </mml:mrow>
  830.       <mml:mrow>
  831.         <xsl:apply-templates select="m:sub[1]" />
  832.       </mml:mrow>
  833.       <mml:mrow>
  834.         <xsl:apply-templates select="m:sup[1]" />
  835.       </mml:mrow>
  836.     </mml:msubsup>
  837.   </xsl:template>
  838.  
  839.   <xsl:template match="m:groupChr">
  840.     <xsl:variable name="ndLastGroupChrPr" select="m:groupChrPr[last()]" />
  841.     <xsl:variable name="sLowerCasePos" select="translate($ndLastGroupChrPr/m:pos/@m:val, 
  842.                                                              'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 
  843.                                                              'abcdefghijklmnopqrstuvwxyz')" />
  844.  
  845.     <xsl:variable name="sLowerCaseVertJc" select="translate($ndLastGroupChrPr/m:vertJc/@m:val, 
  846.                                                              'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 
  847.                                                              'abcdefghijklmnopqrstuvwxyz')" />
  848.     <xsl:variable name="ndLastChr" select="$ndLastGroupChrPr/m:chr" />
  849.  
  850.     <xsl:variable name="chr">
  851.       <xsl:choose>
  852.         <xsl:when test="$ndLastChr and (not($ndLastChr/@m:val) or string-length($ndLastChr/@m:val) = 0)"></xsl:when>
  853.         <xsl:when test="string-length($ndLastChr/@m:val) >= 1">
  854.           <xsl:value-of select="substring($ndLastChr/@m:val,1,1)" />
  855.         </xsl:when>
  856.         <xsl:otherwise>
  857.           <xsl:text>⏟</xsl:text>
  858.         </xsl:otherwise>
  859.       </xsl:choose>
  860.     </xsl:variable>
  861.     <xsl:choose>
  862.       <xsl:when test="$sLowerCasePos = 'top'">
  863.         <xsl:choose>
  864.           <xsl:when test="$sLowerCaseVertJc = 'bot'">
  865.             <mml:mover accent="false">
  866.               <mml:mrow>
  867.                 <xsl:apply-templates select="m:e[1]" />
  868.               </mml:mrow>
  869.               <mml:mo>
  870.                 <xsl:value-of select="$chr" />
  871.               </mml:mo>
  872.             </mml:mover>
  873.           </xsl:when>
  874.           <xsl:otherwise>
  875.             <mml:munder accentunder="false">
  876.               <mml:mo>
  877.                 <xsl:value-of select="$chr" />
  878.               </mml:mo>
  879.               <mml:mrow>
  880.                 <xsl:apply-templates select="m:e[1]" />
  881.               </mml:mrow>
  882.             </mml:munder>
  883.           </xsl:otherwise>
  884.         </xsl:choose>
  885.       </xsl:when>
  886.       <xsl:otherwise>
  887.         <xsl:choose>
  888.           <xsl:when test="$sLowerCaseVertJc = 'bot'">
  889.             <mml:mover accent="false">
  890.               <mml:mo>
  891.                 <xsl:value-of select="$chr" />
  892.               </mml:mo>
  893.               <mml:mrow>
  894.                 <xsl:apply-templates select="m:e[1]" />
  895.               </mml:mrow>
  896.             </mml:mover>
  897.           </xsl:when>
  898.           <xsl:otherwise>
  899.             <mml:munder accentunder="false">
  900.               <mml:mrow>
  901.                 <xsl:apply-templates select="m:e[1]" />
  902.               </mml:mrow>
  903.               <mml:mo>
  904.                 <xsl:value-of select="$chr" />
  905.               </mml:mo>
  906.             </mml:munder>
  907.           </xsl:otherwise>
  908.         </xsl:choose>
  909.       </xsl:otherwise>
  910.     </xsl:choose>
  911.   </xsl:template>
  912.  
  913.   <xsl:template name="fName">
  914.     <xsl:for-each select="m:fName/*">
  915.       <xsl:apply-templates select="." />
  916.     </xsl:for-each>
  917.   </xsl:template>
  918.  
  919.   <xsl:template match="m:func">
  920.     <mml:mrow>
  921.       <mml:mrow>
  922.         <xsl:call-template name="fName" />
  923.       </mml:mrow>
  924.       <mml:mo>⁡</mml:mo>
  925.       <mml:mrow>
  926.         <xsl:apply-templates select="m:e" />
  927.       </mml:mrow>
  928.     </mml:mrow>
  929.   </xsl:template>
  930.  
  931.   <!-- %%Template: match m:f 
  932.         
  933.         m:f maps directly to mfrac. 
  934.     -->
  935.   <xsl:template match="m:f">
  936.     <xsl:variable name="sLowerCaseType" select="translate(m:fPr[last()]/m:type/@m:val, 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz')" />
  937.     <xsl:choose>
  938.       <xsl:when test="$sLowerCaseType='lin'">
  939.         <mml:mrow>
  940.           <mml:mrow>
  941.             <xsl:apply-templates select="m:num[1]" />
  942.           </mml:mrow>
  943.           <mml:mo>/</mml:mo>
  944.           <mml:mrow>
  945.             <xsl:apply-templates select="m:den[1]" />
  946.           </mml:mrow>
  947.         </mml:mrow>
  948.       </xsl:when>
  949.       <xsl:otherwise>
  950.         <mml:mfrac>
  951.           <xsl:call-template name="CreateMathMLFracProp">
  952.             <xsl:with-param name="type" select="$sLowerCaseType" />
  953.           </xsl:call-template>
  954.           <mml:mrow>
  955.             <xsl:apply-templates select="m:num[1]" />
  956.           </mml:mrow>
  957.           <mml:mrow>
  958.             <xsl:apply-templates select="m:den[1]" />
  959.           </mml:mrow>
  960.         </mml:mfrac>
  961.       </xsl:otherwise>
  962.     </xsl:choose>
  963.  
  964.   </xsl:template>
  965.  
  966.  
  967.   <!-- %%Template: CreateMathMLFracProp 
  968.         
  969.             Make fraction properties based on supplied parameters.
  970.             OMML differentiates between a linear fraction and a skewed
  971.             one. For MathML, we write both as bevelled.
  972.     -->
  973.   <xsl:template name="CreateMathMLFracProp">
  974.     <xsl:param name="type" />
  975.     <xsl:variable name="sLowerCaseType" select="translate($type, 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz')" />
  976.  
  977.     <xsl:if test="$sLowerCaseType='skw' or $sLowerCaseType='lin'">
  978.       <xsl:attribute name="bevelled">true</xsl:attribute>
  979.     </xsl:if>
  980.     <xsl:if test="$sLowerCaseType='nobar'">
  981.       <xsl:attribute name="linethickness">0pt</xsl:attribute>
  982.     </xsl:if>
  983.     <xsl:choose>
  984.       <xsl:when test="sLowerCaseNumJc='right'">
  985.         <xsl:attribute name="numalign">right</xsl:attribute>
  986.       </xsl:when>
  987.       <xsl:when test="sLowerCaseNumJc='left'">
  988.         <xsl:attribute name="numalign">left</xsl:attribute>
  989.       </xsl:when>
  990.     </xsl:choose>
  991.     <xsl:choose>
  992.       <xsl:when test="sLowerCaseDenJc='right'">
  993.         <xsl:attribute name="numalign">right</xsl:attribute>
  994.       </xsl:when>
  995.       <xsl:when test="sLowerCaseDenJc='left'">
  996.         <xsl:attribute name="numalign">left</xsl:attribute>
  997.       </xsl:when>
  998.     </xsl:choose>
  999.   </xsl:template>
  1000.  
  1001.   <!-- %%Template: match m:e | m:den | m:num | m:lim | m:sup | m:sub 
  1002.         
  1003.         These element delinate parts of an expression (like the numerator).  -->
  1004.   <xsl:template match="m:e | m:den | m:num | m:lim | m:sup | m:sub">
  1005.     <xsl:choose>
  1006.  
  1007.       <!-- If there is no scriptLevel specified, just call through -->
  1008.       <xsl:when test="not(m:argPr[last()]/m:scrLvl/@m:val)">
  1009.         <xsl:apply-templates select="*" />
  1010.       </xsl:when>
  1011.  
  1012.       <!-- Otherwise, create an mstyle and set the script level -->
  1013.       <xsl:otherwise>
  1014.         <mml:mstyle>
  1015.           <xsl:attribute name="scriptlevel">
  1016.             <xsl:value-of select="m:argPr[last()]/m:scrLvl/@m:val" />
  1017.           </xsl:attribute>
  1018.           <xsl:apply-templates select="*" />
  1019.         </mml:mstyle>
  1020.       </xsl:otherwise>
  1021.     </xsl:choose>
  1022.   </xsl:template>
  1023.  
  1024.   <xsl:template match="m:bar">
  1025.     <xsl:variable name="sLowerCasePos" select="translate(m:barPr/m:pos/@m:val, 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 
  1026.                                                                                'abcdefghijklmnopqrstuvwxyz')" />
  1027.  
  1028.     <xsl:variable name="fTop">
  1029.  
  1030.       <xsl:choose>
  1031.         <xsl:when test="$sLowerCasePos='top'">1</xsl:when>
  1032.         <xsl:otherwise>0</xsl:otherwise>
  1033.       </xsl:choose>
  1034.     </xsl:variable>
  1035.     <xsl:choose>
  1036.       <xsl:when test="$fTop=1">
  1037.         <mml:mover accent="false">
  1038.           <mml:mrow>
  1039.             <xsl:apply-templates select="m:e[1]" />
  1040.           </mml:mrow>
  1041.           <mml:mo>
  1042.             <xsl:text>¯</xsl:text>
  1043.           </mml:mo>
  1044.         </mml:mover>
  1045.       </xsl:when>
  1046.       <xsl:otherwise>
  1047.         <mml:munder underaccent="false">
  1048.           <mml:mrow>
  1049.             <xsl:apply-templates select="m:e[1]" />
  1050.           </mml:mrow>
  1051.           <mml:mo>
  1052.             <xsl:text>_</xsl:text>
  1053.           </mml:mo>
  1054.         </mml:munder>
  1055.       </xsl:otherwise>
  1056.     </xsl:choose>
  1057.   </xsl:template>
  1058.  
  1059.   <!-- %%Template match m:d
  1060.  
  1061.         Process a delimiter. 
  1062.     -->
  1063.   <xsl:template match="m:d">
  1064.     <mml:mfenced>
  1065.       <!-- open: default is '(' for both OMML and MathML -->
  1066.       <xsl:if test="m:dPr[1]/m:begChr/@m:val and not(m:dPr[1]/m:begChr/@m:val ='(')">
  1067.         <xsl:attribute name="open">
  1068.           <xsl:value-of select="m:dPr[1]/m:begChr/@m:val" />
  1069.         </xsl:attribute>
  1070.       </xsl:if>
  1071.  
  1072.       <!-- close: default is ')' for both OMML and MathML -->
  1073.       <xsl:if test="m:dPr[1]/m:endChr/@m:val and not(m:dPr[1]/m:endChr/@m:val =')')">
  1074.         <xsl:attribute name="close">
  1075.           <xsl:value-of select="m:dPr[1]/m:endChr/@m:val" />
  1076.         </xsl:attribute>
  1077.       </xsl:if>
  1078.  
  1079.       <!-- separator: the default is ',' for MathML, and '|' for OMML -->
  1080.       <xsl:choose>
  1081.         <!-- Matches MathML default. Write nothing -->
  1082.         <xsl:when test="m:dPr[1]/m:sepChr/@m:val = ','" />
  1083.  
  1084.         <!-- OMML default: | -->
  1085.         <xsl:when test="not(m:dPr[1]/m:sepChr/@m:val)">
  1086.           <xsl:attribute name="separators">
  1087.             <xsl:value-of select="'|'" />
  1088.           </xsl:attribute>
  1089.         </xsl:when>
  1090.  
  1091.         <xsl:otherwise>
  1092.           <xsl:attribute name="separators">
  1093.             <xsl:value-of select="m:dPr[1]/m:sepChr/@m:val" />
  1094.           </xsl:attribute>
  1095.         </xsl:otherwise>
  1096.       </xsl:choose>
  1097.  
  1098.       <!-- now write all the children. Put each one into an mrow
  1099.             just in case it produces multiple runs, etc -->
  1100.       <xsl:for-each select="m:e">
  1101.         <mml:mrow>
  1102.           <xsl:apply-templates select="." />
  1103.         </mml:mrow>
  1104.       </xsl:for-each>
  1105.     </mml:mfenced>
  1106.   </xsl:template>
  1107.  
  1108.   <xsl:template match="m:r">
  1109.     <xsl:variable name="fNor">
  1110.       <xsl:choose>
  1111.         <xsl:when test="count(child::m:rPr[last()]/m:nor) = 0">0</xsl:when>
  1112.         <xsl:otherwise>
  1113.           <xsl:call-template name="ForceFalseStrVal">
  1114.             <xsl:with-param name="str" select="translate(child::m:rPr[last()]/m:nor/@m:val, 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 
  1115.                                                                                'abcdefghijklmnopqrstuvwxyz')" />
  1116.           </xsl:call-template>
  1117.         </xsl:otherwise>
  1118.       </xsl:choose>
  1119.     </xsl:variable>
  1120.  
  1121.     <xsl:choose>
  1122.       <xsl:when test="$fNor=1">
  1123.         <mml:mtext>
  1124.           <xsl:variable name="sOutput" select="translate(.//m:t, ' ', ' ')" />
  1125.           <xsl:value-of select="$sOutput" />
  1126.         </mml:mtext>
  1127.       </xsl:when>
  1128.       <xsl:otherwise>
  1129.         <xsl:for-each select=".//m:t">
  1130.           <xsl:call-template name="ParseMt">
  1131.             <xsl:with-param name="sToParse" select="text()" />
  1132.             <xsl:with-param name="scr" select="../m:rPr[last()]/m:scr/@m:val" />
  1133.             <xsl:with-param name="sty" select="../m:rPr[last()]/m:sty/@m:val" />
  1134.             <xsl:with-param name="nor">0</xsl:with-param>
  1135.           </xsl:call-template>
  1136.         </xsl:for-each>
  1137.       </xsl:otherwise>
  1138.     </xsl:choose>
  1139.   </xsl:template>
  1140.  
  1141.  
  1142.   <xsl:template name="CreateTokenAttributes">
  1143.     <xsl:param name="scr" />
  1144.     <xsl:param name="sty" />
  1145.     <xsl:param name="nor" />
  1146.     <xsl:param name="nCharToPrint" />
  1147.     <xsl:param name="sTokenType" />
  1148.  
  1149.     <xsl:choose>
  1150.       <xsl:when test="$nor=1">
  1151.         <xsl:attribute name="mathvariant">normal</xsl:attribute>
  1152.       </xsl:when>
  1153.       <xsl:otherwise>
  1154.         <xsl:variable name="mathvariant">
  1155.           <xsl:choose>
  1156.             <!-- numbers don't care -->
  1157.             <xsl:when test="$sTokenType='mn'" />
  1158.  
  1159.             <xsl:when test="$scr='monospace'">monospace</xsl:when>
  1160.             <xsl:when test="$scr='sans-serif' and $sty='i'">sans-serif-italic</xsl:when>
  1161.             <xsl:when test="$scr='sans-serif' and $sty='b'">bold-sans-serif</xsl:when>
  1162.             <xsl:when test="$scr='sans-serif' and $sty='bi'">sans-serif-bold-italic</xsl:when>
  1163.             <xsl:when test="$scr='sans-serif'">sans-serif</xsl:when>
  1164.             <xsl:when test="$scr='fraktur' and ($sty='b' or $sty='bi')">bold-fraktur</xsl:when>
  1165.             <xsl:when test="$scr='fraktur'">fraktur</xsl:when>
  1166.             <xsl:when test="$scr='double-struck'">double-struck</xsl:when>
  1167.             <xsl:when test="$scr='script' and ($sty='b' or $sty='bi')">bold-script</xsl:when>
  1168.             <xsl:when test="$scr='script'">script</xsl:when>
  1169.             <xsl:when test="($scr='roman' or not($scr) or $scr='') and $sty='b'">bold</xsl:when>
  1170.             <xsl:when test="($scr='roman' or not($scr) or $scr='') and $sty='i'">italic</xsl:when>
  1171.             <xsl:when test="($scr='roman' or not($scr) or $scr='') and $sty='p'">normal</xsl:when>
  1172.             <xsl:when test="($scr='roman' or not($scr) or $scr='') and $sty='bi'">bold-italic</xsl:when>
  1173.             <xsl:otherwise />
  1174.           </xsl:choose>
  1175.         </xsl:variable>
  1176.         <xsl:variable name="fontweight">
  1177.           <xsl:choose>
  1178.             <xsl:when test="$sty='b' or $sty='bi'">bold</xsl:when>
  1179.             <xsl:otherwise>normal</xsl:otherwise>
  1180.           </xsl:choose>
  1181.         </xsl:variable>
  1182.         <xsl:variable name="fontstyle">
  1183.           <xsl:choose>
  1184.             <xsl:when test="$sty='p' or $sty='b'">normal</xsl:when>
  1185.             <xsl:otherwise>italic</xsl:otherwise>
  1186.           </xsl:choose>
  1187.         </xsl:variable>
  1188.  
  1189.         <!-- Writing of attributes begins here -->
  1190.         <xsl:choose>
  1191.           <!-- Don't write mathvariant for operators unless they want to be normal -->
  1192.           <xsl:when test="$sTokenType='mo' and $mathvariant!='normal'" />
  1193.  
  1194.           <!-- A single character within an mi is already italics, don't write -->
  1195.           <xsl:when test="$sTokenType='mi' and $nCharToPrint=1 and ($mathvariant='' or $mathvariant='italic')" />
  1196.  
  1197.           <xsl:when test="$sTokenType='mi' and $nCharToPrint > 1 and ($mathvariant='' or $mathvariant='italic')">
  1198.             <xsl:attribute name="mathvariant">
  1199.               <xsl:value-of select="'italic'" />
  1200.             </xsl:attribute>
  1201.           </xsl:when>
  1202.           <xsl:when test="$mathvariant!='italic' and $mathvariant!=''">
  1203.             <xsl:attribute name="mathvariant">
  1204.               <xsl:value-of select="$mathvariant" />
  1205.             </xsl:attribute>
  1206.           </xsl:when>
  1207.           <xsl:otherwise>
  1208.             <xsl:if test="not($sTokenType='mi' and $nCharToPrint=1) and $fontstyle='italic'">
  1209.               <xsl:attribute name="fontstyle">italic</xsl:attribute>
  1210.             </xsl:if>
  1211.             <xsl:if test="$fontweight='bold'">
  1212.               <xsl:attribute name="fontweight">bold</xsl:attribute>
  1213.             </xsl:if>
  1214.           </xsl:otherwise>
  1215.         </xsl:choose>
  1216.       </xsl:otherwise>
  1217.     </xsl:choose>
  1218.   </xsl:template>
  1219.  
  1220.   <xsl:template match="m:eqArr">
  1221.     <mml:mtable>
  1222.       <xsl:for-each select="m:e">
  1223.         <mml:mtr>
  1224.           <mml:mtd>
  1225.             <xsl:choose>
  1226.               <xsl:when test="m:argPr[last()]/m:scrLvl/@m:val!='0' or 
  1227.                                 not(m:argPr[last()]/m:scrLvl/@m:val)  or 
  1228.                                 m:argPr[last()]/m:scrLvl/@m:val=''">
  1229.                 <mml:mrow>
  1230.                   <mml:maligngroup />
  1231.                   <xsl:call-template name="CreateEqArrRow">
  1232.                     <xsl:with-param name="align" select="1" />
  1233.                     <xsl:with-param name="ndCur" select="*[1]" />
  1234.                   </xsl:call-template>
  1235.                 </mml:mrow>
  1236.               </xsl:when>
  1237.               <xsl:otherwise>
  1238.                 <mml:mstyle>
  1239.                   <xsl:attribute name="scriptlevel">
  1240.                     <xsl:value-of select="m:argPr[last()]/m:scrLvl/@m:val" />
  1241.                   </xsl:attribute>
  1242.                   <mml:maligngroup />
  1243.                   <xsl:call-template name="CreateEqArrRow">
  1244.                     <xsl:with-param name="align" select="1" />
  1245.                     <xsl:with-param name="ndCur" select="*[1]" />
  1246.                   </xsl:call-template>
  1247.                 </mml:mstyle>
  1248.               </xsl:otherwise>
  1249.             </xsl:choose>
  1250.           </mml:mtd>
  1251.         </mml:mtr>
  1252.       </xsl:for-each>
  1253.     </mml:mtable>
  1254.   </xsl:template>
  1255.  
  1256.   <xsl:template name="CreateEqArrRow">
  1257.     <xsl:param name="align" />
  1258.     <xsl:param name="ndCur" />
  1259.     <xsl:variable name="sAllMt">
  1260.       <xsl:for-each select="$ndCur/m:t">
  1261.         <xsl:value-of select="." />
  1262.       </xsl:for-each>
  1263.     </xsl:variable>
  1264.     <xsl:choose>
  1265.       <xsl:when test="$ndCur/self::m:r">
  1266.         <xsl:call-template name="ParseEqArrMr">
  1267.           <xsl:with-param name="sToParse" select="$sAllMt" />
  1268.           <xsl:with-param name="scr" select="../m:rPr[last()]/m:scr/@m:val" />
  1269.           <xsl:with-param name="sty" select="../m:rPr[last()]/m:sty/@m:val" />
  1270.           <xsl:with-param name="nor">
  1271.             <xsl:choose>
  1272.               <xsl:when test="count($ndCur/m:rPr[last()]/m:nor) = 0">0</xsl:when>
  1273.               <xsl:otherwise>
  1274.                 <xsl:call-template name="ForceFalseStrVal">
  1275.                   <xsl:with-param name="str" select="translate($ndCur/m:rPr[last()]/m:nor/@m:val, 
  1276.                                                                      'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 
  1277.                                                                          'abcdefghijklmnopqrstuvwxyz')" />
  1278.                 </xsl:call-template>
  1279.               </xsl:otherwise>
  1280.             </xsl:choose>
  1281.           </xsl:with-param>
  1282.           <xsl:with-param name="align" select="$align" />
  1283.         </xsl:call-template>
  1284.       </xsl:when>
  1285.       <xsl:otherwise>
  1286.         <xsl:apply-templates select="$ndCur" />
  1287.       </xsl:otherwise>
  1288.     </xsl:choose>
  1289.     <xsl:if test="count($ndCur/following-sibling::*) > 0">
  1290.       <xsl:variable name="cAmp">
  1291.         <xsl:call-template name="CountAmp">
  1292.           <xsl:with-param name="sAllMt" select="$sAllMt" />
  1293.           <xsl:with-param name="cAmp" select="0" />
  1294.         </xsl:call-template>
  1295.       </xsl:variable>
  1296.       <xsl:call-template name="CreateEqArrRow">
  1297.         <xsl:with-param name="align" select="($align+($cAmp mod 2)) mod 2" />
  1298.         <xsl:with-param name="ndCur" select="$ndCur/following-sibling::*[1]" />
  1299.       </xsl:call-template>
  1300.     </xsl:if>
  1301.   </xsl:template>
  1302.  
  1303.   <xsl:template name="CountAmp">
  1304.     <xsl:param name="sAllMt" />
  1305.     <xsl:param name="cAmp" />
  1306.     <xsl:choose>
  1307.       <xsl:when test="string-length(substring-after($sAllMt, '&')) > 0 or 
  1308.                             substring($sAllMt, string-length($sAllMt))='&'">
  1309.         <xsl:call-template name="CountAmp">
  1310.           <xsl:with-param name="sAllMt" select="substring-after($sAllMt, '&')" />
  1311.           <xsl:with-param name="cAmp" select="$cAmp+1" />
  1312.         </xsl:call-template>
  1313.       </xsl:when>
  1314.       <xsl:otherwise>
  1315.         <xsl:value-of select="$cAmp" />
  1316.       </xsl:otherwise>
  1317.     </xsl:choose>
  1318.   </xsl:template>
  1319.  
  1320.   <!-- %%Template: ParseEqArrMr
  1321.             
  1322.             Similar to ParseMt, but this one has to do more for an equation array. 
  1323.       In equation arrays & is a special character which denotes alignment.
  1324.       
  1325.       The & in an equation works by alternating between meaning insert alignment spacing
  1326.       and insert alignment mark.  For each equation in the equation array
  1327.       there is an implied align space at the beginning of the equation.  Within each equation,
  1328.       the first & means alignmark, the second, align space, the third, alignmark, etc.
  1329.       
  1330.       For this reason when parsing m:r's in equation arrays it is important to keep track of what
  1331.       the next ampersand will mean.
  1332.       
  1333.       $align=0 => Omml's align space, which is similar to MathML's maligngroup.
  1334.       $align=1 => Omml's alignment mark, which is similar to MathML's malignmark.
  1335.     -->
  1336.   <xsl:template name="ParseEqArrMr">
  1337.     <xsl:param name="sToParse" />
  1338.     <xsl:param name="sty" />
  1339.     <xsl:param name="scr" />
  1340.     <xsl:param name="nor" />
  1341.     <xsl:param name="align" />
  1342.  
  1343.     <xsl:if test="string-length($sToParse) > 0">
  1344.       <xsl:choose>
  1345.         <xsl:when test="substring($sToParse,1,1) = '&'">
  1346.           <xsl:choose>
  1347.             <xsl:when test="$align='0'">
  1348.               <mml:maligngroup />
  1349.             </xsl:when>
  1350.             <xsl:when test="$align='1'">
  1351.               <mml:malignmark />
  1352.             </xsl:when>
  1353.           </xsl:choose>
  1354.           <xsl:call-template name="ParseEqArrMr">
  1355.             <xsl:with-param name="sToParse" select="substring($sToParse,2)" />
  1356.             <xsl:with-param name="scr" select="$scr" />
  1357.             <xsl:with-param name="sty" select="$sty" />
  1358.             <xsl:with-param name="nor" select="$nor" />
  1359.             <xsl:with-param name="align">
  1360.               <xsl:choose>
  1361.                 <xsl:when test="$align='1'">0</xsl:when>
  1362.                 <xsl:otherwise>1</xsl:otherwise>
  1363.               </xsl:choose>
  1364.             </xsl:with-param>
  1365.           </xsl:call-template>
  1366.         </xsl:when>
  1367.         <xsl:otherwise>
  1368.           <xsl:variable name="sRepNumWith0">
  1369.             <xsl:call-template name="SReplaceNumWithZero">
  1370.               <xsl:with-param name="sToParse" select="$sToParse" />
  1371.             </xsl:call-template>
  1372.           </xsl:variable>
  1373.           <xsl:variable name="sRepOperWith-">
  1374.             <xsl:call-template name="SReplaceOperWithMinus">
  1375.               <xsl:with-param name="sToParse" select="$sRepNumWith0" />
  1376.             </xsl:call-template>
  1377.           </xsl:variable>
  1378.  
  1379.           <xsl:variable name="iFirstOper" select="string-length($sRepOperWith-) - string-length(substring-after($sRepOperWith-, '-'))" />
  1380.           <xsl:variable name="iFirstNum" select="string-length($sRepOperWith-) - string-length(substring-after($sRepOperWith-, '0'))" />
  1381.           <xsl:variable name="iFirstAmp" select="string-length($sRepOperWith-) - string-length(substring-after($sRepOperWith-, '&'))" />
  1382.           <xsl:variable name="fNumAtPos1">
  1383.             <xsl:choose>
  1384.               <xsl:when test="substring($sRepOperWith-,1,1)='0'">1</xsl:when>
  1385.               <xsl:otherwise>0</xsl:otherwise>
  1386.             </xsl:choose>
  1387.           </xsl:variable>
  1388.           <xsl:variable name="fOperAtPos1">
  1389.             <xsl:choose>
  1390.               <xsl:when test="substring($sRepOperWith-,1,1)='-'">1</xsl:when>
  1391.               <xsl:otherwise>0</xsl:otherwise>
  1392.             </xsl:choose>
  1393.           </xsl:variable>
  1394.           <xsl:choose>
  1395.  
  1396.             <!-- Case I: The string begins with neither a number, nor an operator -->
  1397.             <xsl:when test="$fNumAtPos1='0' and $fOperAtPos1='0'">
  1398.               <xsl:choose>
  1399.                 <xsl:when test="$nor = 0">
  1400.                   <mml:mi>
  1401.                     <xsl:call-template name="CreateTokenAttributes">
  1402.                       <xsl:with-param name="scr" select="$scr" />
  1403.                       <xsl:with-param name="sty" select="$sty" />
  1404.                       <xsl:with-param name="nor" select="$nor" />
  1405.                       <xsl:with-param name="nCharToPrint" select="1" />
  1406.                       <xsl:with-param name="sTokenType" select="'mi'" />
  1407.                     </xsl:call-template>
  1408.                     <xsl:variable name="sOutput" select="translate(substring($sToParse, 1, 1), ' ', ' ')" />
  1409.                     <xsl:value-of select="$sOutput" />
  1410.                   </mml:mi>
  1411.                 </xsl:when>
  1412.                 <xsl:otherwise>
  1413.                   <mml:mtext>
  1414.                     <xsl:variable name="sOutput" select="translate(substring($sToParse, 1, 1), ' ', ' ')" />
  1415.                     <xsl:value-of select="$sOutput" />
  1416.                   </mml:mtext>
  1417.                 </xsl:otherwise>
  1418.               </xsl:choose>
  1419.               <xsl:call-template name="ParseEqArrMr">
  1420.                 <xsl:with-param name="sToParse" select="substring($sToParse, 2)" />
  1421.                 <xsl:with-param name="scr" select="$scr" />
  1422.                 <xsl:with-param name="sty" select="$sty" />
  1423.                 <xsl:with-param name="nor" select="$nor" />
  1424.                 <xsl:with-param name="align" select="$align" />
  1425.               </xsl:call-template>
  1426.             </xsl:when>
  1427.  
  1428.             <!-- Case II: There is an operator at position 1 -->
  1429.             <xsl:when test="$fOperAtPos1='1'">
  1430.               <xsl:choose>
  1431.                 <xsl:when test="$nor = 0">
  1432.                   <mml:mo>
  1433.                     <xsl:call-template name="CreateTokenAttributes">
  1434.                       <xsl:with-param name="scr" />
  1435.                       <xsl:with-param name="sty" />
  1436.                       <xsl:with-param name="nor" select="$nor" />
  1437.                       <xsl:with-param name="sTokenType" select="'mo'" />
  1438.                     </xsl:call-template>
  1439.                     <xsl:value-of select="substring($sToParse,1,1)" />
  1440.                   </mml:mo>
  1441.                 </xsl:when>
  1442.                 <xsl:otherwise>
  1443.                   <mml:mtext>
  1444.                     <xsl:value-of select="substring($sToParse,1,1)" />
  1445.                   </mml:mtext>                  
  1446.                 </xsl:otherwise>
  1447.               </xsl:choose>
  1448.               <xsl:call-template name="ParseEqArrMr">
  1449.                 <xsl:with-param name="sToParse" select="substring($sToParse, 2)" />
  1450.                 <xsl:with-param name="scr" select="$scr" />
  1451.                 <xsl:with-param name="sty" select="$sty" />
  1452.                 <xsl:with-param name="nor" select="$nor" />
  1453.                 <xsl:with-param name="align" select="$align" />
  1454.               </xsl:call-template>
  1455.             </xsl:when>
  1456.  
  1457.             <!-- Case III: There is a number at position 1 -->
  1458.             <xsl:otherwise>
  1459.               <xsl:variable name="sConsecNum">
  1460.                 <xsl:call-template name="SNumStart">
  1461.                   <xsl:with-param name="sToParse" select="$sToParse" />
  1462.                   <xsl:with-param name="sPattern" select="$sRepNumWith0" />
  1463.                 </xsl:call-template>
  1464.               </xsl:variable>
  1465.               <xsl:choose>
  1466.                 <xsl:when test="$nor = 0">
  1467.                   <mml:mn>
  1468.                     <xsl:call-template name="CreateTokenAttributes">
  1469.                       <xsl:with-param name="scr" />
  1470.                       <xsl:with-param name="sty" select="'p'"/>
  1471.                       <xsl:with-param name="nor" select="$nor" />
  1472.                       <xsl:with-param name="sTokenType" select="'mn'" />
  1473.                     </xsl:call-template>
  1474.                     <xsl:value-of select="$sConsecNum" />
  1475.                   </mml:mn>
  1476.                 </xsl:when>
  1477.                 <xsl:otherwise>
  1478.                   <mml:mtext>
  1479.                     <xsl:value-of select="$sConsecNum" />
  1480.                   </mml:mtext>
  1481.                 </xsl:otherwise>
  1482.               </xsl:choose>
  1483.               <xsl:call-template name="ParseEqArrMr">
  1484.                 <xsl:with-param name="sToParse" select="substring-after($sToParse, $sConsecNum)" />
  1485.                 <xsl:with-param name="scr" select="$scr" />
  1486.                 <xsl:with-param name="sty" select="$sty" />
  1487.                 <xsl:with-param name="nor" select="$nor" />
  1488.                 <xsl:with-param name="align" select="$align" />
  1489.               </xsl:call-template>
  1490.             </xsl:otherwise>
  1491.           </xsl:choose>
  1492.         </xsl:otherwise>
  1493.       </xsl:choose>
  1494.     </xsl:if>
  1495.   </xsl:template>
  1496.  
  1497.   <!-- %%Template: ParseMt
  1498.  
  1499.             Produce a run of text. Technically, OMML makes no distinction 
  1500.             between numbers, operators, and other characters in a run. For 
  1501.             MathML we need to break these into mi, mn, or mo elements. 
  1502.             
  1503.             See also ParseEqArrMr
  1504.     -->
  1505.   <xsl:template name="ParseMt">
  1506.     <xsl:param name="sToParse" />
  1507.     <xsl:param name="sty" />
  1508.     <xsl:param name="scr" />
  1509.     <xsl:param name="nor" />
  1510.     <xsl:if test="string-length($sToParse) > 0">
  1511.       <xsl:variable name="sRepNumWith0">
  1512.         <xsl:call-template name="SReplaceNumWithZero">
  1513.           <xsl:with-param name="sToParse" select="$sToParse" />
  1514.         </xsl:call-template>
  1515.       </xsl:variable>
  1516.       <xsl:variable name="sRepOperWith-">
  1517.         <xsl:call-template name="SReplaceOperWithMinus">
  1518.           <xsl:with-param name="sToParse" select="$sRepNumWith0" />
  1519.         </xsl:call-template>
  1520.       </xsl:variable>
  1521.  
  1522.       <xsl:variable name="iFirstOper" select="string-length($sRepOperWith-) - string-length(substring-after($sRepOperWith-, '-'))" />
  1523.       <xsl:variable name="iFirstNum" select="string-length($sRepOperWith-) - string-length(substring-after($sRepOperWith-, '0'))" />
  1524.       <xsl:variable name="fNumAtPos1">
  1525.         <xsl:choose>
  1526.           <xsl:when test="substring($sRepOperWith-,1,1)='0'">1</xsl:when>
  1527.           <xsl:otherwise>0</xsl:otherwise>
  1528.         </xsl:choose>
  1529.       </xsl:variable>
  1530.       <xsl:variable name="fOperAtPos1">
  1531.         <xsl:choose>
  1532.           <xsl:when test="substring($sRepOperWith-,1,1)='-'">1</xsl:when>
  1533.           <xsl:otherwise>0</xsl:otherwise>
  1534.         </xsl:choose>
  1535.       </xsl:variable>
  1536.  
  1537.       <xsl:choose>
  1538.  
  1539.         <!-- Case I: The string begins with neither a number, nor an operator -->
  1540.         <xsl:when test="$fOperAtPos1='0' and $fNumAtPos1='0'">
  1541.           <xsl:variable name="nCharToPrint">
  1542.             <xsl:choose>
  1543.               <xsl:when test="ancestor::m:fName">
  1544.                 <xsl:choose>
  1545.                   <xsl:when test="($iFirstOper=$iFirstNum) and 
  1546.                                             ($iFirstOper=string-length($sToParse)) and
  1547.                                             (substring($sRepOperWith-, string-length($sRepOperWith-))!='0') and 
  1548.                                             (substring($sRepOperWith-, string-length($sRepOperWith-))!='-')">
  1549.                     <xsl:value-of select="string-length($sToParse)" />
  1550.                   </xsl:when>
  1551.                   <xsl:when test="$iFirstOper < $iFirstNum">
  1552.                     <xsl:value-of select="$iFirstOper - 1" />
  1553.                   </xsl:when>
  1554.                   <xsl:otherwise>
  1555.                     <xsl:value-of select="$iFirstNum - 1" />
  1556.                   </xsl:otherwise>
  1557.                 </xsl:choose>
  1558.               </xsl:when>
  1559.               <xsl:otherwise>1</xsl:otherwise>
  1560.             </xsl:choose>
  1561.           </xsl:variable>
  1562.  
  1563.           <mml:mi>
  1564.             <xsl:call-template name="CreateTokenAttributes">
  1565.               <xsl:with-param name="scr" select="$scr" />
  1566.               <xsl:with-param name="sty" select="$sty" />
  1567.               <xsl:with-param name="nor" select="$nor" />
  1568.               <xsl:with-param name="nCharToPrint" select="$nCharToPrint" />
  1569.               <xsl:with-param name="sTokenType" select="'mi'" />
  1570.             </xsl:call-template>
  1571.             <xsl:variable name="sWrite" select="translate(substring($sToParse, 1, $nCharToPrint), ' ', ' ')" />
  1572.             <xsl:value-of select="$sWrite" />
  1573.           </mml:mi>
  1574.           <xsl:call-template name="ParseMt">
  1575.             <xsl:with-param name="sToParse" select="substring($sToParse, $nCharToPrint+1)" />
  1576.             <xsl:with-param name="scr" select="$scr" />
  1577.             <xsl:with-param name="sty" select="$sty" />
  1578.             <xsl:with-param name="nor" select="$nor" />
  1579.           </xsl:call-template>
  1580.         </xsl:when>
  1581.  
  1582.         <!-- Case II: There is an operator at position 1 -->
  1583.         <xsl:when test="$fOperAtPos1='1'">
  1584.           <mml:mo>
  1585.             <xsl:call-template name="CreateTokenAttributes">
  1586.               <xsl:with-param name="scr" />
  1587.               <xsl:with-param name="sty" />
  1588.               <xsl:with-param name="nor" select="$nor" />
  1589.               <xsl:with-param name="sTokenType" select="'mo'" />
  1590.             </xsl:call-template>
  1591.             <xsl:value-of select="substring($sToParse,1,1)" />
  1592.           </mml:mo>
  1593.           <xsl:call-template name="ParseMt">
  1594.             <xsl:with-param name="sToParse" select="substring($sToParse, 2)" />
  1595.             <xsl:with-param name="scr" select="$scr" />
  1596.             <xsl:with-param name="sty" select="$sty" />
  1597.             <xsl:with-param name="nor" select="$nor" />
  1598.           </xsl:call-template>
  1599.         </xsl:when>
  1600.  
  1601.         <!-- Case III: There is a number at position 1 -->
  1602.         <xsl:otherwise>
  1603.           <xsl:variable name="sConsecNum">
  1604.             <xsl:call-template name="SNumStart">
  1605.               <xsl:with-param name="sToParse" select="$sToParse" />
  1606.               <xsl:with-param name="sPattern" select="$sRepNumWith0" />
  1607.             </xsl:call-template>
  1608.           </xsl:variable>
  1609.           <mml:mn>
  1610.             <xsl:call-template name="CreateTokenAttributes">
  1611.               <xsl:with-param name="scr" select="$scr" />
  1612.               <xsl:with-param name="sty" select="'p'" />
  1613.               <xsl:with-param name="nor" select="$nor" />
  1614.               <xsl:with-param name="sTokenType" select="'mn'" />
  1615.             </xsl:call-template>
  1616.             <xsl:value-of select="$sConsecNum" />
  1617.           </mml:mn>
  1618.           <xsl:call-template name="ParseMt">
  1619.             <xsl:with-param name="sToParse" select="substring-after($sToParse, $sConsecNum)" />
  1620.             <xsl:with-param name="scr" select="$scr" />
  1621.             <xsl:with-param name="sty" select="$sty" />
  1622.             <xsl:with-param name="nor" select="$nor" />
  1623.           </xsl:call-template>
  1624.         </xsl:otherwise>
  1625.       </xsl:choose>
  1626.     </xsl:if>
  1627.   </xsl:template>
  1628.  
  1629.   <!-- %%Template: SNumStart 
  1630.     
  1631.         Return the longest substring of sToParse starting from the 
  1632.         start of sToParse that is a number. In addition, it takes the
  1633.         pattern string, which is sToParse with all of its numbers 
  1634.         replaced with a 0. sPattern should be the same length 
  1635.         as sToParse        
  1636.     -->
  1637.   <xsl:template name="SNumStart">
  1638.     <xsl:param name="sToParse" select="''" />
  1639.     <!-- if we don't get anything, take the string itself -->
  1640.     <xsl:param name="sPattern" select="'$sToParse'" />
  1641.  
  1642.  
  1643.     <xsl:choose>
  1644.       <!-- the pattern says this is a number, recurse with the rest -->
  1645.       <xsl:when test="substring($sPattern, 1, 1) = '0'">
  1646.         <xsl:call-template name="SNumStart">
  1647.           <xsl:with-param name="sToParse" select="$sToParse" />
  1648.           <xsl:with-param name="sPattern" select="substring($sPattern, 2)" />
  1649.         </xsl:call-template>
  1650.       </xsl:when>
  1651.  
  1652.       <!-- the pattern says we've run out of numbers. Take as many
  1653.                 characters from sToParse as we shaved off sPattern -->
  1654.       <xsl:otherwise>
  1655.         <xsl:value-of select="substring($sToParse, 1, string-length($sToParse) - string-length($sPattern))" />
  1656.       </xsl:otherwise>
  1657.     </xsl:choose>
  1658.   </xsl:template>
  1659.  
  1660.   <!-- %%Template SRepeatCharAcc
  1661.     
  1662.             The core of SRepeatChar with an accumulator. The current
  1663.             string is in param $acc, and we will double and recurse,
  1664.             if we're less than half of the required length or else just 
  1665.             add the right amount of characters to the accumulator and
  1666.             return
  1667.     -->
  1668.   <xsl:template name="SRepeatCharAcc">
  1669.     <xsl:param name="cchRequired" select="1" />
  1670.     <xsl:param name="ch" select="'-'" />
  1671.     <xsl:param name="acc" select="$ch" />
  1672.  
  1673.     <xsl:variable name="cchAcc" select="string-length($acc)" />
  1674.     <xsl:choose>
  1675.       <xsl:when test="(2 * $cchAcc) < $cchRequired">
  1676.         <xsl:call-template name="SRepeatCharAcc">
  1677.           <xsl:with-param name="cchRequired" select="$cchRequired" />
  1678.           <xsl:with-param name="ch" select="$ch" />
  1679.           <xsl:with-param name="acc" select="concat($acc, $acc)" />
  1680.         </xsl:call-template>
  1681.       </xsl:when>
  1682.  
  1683.       <xsl:otherwise>
  1684.         <xsl:value-of select="concat($acc, substring($acc, 1, $cchRequired - $cchAcc))" />
  1685.       </xsl:otherwise>
  1686.     </xsl:choose>
  1687.   </xsl:template>
  1688.  
  1689.  
  1690.   <!-- %%Template SRepeatChar
  1691.     
  1692.             Generates a string nchRequired long by repeating the given character ch
  1693.     -->
  1694.   <xsl:template name="SRepeatChar">
  1695.     <xsl:param name="cchRequired" select="1" />
  1696.     <xsl:param name="ch" select="'-'" />
  1697.  
  1698.     <xsl:call-template name="SRepeatCharAcc">
  1699.       <xsl:with-param name="cchRequired" select="$cchRequired" />
  1700.       <xsl:with-param name="ch" select="$ch" />
  1701.       <xsl:with-param name="acc" select="$ch" />
  1702.     </xsl:call-template>
  1703.   </xsl:template>
  1704.  
  1705.   <!-- %%Template SReplaceOperWithMinus
  1706.     
  1707.         Go through the given string and replace every instance
  1708.         of an operator with a minus '-'. This helps quickly identify
  1709.         the first instance of an operator.  
  1710.     -->
  1711.   <xsl:template name="SReplaceOperWithMinus">
  1712.     <xsl:param name="sToParse" select="''" />
  1713.  
  1714.     <xsl:value-of select="translate($sToParse, $sOperators, $sMinuses)" />
  1715.   </xsl:template>
  1716.  
  1717.   <!-- %%Template SReplaceNumWithZero
  1718.     
  1719.         Go through the given string and replace every instance
  1720.         of an number with a zero '0'. This helps quickly identify
  1721.         the first occurence of a number. 
  1722.         
  1723.         Considers the '.' and ',' part of a number iff they are sandwiched 
  1724.         between two other numbers. 0.3 will be recognized as a number,
  1725.         x.3 will not be. Since these characters can also be an operator, this 
  1726.         should be called before SReplaceOperWithMinus.
  1727.     -->
  1728.   <xsl:template name="SReplaceNumWithZero">
  1729.     <xsl:param name="sToParse" select="''" />
  1730.  
  1731.     <!-- First do a simple replace. Numbers will all be come 0's.
  1732.             After this point, the pattern involving the . or , that 
  1733.             we are looking for will become 0.0 or 0,0 -->
  1734.     <xsl:variable name="sSimpleReplace" select="translate($sToParse, $sNumbers, $sZeros)" />
  1735.  
  1736.     <!-- And then, replace 0.0 with just 000. This means that the . will 
  1737.             become part of the number -->
  1738.     <xsl:variable name="sReplacePeriod">
  1739.       <xsl:call-template name="SReplace">
  1740.         <xsl:with-param name="sInput" select="$sSimpleReplace" />
  1741.         <xsl:with-param name="sOrig" select="'0.0'" />
  1742.         <xsl:with-param name="sReplacement" select="'000'" />
  1743.       </xsl:call-template>
  1744.     </xsl:variable>
  1745.  
  1746.     <!-- And then, replace 0,0 with just 000. This means that the , will 
  1747.             become part of the number -->
  1748.     <xsl:call-template name="SReplace">
  1749.       <xsl:with-param name="sInput" select="$sReplacePeriod" />
  1750.       <xsl:with-param name="sOrig" select="'0,0'" />
  1751.       <xsl:with-param name="sReplacement" select="'000'" />
  1752.     </xsl:call-template>
  1753.   </xsl:template>
  1754.  
  1755.   <!-- Template to translate Word's borderBox properties into the menclose notation attribute
  1756.        The initial call to this SHOULD NOT pass an sAttribute.  Subsequent calls to 
  1757.        CreateMencloseNotationAttrFromBorderBoxAttr by CreateMencloseNotationAttrFromBorderBoxAttr will
  1758.        update the sAttribute as appropriate.
  1759.        
  1760.        CreateMencloseNotationAttrFromBorderBoxAttr looks at each attribute (fHideTop, fHideBot, etc.) one at a time
  1761.        in the order they are listed and passes a modified sAttribute to CreateMencloseNotationAttrFromBorderBoxAttr.
  1762.        Each successive call to CreateMencloseNotationAttrFromBorderBoxAttr knows which attribute to look at because 
  1763.        the previous call should have omitted passing the attribute it just analyzed.  This is why as you read lower 
  1764.        and lower in the template that each call to CreateMencloseNotationAttrFromBorderBoxAttr has fewer and fewer attributes.
  1765.        -->
  1766.   <xsl:template name="CreateMencloseNotationAttrFromBorderBoxAttr">
  1767.     <xsl:param name="fHideTop" />
  1768.     <xsl:param name="fHideBot" />
  1769.     <xsl:param name="fHideLeft" />
  1770.     <xsl:param name="fHideRight" />
  1771.     <xsl:param name="fStrikeH" />
  1772.     <xsl:param name="fStrikeV" />
  1773.     <xsl:param name="fStrikeBLTR" />
  1774.     <xsl:param name="fStrikeTLBR" />
  1775.     <xsl:param name="sAttribute" />
  1776.  
  1777.     <xsl:choose>
  1778.       <xsl:when test="string-length($sAttribute) = 0">
  1779.         <xsl:choose>
  1780.           <xsl:when test="string-length($fHideTop) > 0
  1781.                       and string-length($fHideBot) > 0 
  1782.                       and string-length($fHideLeft) > 0
  1783.                       and string-length($fHideRight) > 0">
  1784.  
  1785.             <xsl:choose>
  1786.               <xsl:when test="$fHideTop = 0 
  1787.                               and $fHideBot = 0
  1788.                               and $fHideLeft = 0 
  1789.                               and $fHideRight = 0">
  1790.                 <!-- We can use 'box' instead of top, bot, left, and right.  Therefore,
  1791.                   replace sAttribute with 'box' and begin analyzing params fStrikeH
  1792.                   and below. -->
  1793.                 <xsl:call-template name="CreateMencloseNotationAttrFromBorderBoxAttr">
  1794.                   <xsl:with-param name="fStrikeH" select="$fStrikeH" />
  1795.                   <xsl:with-param name="fStrikeV" select="$fStrikeV" />
  1796.                   <xsl:with-param name="fStrikeBLTR" select="$fStrikeBLTR" />
  1797.                   <xsl:with-param name="fStrikeTLBR" select="$fStrikeTLBR" />
  1798.                   <xsl:with-param name="sAttribute">
  1799.                     <xsl:text>box</xsl:text>
  1800.                   </xsl:with-param>
  1801.                 </xsl:call-template>
  1802.               </xsl:when>
  1803.               <xsl:otherwise>
  1804.                 <!-- Can't use 'box', theremore, must analyze all attributes -->
  1805.                 <xsl:call-template name="CreateMencloseNotationAttrFromBorderBoxAttr">
  1806.                   <xsl:with-param name="fHideTop" select="$fHideTop" />
  1807.                   <xsl:with-param name="fHideBot" select="$fHideBot" />
  1808.                   <xsl:with-param name="fHideLeft" select="$fHideLeft" />
  1809.                   <xsl:with-param name="fHideRight" select="$fHideRight" />
  1810.                   <xsl:with-param name="fStrikeH" select="$fStrikeH" />
  1811.                   <xsl:with-param name="fStrikeV" select="$fStrikeV" />
  1812.                   <xsl:with-param name="fStrikeBLTR" select="$fStrikeBLTR" />
  1813.                   <xsl:with-param name="fStrikeTLBR" select="$fStrikeTLBR" />
  1814.                   <xsl:with-param name="sAttribute">
  1815.                     <!-- Assume using all four (left right top bottom).  Subsequent calls
  1816.                          will remove the sides which aren't to be includes. -->
  1817.                     <xsl:text>left right top bottom</xsl:text>
  1818.                   </xsl:with-param>
  1819.                 </xsl:call-template>
  1820.               </xsl:otherwise>
  1821.             </xsl:choose>
  1822.           </xsl:when>
  1823.         </xsl:choose>
  1824.       </xsl:when>
  1825.       <xsl:otherwise>
  1826.         <xsl:choose>
  1827.           <xsl:when test="string-length($fHideTop) > 0">
  1828.             <xsl:choose>
  1829.               <xsl:when test="$fHideTop=1">
  1830.                 <xsl:call-template name="CreateMencloseNotationAttrFromBorderBoxAttr">
  1831.                   <xsl:with-param name="fHideBot" select="$fHideBot" />
  1832.                   <xsl:with-param name="fHideLeft" select="$fHideLeft" />
  1833.                   <xsl:with-param name="fHideRight" select="$fHideRight" />
  1834.                   <xsl:with-param name="fStrikeH" select="$fStrikeH" />
  1835.                   <xsl:with-param name="fStrikeV" select="$fStrikeV" />
  1836.                   <xsl:with-param name="fStrikeBLTR" select="$fStrikeBLTR" />
  1837.                   <xsl:with-param name="fStrikeTLBR" select="$fStrikeTLBR" />
  1838.                   <xsl:with-param name="sAttribute">
  1839.                     <xsl:call-template name="SReplace">
  1840.                       <xsl:with-param name="sInput" select="$sAttribute" />
  1841.                       <xsl:with-param name="sOrig" select="'top'" />
  1842.                       <xsl:with-param name="sReplacement" select="''" />
  1843.                     </xsl:call-template>
  1844.                   </xsl:with-param>
  1845.                 </xsl:call-template>
  1846.               </xsl:when>
  1847.               <xsl:otherwise>
  1848.                 <xsl:call-template name="CreateMencloseNotationAttrFromBorderBoxAttr">
  1849.                   <xsl:with-param name="fHideBot" select="$fHideBot" />
  1850.                   <xsl:with-param name="fHideLeft" select="$fHideLeft" />
  1851.                   <xsl:with-param name="fHideRight" select="$fHideRight" />
  1852.                   <xsl:with-param name="fStrikeH" select="$fStrikeH" />
  1853.                   <xsl:with-param name="fStrikeV" select="$fStrikeV" />
  1854.                   <xsl:with-param name="fStrikeBLTR" select="$fStrikeBLTR" />
  1855.                   <xsl:with-param name="fStrikeTLBR" select="$fStrikeTLBR" />
  1856.                   <xsl:with-param name="sAttribute" select="$sAttribute" />
  1857.                 </xsl:call-template>
  1858.               </xsl:otherwise>
  1859.             </xsl:choose>
  1860.           </xsl:when>
  1861.           <xsl:when test="string-length($fHideBot) > 0">
  1862.             <xsl:choose>
  1863.               <xsl:when test="$fHideBot=1">
  1864.                 <xsl:call-template name="CreateMencloseNotationAttrFromBorderBoxAttr">
  1865.                   <xsl:with-param name="fHideLeft" select="$fHideLeft" />
  1866.                   <xsl:with-param name="fHideRight" select="$fHideRight" />
  1867.                   <xsl:with-param name="fStrikeH" select="$fStrikeH" />
  1868.                   <xsl:with-param name="fStrikeV" select="$fStrikeV" />
  1869.                   <xsl:with-param name="fStrikeBLTR" select="$fStrikeBLTR" />
  1870.                   <xsl:with-param name="fStrikeTLBR" select="$fStrikeTLBR" />
  1871.                   <xsl:with-param name="sAttribute">
  1872.                     <xsl:call-template name="SReplace">
  1873.                       <xsl:with-param name="sInput" select="$sAttribute" />
  1874.                       <xsl:with-param name="sOrig" select="'bottom'" />
  1875.                       <xsl:with-param name="sReplacement" select="''" />
  1876.                     </xsl:call-template>
  1877.                   </xsl:with-param>
  1878.                 </xsl:call-template>
  1879.               </xsl:when>
  1880.               <xsl:otherwise>
  1881.                 <xsl:call-template name="CreateMencloseNotationAttrFromBorderBoxAttr">
  1882.                   <xsl:with-param name="fHideLeft" select="$fHideLeft" />
  1883.                   <xsl:with-param name="fHideRight" select="$fHideRight" />
  1884.                   <xsl:with-param name="fStrikeH" select="$fStrikeH" />
  1885.                   <xsl:with-param name="fStrikeV" select="$fStrikeV" />
  1886.                   <xsl:with-param name="fStrikeBLTR" select="$fStrikeBLTR" />
  1887.                   <xsl:with-param name="fStrikeTLBR" select="$fStrikeTLBR" />
  1888.                   <xsl:with-param name="sAttribute" select="$sAttribute" />
  1889.                 </xsl:call-template>
  1890.               </xsl:otherwise>
  1891.             </xsl:choose>
  1892.           </xsl:when>
  1893.           <xsl:when test="string-length($fHideLeft) > 0">
  1894.             <xsl:choose>
  1895.               <xsl:when test="$fHideLeft=1">
  1896.                 <xsl:call-template name="CreateMencloseNotationAttrFromBorderBoxAttr">
  1897.                   <xsl:with-param name="fHideRight" select="$fHideRight" />
  1898.                   <xsl:with-param name="fStrikeH" select="$fStrikeH" />
  1899.                   <xsl:with-param name="fStrikeV" select="$fStrikeV" />
  1900.                   <xsl:with-param name="fStrikeBLTR" select="$fStrikeBLTR" />
  1901.                   <xsl:with-param name="fStrikeTLBR" select="$fStrikeTLBR" />
  1902.                   <xsl:with-param name="sAttribute">
  1903.                     <xsl:call-template name="SReplace">
  1904.                       <xsl:with-param name="sInput" select="$sAttribute" />
  1905.                       <xsl:with-param name="sOrig" select="'left'" />
  1906.                       <xsl:with-param name="sReplacement" select="''" />
  1907.                     </xsl:call-template>
  1908.                   </xsl:with-param>
  1909.                 </xsl:call-template>
  1910.               </xsl:when>
  1911.               <xsl:otherwise>
  1912.                 <xsl:call-template name="CreateMencloseNotationAttrFromBorderBoxAttr">
  1913.                   <xsl:with-param name="fHideRight" select="$fHideRight" />
  1914.                   <xsl:with-param name="fStrikeH" select="$fStrikeH" />
  1915.                   <xsl:with-param name="fStrikeV" select="$fStrikeV" />
  1916.                   <xsl:with-param name="fStrikeBLTR" select="$fStrikeBLTR" />
  1917.                   <xsl:with-param name="fStrikeTLBR" select="$fStrikeTLBR" />
  1918.                   <xsl:with-param name="sAttribute" select="$sAttribute" />
  1919.                 </xsl:call-template>
  1920.               </xsl:otherwise>
  1921.             </xsl:choose>
  1922.           </xsl:when>
  1923.           <xsl:when test="string-length($fHideRight) > 0">
  1924.             <xsl:choose>
  1925.               <xsl:when test="$fHideRight=1">
  1926.                 <xsl:call-template name="CreateMencloseNotationAttrFromBorderBoxAttr">
  1927.                   <xsl:with-param name="fStrikeH" select="$fStrikeH" />
  1928.                   <xsl:with-param name="fStrikeV" select="$fStrikeV" />
  1929.                   <xsl:with-param name="fStrikeBLTR" select="$fStrikeBLTR" />
  1930.                   <xsl:with-param name="fStrikeTLBR" select="$fStrikeTLBR" />
  1931.                   <xsl:with-param name="sAttribute">
  1932.                     <xsl:call-template name="SReplace">
  1933.                       <xsl:with-param name="sInput" select="$sAttribute" />
  1934.                       <xsl:with-param name="sOrig" select="'right'" />
  1935.                       <xsl:with-param name="sReplacement" select="''" />
  1936.                     </xsl:call-template>
  1937.                   </xsl:with-param>
  1938.                 </xsl:call-template>
  1939.               </xsl:when>
  1940.               <xsl:otherwise>
  1941.                 <xsl:call-template name="CreateMencloseNotationAttrFromBorderBoxAttr">
  1942.                   <xsl:with-param name="fStrikeH" select="$fStrikeH" />
  1943.                   <xsl:with-param name="fStrikeV" select="$fStrikeV" />
  1944.                   <xsl:with-param name="fStrikeBLTR" select="$fStrikeBLTR" />
  1945.                   <xsl:with-param name="fStrikeTLBR" select="$fStrikeTLBR" />
  1946.                   <xsl:with-param name="sAttribute" select="$sAttribute" />
  1947.                 </xsl:call-template>
  1948.               </xsl:otherwise>
  1949.             </xsl:choose>
  1950.           </xsl:when>
  1951.           <xsl:when test="string-length($fStrikeH) > 0">
  1952.             <xsl:choose>
  1953.               <xsl:when test="$fStrikeH=1">
  1954.                 <xsl:call-template name="CreateMencloseNotationAttrFromBorderBoxAttr">
  1955.                   <xsl:with-param name="fStrikeV" select="$fStrikeV" />
  1956.                   <xsl:with-param name="fStrikeBLTR" select="$fStrikeBLTR" />
  1957.                   <xsl:with-param name="fStrikeTLBR" select="$fStrikeTLBR" />
  1958.                   <xsl:with-param name="sAttribute" select="concat($sAttribute, ' horizontalstrike')" />
  1959.                 </xsl:call-template>
  1960.               </xsl:when>
  1961.               <xsl:otherwise>
  1962.                 <xsl:call-template name="CreateMencloseNotationAttrFromBorderBoxAttr">
  1963.                   <xsl:with-param name="fStrikeV" select="$fStrikeV" />
  1964.                   <xsl:with-param name="fStrikeBLTR" select="$fStrikeBLTR" />
  1965.                   <xsl:with-param name="fStrikeTLBR" select="$fStrikeTLBR" />
  1966.                   <xsl:with-param name="sAttribute" select="$sAttribute" />
  1967.                 </xsl:call-template>
  1968.               </xsl:otherwise>
  1969.             </xsl:choose>
  1970.           </xsl:when>
  1971.           <xsl:when test="string-length($fStrikeV) > 0">
  1972.             <xsl:choose>
  1973.               <xsl:when test="$fStrikeV=1">
  1974.                 <xsl:call-template name="CreateMencloseNotationAttrFromBorderBoxAttr">
  1975.                   <xsl:with-param name="fStrikeBLTR" select="$fStrikeBLTR" />
  1976.                   <xsl:with-param name="fStrikeTLBR" select="$fStrikeTLBR" />
  1977.                   <xsl:with-param name="sAttribute" select="concat($sAttribute, ' verticalstrike')" />
  1978.                 </xsl:call-template>
  1979.               </xsl:when>
  1980.               <xsl:otherwise>
  1981.                 <xsl:call-template name="CreateMencloseNotationAttrFromBorderBoxAttr">
  1982.                   <xsl:with-param name="fStrikeBLTR" select="$fStrikeBLTR" />
  1983.                   <xsl:with-param name="fStrikeTLBR" select="$fStrikeTLBR" />
  1984.                   <xsl:with-param name="sAttribute" select="$sAttribute" />
  1985.                 </xsl:call-template>
  1986.               </xsl:otherwise>
  1987.             </xsl:choose>
  1988.           </xsl:when>
  1989.           <xsl:when test="string-length($fStrikeBLTR) > 0">
  1990.             <xsl:choose>
  1991.               <xsl:when test="$fStrikeBLTR=1">
  1992.                 <xsl:call-template name="CreateMencloseNotationAttrFromBorderBoxAttr">
  1993.                   <xsl:with-param name="fStrikeTLBR" select="$fStrikeTLBR" />
  1994.                   <xsl:with-param name="sAttribute" select="concat($sAttribute, ' updiagonalstrike')" />
  1995.                 </xsl:call-template>
  1996.               </xsl:when>
  1997.               <xsl:otherwise>
  1998.                 <xsl:call-template name="CreateMencloseNotationAttrFromBorderBoxAttr">
  1999.                   <xsl:with-param name="fStrikeTLBR" select="$fStrikeTLBR" />
  2000.                   <xsl:with-param name="sAttribute" select="$sAttribute" />
  2001.                 </xsl:call-template>
  2002.               </xsl:otherwise>
  2003.             </xsl:choose>
  2004.           </xsl:when>
  2005.           <xsl:when test="string-length($fStrikeTLBR) > 0">
  2006.             <xsl:choose>
  2007.               <xsl:when test="$fStrikeTLBR=1">
  2008.                 <xsl:call-template name="CreateMencloseNotationAttrFromBorderBoxAttr">
  2009.                   <xsl:with-param name="sAttribute" select="concat($sAttribute, ' downdiagonalstrike')" />
  2010.                 </xsl:call-template>
  2011.               </xsl:when>
  2012.               <xsl:otherwise>
  2013.                 <xsl:call-template name="CreateMencloseNotationAttrFromBorderBoxAttr">
  2014.                   <xsl:with-param name="sAttribute" select="$sAttribute" />
  2015.                 </xsl:call-template>
  2016.               </xsl:otherwise>
  2017.             </xsl:choose>
  2018.           </xsl:when>
  2019.           <xsl:otherwise>
  2020.             <xsl:attribute name="notation">
  2021.               <xsl:value-of select="normalize-space($sAttribute)" />
  2022.             </xsl:attribute>
  2023.           </xsl:otherwise>
  2024.         </xsl:choose>
  2025.       </xsl:otherwise>
  2026.     </xsl:choose>
  2027.   </xsl:template>
  2028.  
  2029.   <!-- Tristate (true, false, neither) from string value -->
  2030.   <xsl:template name="TFromStrVal">
  2031.     <xsl:param name="str" />
  2032.     <xsl:choose>
  2033.       <xsl:when test="$str = 'on' or $str = '1' or $str = 'true'">1</xsl:when>
  2034.       <xsl:when test="$str = 'off' or $str = '0' or $str = 'false'">0</xsl:when>
  2035.       <xsl:otherwise>-1</xsl:otherwise>
  2036.     </xsl:choose>
  2037.   </xsl:template>
  2038.  
  2039.   <!-- Return 0 iff $str is explicitly set to a false value.  
  2040.        Return true otherwise -->
  2041.   <xsl:template name="ForceFalseStrVal">
  2042.     <xsl:param name="str" />
  2043.     <xsl:variable name="tValue">
  2044.       <xsl:call-template name="TFromStrVal">
  2045.         <xsl:with-param name="str" select="$str"/>
  2046.       </xsl:call-template>
  2047.     </xsl:variable>
  2048.     <xsl:choose>
  2049.       <xsl:when test="$tValue = '0'">0</xsl:when>
  2050.       <xsl:otherwise>1</xsl:otherwise>
  2051.     </xsl:choose>
  2052.   </xsl:template>
  2053.  
  2054.   <!-- Return 1 iff $str is explicitly set to a true value.  
  2055.        Return false otherwise -->
  2056.   <xsl:template name="ForceTrueStrVal">
  2057.     <xsl:param name="str" />
  2058.     <xsl:variable name="tValue">
  2059.       <xsl:call-template name="TFromStrVal">
  2060.         <xsl:with-param name="str" select="$str"/>
  2061.       </xsl:call-template>
  2062.     </xsl:variable>
  2063.     <xsl:choose>
  2064.       <xsl:when test="$tValue = '1'">1</xsl:when>
  2065.       <xsl:otherwise>0</xsl:otherwise>
  2066.     </xsl:choose>
  2067.   </xsl:template>
  2068. </xsl:stylesheet>
  2069.