Mercurial > hg > ooxml
annotate ascii.xsl @ 8:785187b9caef
working toward doing an ascii-rectangle repr of a sheet
author | Henry S. Thompson <ht@markup.co.uk> |
---|---|
date | Sun, 02 Apr 2017 21:13:16 +0800 |
parents | |
children | 01e80c7a9575 |
rev | line source |
---|---|
8
785187b9caef
working toward doing an ascii-rectangle repr of a sheet
Henry S. Thompson <ht@markup.co.uk>
parents:
diff
changeset
|
1 <?xml version='1.0'?> |
785187b9caef
working toward doing an ascii-rectangle repr of a sheet
Henry S. Thompson <ht@markup.co.uk>
parents:
diff
changeset
|
2 <!DOCTYPE doc SYSTEM "../../../lib/xml/xsl.dtd" > |
785187b9caef
working toward doing an ascii-rectangle repr of a sheet
Henry S. Thompson <ht@markup.co.uk>
parents:
diff
changeset
|
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://schemas.openxmlformats.org/spreadsheetml/2006/main" xmlns:xpf="http://www.w3.org/2005/xpath-functions"> |
785187b9caef
working toward doing an ascii-rectangle repr of a sheet
Henry S. Thompson <ht@markup.co.uk>
parents:
diff
changeset
|
4 <xsl:variable name="dim" select="//s:dimension/@ref"/> |
785187b9caef
working toward doing an ascii-rectangle repr of a sheet
Henry S. Thompson <ht@markup.co.uk>
parents:
diff
changeset
|
5 <xsl:variable name="codeBase" select="string-to-codepoints('A')-1"/> |
785187b9caef
working toward doing an ascii-rectangle repr of a sheet
Henry S. Thompson <ht@markup.co.uk>
parents:
diff
changeset
|
6 |
785187b9caef
working toward doing an ascii-rectangle repr of a sheet
Henry S. Thompson <ht@markup.co.uk>
parents:
diff
changeset
|
7 <xsl:function name="e:a2n" as="xs:integer"> |
785187b9caef
working toward doing an ascii-rectangle repr of a sheet
Henry S. Thompson <ht@markup.co.uk>
parents:
diff
changeset
|
8 <!-- Convert an alphabetic excel column 'index' into a number, |
785187b9caef
working toward doing an ascii-rectangle repr of a sheet
Henry S. Thompson <ht@markup.co.uk>
parents:
diff
changeset
|
9 a sort of base 26 + 1, since 'A' is 1 and 'AA' is 27 --> |
785187b9caef
working toward doing an ascii-rectangle repr of a sheet
Henry S. Thompson <ht@markup.co.uk>
parents:
diff
changeset
|
10 <xsl:param name="aa" as="xs:string"/> |
785187b9caef
working toward doing an ascii-rectangle repr of a sheet
Henry S. Thompson <ht@markup.co.uk>
parents:
diff
changeset
|
11 <xsl:value-of select="let $l := string-length($aa), |
785187b9caef
working toward doing an ascii-rectangle repr of a sheet
Henry S. Thompson <ht@markup.co.uk>
parents:
diff
changeset
|
12 $lv := string-to-codepoints(substring($aa,$l))-$codeBase |
785187b9caef
working toward doing an ascii-rectangle repr of a sheet
Henry S. Thompson <ht@markup.co.uk>
parents:
diff
changeset
|
13 return if ($l=1) then $lv |
785187b9caef
working toward doing an ascii-rectangle repr of a sheet
Henry S. Thompson <ht@markup.co.uk>
parents:
diff
changeset
|
14 else $lv+(26*e:a2n(substring($aa,1,$l - 1)))"/> |
785187b9caef
working toward doing an ascii-rectangle repr of a sheet
Henry S. Thompson <ht@markup.co.uk>
parents:
diff
changeset
|
15 </xsl:function> |
785187b9caef
working toward doing an ascii-rectangle repr of a sheet
Henry S. Thompson <ht@markup.co.uk>
parents:
diff
changeset
|
16 |
785187b9caef
working toward doing an ascii-rectangle repr of a sheet
Henry S. Thompson <ht@markup.co.uk>
parents:
diff
changeset
|
17 <xsl:function name="e:n2aa" as="xs:integer*"> |
785187b9caef
working toward doing an ascii-rectangle repr of a sheet
Henry S. Thompson <ht@markup.co.uk>
parents:
diff
changeset
|
18 <!-- Does the real work for e:n2a --> |
785187b9caef
working toward doing an ascii-rectangle repr of a sheet
Henry S. Thompson <ht@markup.co.uk>
parents:
diff
changeset
|
19 <xsl:param name="n" as="xs:integer"/> |
785187b9caef
working toward doing an ascii-rectangle repr of a sheet
Henry S. Thompson <ht@markup.co.uk>
parents:
diff
changeset
|
20 <xsl:sequence select="let $least := $codeBase+(($n - 1) mod 26)+1 |
785187b9caef
working toward doing an ascii-rectangle repr of a sheet
Henry S. Thompson <ht@markup.co.uk>
parents:
diff
changeset
|
21 return if ($n < 27) then $least |
785187b9caef
working toward doing an ascii-rectangle repr of a sheet
Henry S. Thompson <ht@markup.co.uk>
parents:
diff
changeset
|
22 else (e:n2aa($n idiv 26),$least)"/> |
785187b9caef
working toward doing an ascii-rectangle repr of a sheet
Henry S. Thompson <ht@markup.co.uk>
parents:
diff
changeset
|
23 </xsl:function> |
785187b9caef
working toward doing an ascii-rectangle repr of a sheet
Henry S. Thompson <ht@markup.co.uk>
parents:
diff
changeset
|
24 |
785187b9caef
working toward doing an ascii-rectangle repr of a sheet
Henry S. Thompson <ht@markup.co.uk>
parents:
diff
changeset
|
25 <xsl:function name="e:n2a" as="xs:string"> |
785187b9caef
working toward doing an ascii-rectangle repr of a sheet
Henry S. Thompson <ht@markup.co.uk>
parents:
diff
changeset
|
26 <!-- Invert the a2n computation --> |
785187b9caef
working toward doing an ascii-rectangle repr of a sheet
Henry S. Thompson <ht@markup.co.uk>
parents:
diff
changeset
|
27 <xsl:param name="n" as="xs:integer"/> |
785187b9caef
working toward doing an ascii-rectangle repr of a sheet
Henry S. Thompson <ht@markup.co.uk>
parents:
diff
changeset
|
28 <xsl:value-of select="codepoints-to-string(e:n2aa($n))"/> |
785187b9caef
working toward doing an ascii-rectangle repr of a sheet
Henry S. Thompson <ht@markup.co.uk>
parents:
diff
changeset
|
29 </xsl:function> |
785187b9caef
working toward doing an ascii-rectangle repr of a sheet
Henry S. Thompson <ht@markup.co.uk>
parents:
diff
changeset
|
30 |
785187b9caef
working toward doing an ascii-rectangle repr of a sheet
Henry S. Thompson <ht@markup.co.uk>
parents:
diff
changeset
|
31 <xsl:template match="s:sheetData"> |
785187b9caef
working toward doing an ascii-rectangle repr of a sheet
Henry S. Thompson <ht@markup.co.uk>
parents:
diff
changeset
|
32 <xsl:if test="s:row"> |
785187b9caef
working toward doing an ascii-rectangle repr of a sheet
Henry S. Thompson <ht@markup.co.uk>
parents:
diff
changeset
|
33 <xsl:variable name="dims" select="analyze-string($dim,'([A-Z]+)([0-9]+):([A-Z]+)([0-9]+)')"/> |
785187b9caef
working toward doing an ascii-rectangle repr of a sheet
Henry S. Thompson <ht@markup.co.uk>
parents:
diff
changeset
|
34 <xsl:variable name="width" select="1+number($dims//xpf:group[@nr='4'])-number($dims//xpf:group[@nr='2'])"/> |
785187b9caef
working toward doing an ascii-rectangle repr of a sheet
Henry S. Thompson <ht@markup.co.uk>
parents:
diff
changeset
|
35 <xsl:message><xsl:value-of select="$width"/>|<xsl:value-of select="1+e:a2n($dims//xpf:group[@nr='3'])-e:a2n($dims//xpf:group[@nr='1'])"/>|<xsl:value-of select="e:a2n('AA')"/></xsl:message> |
785187b9caef
working toward doing an ascii-rectangle repr of a sheet
Henry S. Thompson <ht@markup.co.uk>
parents:
diff
changeset
|
36 <xsl:message><xsl:value-of select="e:n2a(1)"/>|<xsl:value-of select="e:n2a(26)"/>|<xsl:value-of select="e:n2a(27)"/>|<xsl:value-of select="e:n2a(52)"/>|<xsl:value-of select="e:n2a(54)"/></xsl:message> |
785187b9caef
working toward doing an ascii-rectangle repr of a sheet
Henry S. Thompson <ht@markup.co.uk>
parents:
diff
changeset
|
37 </xsl:if> |
785187b9caef
working toward doing an ascii-rectangle repr of a sheet
Henry S. Thompson <ht@markup.co.uk>
parents:
diff
changeset
|
38 </xsl:template> |
785187b9caef
working toward doing an ascii-rectangle repr of a sheet
Henry S. Thompson <ht@markup.co.uk>
parents:
diff
changeset
|
39 </xsl:stylesheet> |