diff n2a.xsl @ 45:6ed900e8cc61

towards comparable formulae
author Henry S. Thompson <ht@markup.co.uk>
date Sun, 07 May 2017 19:21:53 +0100
parents 5469a32795da
children d3569a8cbf7a
line wrap: on
line diff
--- a/n2a.xsl	Sun May 07 11:56:02 2017 +0100
+++ b/n2a.xsl	Sun May 07 19:21:53 2017 +0100
@@ -16,4 +16,48 @@
   <xsl:param name="n" as="xs:integer"/>
   <xsl:value-of select="codepoints-to-string(e:n2aa($n))"/>
  </xsl:function>
+ 
+ <xsl:function name="e:crnf" as="xs:string">
+  <!-- compute CR-normal-form of a singleton reference -->
+  <xsl:param name="s" as="element(e:s)"/>
+  <xsl:value-of select="concat(e:snf(($s/*)[1]),e:snf(($s/*)[2]))"/>
+ </xsl:function>
+ 
+ <xsl:function name="e:snf" as="xs:string">
+  <xsl:param name="s" as="element(*)"/><!-- either a(bsolute) or r(elative)-->
+  <xsl:value-of select="if (local-name($s)='a')
+                         then concat('&#xAA;',$s)
+                         else concat('&#xBA;',$s/@d)"/>
+ </xsl:function>
+ 
+ <xsl:function name="e:rnf" as="xs:string">
+  <!-- CRNF for a range or singleton reference -->
+  <xsl:param name="b" as="element(*)"/>
+  <xsl:value-of select="if (local-name($b)='s') then e:crnf($b)
+                           else if (local-name($b)='r')
+                                 then
+                                  let $l := ($b/e:s)[1],
+                                      $r := ($b/e:s)[2] return
+                                     concat(e:crnf($l),
+                                            ':',
+                                            e:crnf($r))
+                                 else if (local-name($b)='v')
+                                  then $b/text()
+                                 else e:shouldnt()"/>
+ </xsl:function>
+ 
+ <xsl:function name="e:fnf" as="xs:string">
+  <!-- rebuild a formula from its parts, but using CRNF for all references -->
+  <xsl:param name="bits" as="element(*)*"/>
+  <xsl:value-of select="string-join(
+                          for $b in $bits return
+                           if (local-name($b)=('s','r')) then e:rnf($b)
+                           else if (local-name($b)='e')
+                                 then concat($b/@x,'!',e:rnf($b/*))
+                          else $b/text())"/>
+ </xsl:function>
+ 
+ <xsl:function name="e:shouldnt">
+  <xsl:message terminate="yes">shouldn't happen</xsl:message>
+ </xsl:function>
 </xsl:stylesheet>