comparison rect.xsl @ 34:93fd0d532754

fix bug in refs wrt e.g. [1]!.SGX, adapt html and ascii to new-format refs, move a2n and n2a into separate files for re-use
author Henry S. Thompson <ht@markup.co.uk>
date Wed, 12 Apr 2017 21:35:04 +0100
parents 8309dcfce613
children 468a6cf8bf0b
comparison
equal deleted inserted replaced
33:27bffc66ce10 34:93fd0d532754
1 <?xml version='1.0'?> 1 <?xml version='1.0'?>
2 <!DOCTYPE doc SYSTEM "../../../lib/xml/xsl.dtd" > 2 <!DOCTYPE doc SYSTEM "../../../lib/xml/xsl.dtd" >
3 <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="3.0" xmlns:s="http://schemas.openxmlformats.org/spreadsheetml/2006/main" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:e="http://markup.co.uk/excel" exclude-result-prefixes="xs s xpf" xmlns="http://markup.co.uk/excel" xmlns:xpf="http://www.w3.org/2005/xpath-functions"> 3 <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="3.0" xmlns:s="http://schemas.openxmlformats.org/spreadsheetml/2006/main" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:e="http://markup.co.uk/excel" exclude-result-prefixes="xs s xpf" xmlns="http://markup.co.uk/excel" xmlns:xpf="http://www.w3.org/2005/xpath-functions">
4 <xsl:strip-space elements="s:sheetData"/> 4 <xsl:strip-space elements="s:sheetData"/>
5 5
6 <xsl:include href="a2n.xsl"/>
7 <xsl:include href="n2a.xsl"/>
8
6 <xsl:variable name="refs" select="collection()[2]/*"/> 9 <xsl:variable name="refs" select="collection()[2]/*"/>
7 10
8 <xsl:key name="ref" match="e:i" use="@r"/> 11 <xsl:key name="ref" match="e:i" use="@r"/>
9
10 <xsl:function name="e:a2n" as="xs:integer">
11 <!-- Convert an alphabetic excel column 'index' into a number,
12 a sort of base 26 + 1, since 'A' is 1 and 'AA' is 27 -->
13 <xsl:param name="aa" as="xs:string"/>
14 <xsl:value-of select="let $l := string-length($aa),
15 $lv := string-to-codepoints(substring($aa,$l))-$codeBase
16 return if ($l=1) then $lv
17 else $lv+(26*e:a2n(substring($aa,1,$l - 1)))"/>
18 </xsl:function>
19
20 <xsl:function name="e:n2aa" as="xs:integer*">
21 <!-- Does the real work for e:n2a -->
22 <xsl:param name="n" as="xs:integer"/>
23 <xsl:sequence select="let $least := $codeBase+(($n - 1) mod 26)+1
24 return if ($n &lt; 27) then $least
25 else (e:n2aa($n idiv 26),$least)"/>
26 </xsl:function>
27
28 <xsl:function name="e:n2a" as="xs:string">
29 <!-- Invert the a2n computation -->
30 <xsl:param name="n" as="xs:integer"/>
31 <xsl:value-of select="codepoints-to-string(e:n2aa($n))"/>
32 </xsl:function>
33 12
34 <xsl:variable name="dim" select="//s:dimension/@ref"/> 13 <xsl:variable name="dim" select="//s:dimension/@ref"/>
35 <xsl:variable name="codeBase" select="string-to-codepoints('A')-1"/>
36 14
37 <xsl:template match="/"> 15 <xsl:template match="/">
38 <xsl:apply-templates select="//s:sheetData"/> 16 <xsl:apply-templates select="//s:sheetData"/>
39 </xsl:template> 17 </xsl:template>
40 18