annotate format.xsl @ 41:afda541de4c4

working again with new refs
author Henry S. Thompson <ht@markup.co.uk>
date Tue, 02 May 2017 10:00:02 +0100
parents e500d7c18aad
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
3
2c115aefde6b beginning work on elaboration of worksheets
Henry S. Thompson <ht@markup.co.uk>
parents:
diff changeset
1 <?xml version='1.0'?>
2c115aefde6b beginning work on elaboration of worksheets
Henry S. Thompson <ht@markup.co.uk>
parents:
diff changeset
2 <!DOCTYPE doc SYSTEM "../../../lib/xml/xsl.dtd" >
5
106bf970a867 builtin fmt and locally-defined fmtCode
Henry S. Thompson <ht@markup.co.uk>
parents: 4
diff changeset
3 <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="2.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" xmlns="http://schemas.openxmlformats.org/spreadsheetml/2006/main">
4
fe3fc6b2d890 1st level of format type lookup
Henry S. Thompson <ht@markup.co.uk>
parents: 3
diff changeset
4 <xsl:param name="elabDir"/>
27
8309dcfce613 preparing for variable deref
Henry S. Thompson <ht@markup.co.uk>
parents: 16
diff changeset
5 <xsl:param name="xlDir"/>
5
106bf970a867 builtin fmt and locally-defined fmtCode
Henry S. Thompson <ht@markup.co.uk>
parents: 4
diff changeset
6 <xsl:variable name="fmts" select="document(concat($elabDir,'/fmt.xml'))/fmts/fmt"/>
27
8309dcfce613 preparing for variable deref
Henry S. Thompson <ht@markup.co.uk>
parents: 16
diff changeset
7 <xsl:variable name="styles" select="document(concat($xlDir,'/styles.xml'))/*"/>
4
fe3fc6b2d890 1st level of format type lookup
Henry S. Thompson <ht@markup.co.uk>
parents: 3
diff changeset
8 <xsl:variable name="xfs" select="$styles//s:cellXfs/s:xf"/>
5
106bf970a867 builtin fmt and locally-defined fmtCode
Henry S. Thompson <ht@markup.co.uk>
parents: 4
diff changeset
9 <xsl:variable name="nfs" select="$styles//s:numFmts/s:numFmt"/>
6
d6dae580f6a0 preliminary attempt to detect currency formatting
Henry S. Thompson <ht@markup.co.uk>
parents: 5
diff changeset
10
d6dae580f6a0 preliminary attempt to detect currency formatting
Henry S. Thompson <ht@markup.co.uk>
parents: 5
diff changeset
11 <xsl:function name="e:currencyFormatP" as="xs:boolean">
d6dae580f6a0 preliminary attempt to detect currency formatting
Henry S. Thompson <ht@markup.co.uk>
parents: 5
diff changeset
12 <xsl:param name="format"/>
d6dae580f6a0 preliminary attempt to detect currency formatting
Henry S. Thompson <ht@markup.co.uk>
parents: 5
diff changeset
13 <!-- Really need a unicode block check -->
9
5f2d691014ff allow \ to start and use Unicode currency class Sc for currency format code detection
Henry S. Thompson <ht@markup.co.uk>
parents: 7
diff changeset
14 <xsl:value-of select="matches($format,concat('^[&quot;',&quot;'&quot;,'\\]\p{Sc}'))"/>
6
d6dae580f6a0 preliminary attempt to detect currency formatting
Henry S. Thompson <ht@markup.co.uk>
parents: 5
diff changeset
15 </xsl:function>
d6dae580f6a0 preliminary attempt to detect currency formatting
Henry S. Thompson <ht@markup.co.uk>
parents: 5
diff changeset
16
5
106bf970a867 builtin fmt and locally-defined fmtCode
Henry S. Thompson <ht@markup.co.uk>
parents: 4
diff changeset
17 <xsl:template match="s:worksheet">
7
fd8678fb7b4d move to type/[class|code]
Henry S. Thompson <ht@markup.co.uk>
parents: 6
diff changeset
18 <!-- Just here to bind the namespaces at the top -->
16
2bbd067529b6 improve efficiency, detect blank rows, don't type empty cells
Henry S. Thompson <ht@markup.co.uk>
parents: 9
diff changeset
19 <worksheet xmlns:r="http://schemas.openxmlformats.org/officeDocument/2006/relationships" xmlns:x14ac="http://schemas.microsoft.com/office/spreadsheetml/2009/9/ac" xmlns:xdr="http://schemas.openxmlformats.org/drawingml/2006/spreadsheetDrawing" xmlns:x14="http://schemas.microsoft.com/office/spreadsheetml/2009/9/main"><xsl:apply-templates select="@*|node()"/></worksheet>
5
106bf970a867 builtin fmt and locally-defined fmtCode
Henry S. Thompson <ht@markup.co.uk>
parents: 4
diff changeset
20 </xsl:template>
7
fd8678fb7b4d move to type/[class|code]
Henry S. Thompson <ht@markup.co.uk>
parents: 6
diff changeset
21
fd8678fb7b4d move to type/[class|code]
Henry S. Thompson <ht@markup.co.uk>
parents: 6
diff changeset
22 <xsl:template match="s:c[@t and @t!='n']">
fd8678fb7b4d move to type/[class|code]
Henry S. Thompson <ht@markup.co.uk>
parents: 6
diff changeset
23 <!-- These take precedence over formatting-->
fd8678fb7b4d move to type/[class|code]
Henry S. Thompson <ht@markup.co.uk>
parents: 6
diff changeset
24 <xsl:copy>
fd8678fb7b4d move to type/[class|code]
Henry S. Thompson <ht@markup.co.uk>
parents: 6
diff changeset
25 <xsl:attribute namespace="http://markup.co.uk/excel" name="type">
fd8678fb7b4d move to type/[class|code]
Henry S. Thompson <ht@markup.co.uk>
parents: 6
diff changeset
26 <xsl:choose>
fd8678fb7b4d move to type/[class|code]
Henry S. Thompson <ht@markup.co.uk>
parents: 6
diff changeset
27 <xsl:when test="@t='s'">str</xsl:when>
fd8678fb7b4d move to type/[class|code]
Henry S. Thompson <ht@markup.co.uk>
parents: 6
diff changeset
28 <xsl:when test="@t='b'">bool</xsl:when><!-- not yet seen -->
fd8678fb7b4d move to type/[class|code]
Henry S. Thompson <ht@markup.co.uk>
parents: 6
diff changeset
29 <xsl:when test="@t='d'">date</xsl:when><!-- not yet seen -->
fd8678fb7b4d move to type/[class|code]
Henry S. Thompson <ht@markup.co.uk>
parents: 6
diff changeset
30 <xsl:when test="@t='e'">err</xsl:when><!-- not yet seen -->
fd8678fb7b4d move to type/[class|code]
Henry S. Thompson <ht@markup.co.uk>
parents: 6
diff changeset
31 <xsl:when test="@t='inlineStr'">str</xsl:when><!-- not yet seen -->
fd8678fb7b4d move to type/[class|code]
Henry S. Thompson <ht@markup.co.uk>
parents: 6
diff changeset
32 <xsl:when test="@t='str'">str</xsl:when><!-- result of formula with string value -->
fd8678fb7b4d move to type/[class|code]
Henry S. Thompson <ht@markup.co.uk>
parents: 6
diff changeset
33 <xsl:otherwise><xsl:message terminate="yes">Unknown value for c/@t <xsl:value-of select="@t"/></xsl:message></xsl:otherwise>
fd8678fb7b4d move to type/[class|code]
Henry S. Thompson <ht@markup.co.uk>
parents: 6
diff changeset
34 </xsl:choose>
fd8678fb7b4d move to type/[class|code]
Henry S. Thompson <ht@markup.co.uk>
parents: 6
diff changeset
35 </xsl:attribute>
fd8678fb7b4d move to type/[class|code]
Henry S. Thompson <ht@markup.co.uk>
parents: 6
diff changeset
36 <xsl:apply-templates select="@*|node()"/>
fd8678fb7b4d move to type/[class|code]
Henry S. Thompson <ht@markup.co.uk>
parents: 6
diff changeset
37 </xsl:copy>
fd8678fb7b4d move to type/[class|code]
Henry S. Thompson <ht@markup.co.uk>
parents: 6
diff changeset
38 </xsl:template>
fd8678fb7b4d move to type/[class|code]
Henry S. Thompson <ht@markup.co.uk>
parents: 6
diff changeset
39
fd8678fb7b4d move to type/[class|code]
Henry S. Thompson <ht@markup.co.uk>
parents: 6
diff changeset
40 <xsl:template match="s:c[not(@t) or @t='n']">
fd8678fb7b4d move to type/[class|code]
Henry S. Thompson <ht@markup.co.uk>
parents: 6
diff changeset
41 <!-- I _think_ this can only happen if the contents are in some sense numeric -->
5
106bf970a867 builtin fmt and locally-defined fmtCode
Henry S. Thompson <ht@markup.co.uk>
parents: 4
diff changeset
42 <xsl:variable name="i" select="number(@s)"/>
106bf970a867 builtin fmt and locally-defined fmtCode
Henry S. Thompson <ht@markup.co.uk>
parents: 4
diff changeset
43 <xsl:variable name="nfi" select="$xfs[position()-1=$i]/@numFmtId"/>
106bf970a867 builtin fmt and locally-defined fmtCode
Henry S. Thompson <ht@markup.co.uk>
parents: 4
diff changeset
44 <xsl:variable name="builtin" select="$fmts[@i=$nfi]"/>
106bf970a867 builtin fmt and locally-defined fmtCode
Henry S. Thompson <ht@markup.co.uk>
parents: 4
diff changeset
45 <xsl:variable name="biClass" select="$builtin/@class"/>
35
e500d7c18aad Fixed confusion wrt gen vs. num, nature of @ format (id=49)
Henry S. Thompson <ht@markup.co.uk>
parents: 27
diff changeset
46 <xsl:if test="@r='xxx'"><xsl:message><xsl:value-of select="@r"/>: <xsl:value-of select="concat(@s,'|',$nfi,'|',$biClass)"/></xsl:message></xsl:if>
5
106bf970a867 builtin fmt and locally-defined fmtCode
Henry S. Thompson <ht@markup.co.uk>
parents: 4
diff changeset
47 <c>
106bf970a867 builtin fmt and locally-defined fmtCode
Henry S. Thompson <ht@markup.co.uk>
parents: 4
diff changeset
48 <xsl:choose>
106bf970a867 builtin fmt and locally-defined fmtCode
Henry S. Thompson <ht@markup.co.uk>
parents: 4
diff changeset
49 <xsl:when test="$biClass">
7
fd8678fb7b4d move to type/[class|code]
Henry S. Thompson <ht@markup.co.uk>
parents: 6
diff changeset
50 <xsl:choose>
fd8678fb7b4d move to type/[class|code]
Henry S. Thompson <ht@markup.co.uk>
parents: 6
diff changeset
51 <xsl:when test="$biClass='date'">
fd8678fb7b4d move to type/[class|code]
Henry S. Thompson <ht@markup.co.uk>
parents: 6
diff changeset
52 <xsl:attribute namespace="http://markup.co.uk/excel" name="type">date</xsl:attribute>
fd8678fb7b4d move to type/[class|code]
Henry S. Thompson <ht@markup.co.uk>
parents: 6
diff changeset
53 </xsl:when>
fd8678fb7b4d move to type/[class|code]
Henry S. Thompson <ht@markup.co.uk>
parents: 6
diff changeset
54 <xsl:otherwise>
fd8678fb7b4d move to type/[class|code]
Henry S. Thompson <ht@markup.co.uk>
parents: 6
diff changeset
55 <xsl:attribute namespace="http://markup.co.uk/excel" name="type">num</xsl:attribute>
35
e500d7c18aad Fixed confusion wrt gen vs. num, nature of @ format (id=49)
Henry S. Thompson <ht@markup.co.uk>
parents: 27
diff changeset
56 <xsl:if test="not($biClass=('num','gen'))"><xsl:attribute namespace="http://markup.co.uk/excel" name="class">
5
106bf970a867 builtin fmt and locally-defined fmtCode
Henry S. Thompson <ht@markup.co.uk>
parents: 4
diff changeset
57 <xsl:value-of select="$biClass"/>
7
fd8678fb7b4d move to type/[class|code]
Henry S. Thompson <ht@markup.co.uk>
parents: 6
diff changeset
58 </xsl:attribute></xsl:if>
fd8678fb7b4d move to type/[class|code]
Henry S. Thompson <ht@markup.co.uk>
parents: 6
diff changeset
59 </xsl:otherwise>
fd8678fb7b4d move to type/[class|code]
Henry S. Thompson <ht@markup.co.uk>
parents: 6
diff changeset
60 </xsl:choose>
5
106bf970a867 builtin fmt and locally-defined fmtCode
Henry S. Thompson <ht@markup.co.uk>
parents: 4
diff changeset
61 </xsl:when>
7
fd8678fb7b4d move to type/[class|code]
Henry S. Thompson <ht@markup.co.uk>
parents: 6
diff changeset
62 <xsl:otherwise>
fd8678fb7b4d move to type/[class|code]
Henry S. Thompson <ht@markup.co.uk>
parents: 6
diff changeset
63 <!-- Note the completely vanilla no @t no @s case comes here. I _think_ it's correct to treat that as numeric -->
fd8678fb7b4d move to type/[class|code]
Henry S. Thompson <ht@markup.co.uk>
parents: 6
diff changeset
64 <xsl:attribute namespace="http://markup.co.uk/excel" name="type">num</xsl:attribute><!-- Would be wrong if any non-numeric formatCodes exist -->
fd8678fb7b4d move to type/[class|code]
Henry S. Thompson <ht@markup.co.uk>
parents: 6
diff changeset
65 <xsl:if test="$nfs[@numFmtId=$nfi]">
6
d6dae580f6a0 preliminary attempt to detect currency formatting
Henry S. Thompson <ht@markup.co.uk>
parents: 5
diff changeset
66 <xsl:variable name="code" select="$nfs[@numFmtId=$nfi]/@formatCode"/>
d6dae580f6a0 preliminary attempt to detect currency formatting
Henry S. Thompson <ht@markup.co.uk>
parents: 5
diff changeset
67 <xsl:choose>
d6dae580f6a0 preliminary attempt to detect currency formatting
Henry S. Thompson <ht@markup.co.uk>
parents: 5
diff changeset
68 <xsl:when test="e:currencyFormatP($code)">
7
fd8678fb7b4d move to type/[class|code]
Henry S. Thompson <ht@markup.co.uk>
parents: 6
diff changeset
69 <xsl:attribute namespace="http://markup.co.uk/excel" name="class">cur</xsl:attribute>
6
d6dae580f6a0 preliminary attempt to detect currency formatting
Henry S. Thompson <ht@markup.co.uk>
parents: 5
diff changeset
70 </xsl:when>
d6dae580f6a0 preliminary attempt to detect currency formatting
Henry S. Thompson <ht@markup.co.uk>
parents: 5
diff changeset
71 <xsl:otherwise>
d6dae580f6a0 preliminary attempt to detect currency formatting
Henry S. Thompson <ht@markup.co.uk>
parents: 5
diff changeset
72 <xsl:attribute namespace="http://markup.co.uk/excel" name="code">
d6dae580f6a0 preliminary attempt to detect currency formatting
Henry S. Thompson <ht@markup.co.uk>
parents: 5
diff changeset
73 <xsl:value-of select="$code"/>
5
106bf970a867 builtin fmt and locally-defined fmtCode
Henry S. Thompson <ht@markup.co.uk>
parents: 4
diff changeset
74 </xsl:attribute>
6
d6dae580f6a0 preliminary attempt to detect currency formatting
Henry S. Thompson <ht@markup.co.uk>
parents: 5
diff changeset
75 </xsl:otherwise>
d6dae580f6a0 preliminary attempt to detect currency formatting
Henry S. Thompson <ht@markup.co.uk>
parents: 5
diff changeset
76 </xsl:choose>
7
fd8678fb7b4d move to type/[class|code]
Henry S. Thompson <ht@markup.co.uk>
parents: 6
diff changeset
77 </xsl:if>
fd8678fb7b4d move to type/[class|code]
Henry S. Thompson <ht@markup.co.uk>
parents: 6
diff changeset
78 </xsl:otherwise>
5
106bf970a867 builtin fmt and locally-defined fmtCode
Henry S. Thompson <ht@markup.co.uk>
parents: 4
diff changeset
79 </xsl:choose>
4
fe3fc6b2d890 1st level of format type lookup
Henry S. Thompson <ht@markup.co.uk>
parents: 3
diff changeset
80 <xsl:for-each select="@*"><xsl:copy/></xsl:for-each>
fe3fc6b2d890 1st level of format type lookup
Henry S. Thompson <ht@markup.co.uk>
parents: 3
diff changeset
81 <xsl:apply-templates/>
7
fd8678fb7b4d move to type/[class|code]
Henry S. Thompson <ht@markup.co.uk>
parents: 6
diff changeset
82 </c>
3
2c115aefde6b beginning work on elaboration of worksheets
Henry S. Thompson <ht@markup.co.uk>
parents:
diff changeset
83 </xsl:template>
5
106bf970a867 builtin fmt and locally-defined fmtCode
Henry S. Thompson <ht@markup.co.uk>
parents: 4
diff changeset
84 <xsl:template match="@*|node()"><xsl:copy><xsl:apply-templates select="@*|node()"/></xsl:copy>
106bf970a867 builtin fmt and locally-defined fmtCode
Henry S. Thompson <ht@markup.co.uk>
parents: 4
diff changeset
85 </xsl:template>
3
2c115aefde6b beginning work on elaboration of worksheets
Henry S. Thompson <ht@markup.co.uk>
parents:
diff changeset
86 </xsl:stylesheet>