comparison 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
comparison
equal deleted inserted replaced
44:5b2333e59d91 45:6ed900e8cc61
14 <xsl:function name="e:n2a" as="xs:string"> 14 <xsl:function name="e:n2a" as="xs:string">
15 <!-- Invert the a2n computation --> 15 <!-- Invert the a2n computation -->
16 <xsl:param name="n" as="xs:integer"/> 16 <xsl:param name="n" as="xs:integer"/>
17 <xsl:value-of select="codepoints-to-string(e:n2aa($n))"/> 17 <xsl:value-of select="codepoints-to-string(e:n2aa($n))"/>
18 </xsl:function> 18 </xsl:function>
19
20 <xsl:function name="e:crnf" as="xs:string">
21 <!-- compute CR-normal-form of a singleton reference -->
22 <xsl:param name="s" as="element(e:s)"/>
23 <xsl:value-of select="concat(e:snf(($s/*)[1]),e:snf(($s/*)[2]))"/>
24 </xsl:function>
25
26 <xsl:function name="e:snf" as="xs:string">
27 <xsl:param name="s" as="element(*)"/><!-- either a(bsolute) or r(elative)-->
28 <xsl:value-of select="if (local-name($s)='a')
29 then concat('&#xAA;',$s)
30 else concat('&#xBA;',$s/@d)"/>
31 </xsl:function>
32
33 <xsl:function name="e:rnf" as="xs:string">
34 <!-- CRNF for a range or singleton reference -->
35 <xsl:param name="b" as="element(*)"/>
36 <xsl:value-of select="if (local-name($b)='s') then e:crnf($b)
37 else if (local-name($b)='r')
38 then
39 let $l := ($b/e:s)[1],
40 $r := ($b/e:s)[2] return
41 concat(e:crnf($l),
42 ':',
43 e:crnf($r))
44 else if (local-name($b)='v')
45 then $b/text()
46 else e:shouldnt()"/>
47 </xsl:function>
48
49 <xsl:function name="e:fnf" as="xs:string">
50 <!-- rebuild a formula from its parts, but using CRNF for all references -->
51 <xsl:param name="bits" as="element(*)*"/>
52 <xsl:value-of select="string-join(
53 for $b in $bits return
54 if (local-name($b)=('s','r')) then e:rnf($b)
55 else if (local-name($b)='e')
56 then concat($b/@x,'!',e:rnf($b/*))
57 else $b/text())"/>
58 </xsl:function>
59
60 <xsl:function name="e:shouldnt">
61 <xsl:message terminate="yes">shouldn't happen</xsl:message>
62 </xsl:function>
19 </xsl:stylesheet> 63 </xsl:stylesheet>