comparison rect.xsl @ 24:87e0d620deea

switch to elements from attributes and default namespace
author Henry S. Thompson <ht@markup.co.uk>
date Thu, 06 Apr 2017 17:24:30 +0100
parents 104ef815b0b0
children d2ca3ea1f5ae
comparison
equal deleted inserted replaced
23:bfa38afaea63 24:87e0d620deea
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://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:variable name="refs" select="collection()[2]/*"/> 6 <xsl:variable name="refs" select="collection()[2]/*"/>
7 7
8 <xsl:key name="ref" match="e:ref" use="tokenize(@r)"/> 8 <xsl:key name="ref" match="e:ref" use="e:s"/>
9 9
10 <xsl:function name="e:a2n" as="xs:integer"> 10 <xsl:function name="e:a2n" as="xs:integer">
11 <!-- Convert an alphabetic excel column 'index' into a number, 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 --> 12 a sort of base 26 + 1, since 'A' is 1 and 'AA' is 27 -->
13 <xsl:param name="aa" as="xs:string"/> 13 <xsl:param name="aa" as="xs:string"/>
43 <xsl:variable name="dims" select="analyze-string($dim,'([A-Z]+)([0-9]+):([A-Z]+)([0-9]+)')"/> 43 <xsl:variable name="dims" select="analyze-string($dim,'([A-Z]+)([0-9]+):([A-Z]+)([0-9]+)')"/>
44 <xsl:variable name="height" select="1+xs:integer($dims//xpf:group[@nr='4'])-xs:integer($dims//xpf:group[@nr='2'])"/> 44 <xsl:variable name="height" select="1+xs:integer($dims//xpf:group[@nr='4'])-xs:integer($dims//xpf:group[@nr='2'])"/>
45 <xsl:variable name="width" select="1+e:a2n($dims//xpf:group[@nr='3'])-e:a2n($dims//xpf:group[@nr='1'])"/> 45 <xsl:variable name="width" select="1+e:a2n($dims//xpf:group[@nr='3'])-e:a2n($dims//xpf:group[@nr='1'])"/>
46 <!-- Brute force! --> 46 <!-- Brute force! -->
47 <xsl:variable name="sheet" select="."/> 47 <xsl:variable name="sheet" select="."/>
48 <e:a> 48 <a>
49 <xsl:text>&#10;</xsl:text> 49 <xsl:text>&#10;</xsl:text>
50 <xsl:for-each select="(1 to $height)"><xsl:variable name="row" select="."/> 50 <xsl:for-each select="(1 to $height)"><xsl:variable name="row" select="."/>
51 <e:r r="{$row}"> 51 <r r="{$row}">
52 <xsl:variable select="$sheet/s:row[@r=$row]/s:c" name="cells"/> 52 <xsl:variable select="$sheet/s:row[@r=$row]/s:c" name="cells"/>
53 <xsl:if test="$cells/*"> 53 <xsl:if test="$cells/*">
54 <xsl:for-each select="(1 to $width)"> 54 <xsl:for-each select="(1 to $width)">
55 <xsl:variable name="col" select="."/> 55 <xsl:variable name="col" select="."/>
56 <xsl:variable name="r" select="concat(e:n2a($col),string($row))"/> 56 <xsl:variable name="r" select="concat(e:n2a($col),string($row))"/>
57 <xsl:variable name="c" select="$cells[@r=$r]"/> 57 <xsl:variable name="c" select="$cells[@r=$r]"/>
58 <xsl:variable name="reffed" select="key('ref',$r,$refs)"/> 58 <xsl:variable name="reffed" select="key('ref',$r,$refs)"/>
59 <e:c c="{$col}"> 59 <c c="{$col}">
60 <xsl:if test="$c/s:f"><xsl:attribute name="f">1</xsl:attribute></xsl:if> 60 <xsl:if test="$c/s:f"><xsl:attribute name="f">1</xsl:attribute></xsl:if>
61 <xsl:if test="$reffed"><xsl:attribute name="r"><xsl:value-of select="$reffed/@c"/></xsl:attribute></xsl:if> 61 <xsl:if test="$c/*"><t><xsl:value-of select="substring($c/@e:type,1,1)"/></t></xsl:if>
62 <xsl:if test="$c/*"><xsl:value-of select="substring($c/@e:type,1,1)"/></xsl:if> 62 <xsl:if test="$reffed"><xsl:for-each select="$reffed/@c"><r><xsl:value-of select="."/></r></xsl:for-each></xsl:if>
63 </e:c> 63 </c>
64 </xsl:for-each></xsl:if> 64 </xsl:for-each></xsl:if>
65 </e:r> 65 </r>
66 <xsl:text>&#10;</xsl:text></xsl:for-each> 66 <xsl:text>&#10;</xsl:text></xsl:for-each>
67 </e:a> 67 </a>
68 </xsl:if> 68 </xsl:if>
69 </xsl:template> 69 </xsl:template>
70 </xsl:stylesheet> 70 </xsl:stylesheet>