Mercurial > hg > ooxml
comparison rect.xsl @ 12:01e125d722be
widening scope so better names
author | Henry S. Thompson <ht@markup.co.uk> |
---|---|
date | Mon, 03 Apr 2017 13:46:54 +0100 |
parents | ascii.xsl@480454d218f7 |
children | f78e8c55c06b |
comparison
equal
deleted
inserted
replaced
11:480454d218f7 | 12:01e125d722be |
---|---|
1 <?xml version='1.0'?> | |
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://schemas.openxmlformats.org/spreadsheetml/2006/main" xmlns:xpf="http://www.w3.org/2005/xpath-functions"> | |
4 | |
5 <xsl:function name="e:a2n" as="xs:integer"> | |
6 <!-- Convert an alphabetic excel column 'index' into a number, | |
7 a sort of base 26 + 1, since 'A' is 1 and 'AA' is 27 --> | |
8 <xsl:param name="aa" as="xs:string"/> | |
9 <xsl:value-of select="let $l := string-length($aa), | |
10 $lv := string-to-codepoints(substring($aa,$l))-$codeBase | |
11 return if ($l=1) then $lv | |
12 else $lv+(26*e:a2n(substring($aa,1,$l - 1)))"/> | |
13 </xsl:function> | |
14 | |
15 <xsl:function name="e:n2aa" as="xs:integer*"> | |
16 <!-- Does the real work for e:n2a --> | |
17 <xsl:param name="n" as="xs:integer"/> | |
18 <xsl:sequence select="let $least := $codeBase+(($n - 1) mod 26)+1 | |
19 return if ($n < 27) then $least | |
20 else (e:n2aa($n idiv 26),$least)"/> | |
21 </xsl:function> | |
22 | |
23 <xsl:function name="e:n2a" as="xs:string"> | |
24 <!-- Invert the a2n computation --> | |
25 <xsl:param name="n" as="xs:integer"/> | |
26 <xsl:value-of select="codepoints-to-string(e:n2aa($n))"/> | |
27 </xsl:function> | |
28 | |
29 <xsl:variable name="dim" select="//s:dimension/@ref"/> | |
30 <xsl:variable name="codeBase" select="string-to-codepoints('A')-1"/> | |
31 | |
32 <xsl:template match="s:sheetData"> | |
33 <xsl:if test="s:row"> | |
34 <xsl:variable name="dims" select="analyze-string($dim,'([A-Z]+)([0-9]+):([A-Z]+)([0-9]+)')"/> | |
35 <xsl:variable name="height" select="1+xs:integer($dims//xpf:group[@nr='4'])-xs:integer($dims//xpf:group[@nr='2'])"/> | |
36 <xsl:variable name="width" select="1+e:a2n($dims//xpf:group[@nr='3'])-e:a2n($dims//xpf:group[@nr='1'])"/> | |
37 <!-- Brute force! --> | |
38 <xsl:variable name="sheet" select="."/> | |
39 <e:a> | |
40 <xsl:text> </xsl:text> | |
41 <xsl:for-each select="(1 to $height)"><xsl:variable name="row" select="."/> | |
42 <e:r r="{$row}"> | |
43 <xsl:for-each select="(1 to $width)"> | |
44 <xsl:variable name="col" select="."/> | |
45 <xsl:variable name="r" select="concat(e:n2a($col),string($row))"/> | |
46 <xsl:variable name="c" select="$sheet/s:row/s:c[@r=$r]"/> | |
47 <e:c c="{$col}"> | |
48 <xsl:if test="$c/s:f"><xsl:attribute name="f">1</xsl:attribute></xsl:if> | |
49 <xsl:if test="$c"><xsl:value-of select="substring($c/@e:type,1,1)"/></xsl:if> | |
50 </e:c> | |
51 </xsl:for-each> | |
52 </e:r> | |
53 <xsl:text> </xsl:text></xsl:for-each> | |
54 </e:a> | |
55 </xsl:if> | |
56 </xsl:template> | |
57 </xsl:stylesheet> |