Mercurial > hg > ooxml
comparison ascii.xsl @ 10:01e80c7a9575
simple ascii type matrix output working
author | Henry S. Thompson <ht@markup.co.uk> |
---|---|
date | Mon, 03 Apr 2017 12:31:58 +0100 |
parents | 785187b9caef |
children | 480454d218f7 |
comparison
equal
deleted
inserted
replaced
9:5f2d691014ff | 10:01e80c7a9575 |
---|---|
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://schemas.openxmlformats.org/spreadsheetml/2006/main" 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://schemas.openxmlformats.org/spreadsheetml/2006/main" xmlns:xpf="http://www.w3.org/2005/xpath-functions"> |
4 <xsl:variable name="dim" select="//s:dimension/@ref"/> | |
5 <xsl:variable name="codeBase" select="string-to-codepoints('A')-1"/> | |
6 | 4 |
7 <xsl:function name="e:a2n" as="xs:integer"> | 5 <xsl:function name="e:a2n" as="xs:integer"> |
8 <!-- Convert an alphabetic excel column 'index' into a number, | 6 <!-- Convert an alphabetic excel column 'index' into a number, |
9 a sort of base 26 + 1, since 'A' is 1 and 'AA' is 27 --> | 7 a sort of base 26 + 1, since 'A' is 1 and 'AA' is 27 --> |
10 <xsl:param name="aa" as="xs:string"/> | 8 <xsl:param name="aa" as="xs:string"/> |
25 <xsl:function name="e:n2a" as="xs:string"> | 23 <xsl:function name="e:n2a" as="xs:string"> |
26 <!-- Invert the a2n computation --> | 24 <!-- Invert the a2n computation --> |
27 <xsl:param name="n" as="xs:integer"/> | 25 <xsl:param name="n" as="xs:integer"/> |
28 <xsl:value-of select="codepoints-to-string(e:n2aa($n))"/> | 26 <xsl:value-of select="codepoints-to-string(e:n2aa($n))"/> |
29 </xsl:function> | 27 </xsl:function> |
30 | 28 |
29 <xsl:variable name="dim" select="//s:dimension/@ref"/> | |
30 <xsl:variable name="codeBase" select="string-to-codepoints('A')-1"/> | |
31 | |
31 <xsl:template match="s:sheetData"> | 32 <xsl:template match="s:sheetData"> |
32 <xsl:if test="s:row"> | 33 <xsl:if test="s:row"> |
33 <xsl:variable name="dims" select="analyze-string($dim,'([A-Z]+)([0-9]+):([A-Z]+)([0-9]+)')"/> | 34 <xsl:variable name="dims" select="analyze-string($dim,'([A-Z]+)([0-9]+):([A-Z]+)([0-9]+)')"/> |
34 <xsl:variable name="width" select="1+number($dims//xpf:group[@nr='4'])-number($dims//xpf:group[@nr='2'])"/> | 35 <xsl:variable name="height" select="1+xs:integer($dims//xpf:group[@nr='4'])-xs:integer($dims//xpf:group[@nr='2'])"/> |
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> | 36 <xsl:variable name="width" select="1+e:a2n($dims//xpf:group[@nr='3'])-e:a2n($dims//xpf:group[@nr='1'])"/> |
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> | 37 <!-- Brute force! --> |
38 <xsl:variable name="sheet" select="."/> | |
39 <a> | |
40 <xsl:text> </xsl:text> | |
41 <xsl:for-each select="(1 to $height)"> | |
42 <xsl:variable name="row" select="."/> | |
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]"></xsl:variable> | |
47 <xsl:value-of select="if (count($c)=1) then substring($c/@e:type,1,1) else ' '"/> | |
48 </xsl:for-each> | |
49 <xsl:text> </xsl:text> | |
50 </xsl:for-each></a> | |
37 </xsl:if> | 51 </xsl:if> |
38 </xsl:template> | 52 </xsl:template> |
39 </xsl:stylesheet> | 53 </xsl:stylesheet> |