Mercurial > hg > ooxml
annotate format.xsl @ 22:ca98c74a7cb1
towards var handling, no lookup yet
author | Henry S. Thompson <ht@markup.co.uk> |
---|---|
date | Wed, 05 Apr 2017 11:57:00 +0100 |
parents | 2bbd067529b6 |
children | 8309dcfce613 |
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"/> |
3
2c115aefde6b
beginning work on elaboration of worksheets
Henry S. Thompson <ht@markup.co.uk>
parents:
diff
changeset
|
5 <xsl:variable name="xldir" select="replace(base-uri(),'/[^/]*/[^/]*$','')"/> |
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"/> |
106bf970a867
builtin fmt and locally-defined fmtCode
Henry S. Thompson <ht@markup.co.uk>
parents:
4
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('^["',"'",'\\]\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"/> |
106bf970a867
builtin fmt and locally-defined fmtCode
Henry S. Thompson <ht@markup.co.uk>
parents:
4
diff
changeset
|
46 <c> |
106bf970a867
builtin fmt and locally-defined fmtCode
Henry S. Thompson <ht@markup.co.uk>
parents:
4
diff
changeset
|
47 <xsl:choose> |
106bf970a867
builtin fmt and locally-defined fmtCode
Henry S. Thompson <ht@markup.co.uk>
parents:
4
diff
changeset
|
48 <xsl:when test="$biClass"> |
7
fd8678fb7b4d
move to type/[class|code]
Henry S. Thompson <ht@markup.co.uk>
parents:
6
diff
changeset
|
49 <xsl:choose> |
fd8678fb7b4d
move to type/[class|code]
Henry S. Thompson <ht@markup.co.uk>
parents:
6
diff
changeset
|
50 <xsl:when test="$biClass='date'"> |
fd8678fb7b4d
move to type/[class|code]
Henry S. Thompson <ht@markup.co.uk>
parents:
6
diff
changeset
|
51 <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
|
52 </xsl:when> |
fd8678fb7b4d
move to type/[class|code]
Henry S. Thompson <ht@markup.co.uk>
parents:
6
diff
changeset
|
53 <xsl:otherwise> |
fd8678fb7b4d
move to type/[class|code]
Henry S. Thompson <ht@markup.co.uk>
parents:
6
diff
changeset
|
54 <xsl:attribute namespace="http://markup.co.uk/excel" name="type">num</xsl:attribute> |
fd8678fb7b4d
move to type/[class|code]
Henry S. Thompson <ht@markup.co.uk>
parents:
6
diff
changeset
|
55 <xsl:if test="$biClass!='num'"><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
|
56 <xsl:value-of select="$biClass"/> |
7
fd8678fb7b4d
move to type/[class|code]
Henry S. Thompson <ht@markup.co.uk>
parents:
6
diff
changeset
|
57 </xsl:attribute></xsl:if> |
fd8678fb7b4d
move to type/[class|code]
Henry S. Thompson <ht@markup.co.uk>
parents:
6
diff
changeset
|
58 </xsl:otherwise> |
fd8678fb7b4d
move to type/[class|code]
Henry S. Thompson <ht@markup.co.uk>
parents:
6
diff
changeset
|
59 </xsl:choose> |
5
106bf970a867
builtin fmt and locally-defined fmtCode
Henry S. Thompson <ht@markup.co.uk>
parents:
4
diff
changeset
|
60 </xsl:when> |
7
fd8678fb7b4d
move to type/[class|code]
Henry S. Thompson <ht@markup.co.uk>
parents:
6
diff
changeset
|
61 <xsl:otherwise> |
fd8678fb7b4d
move to type/[class|code]
Henry S. Thompson <ht@markup.co.uk>
parents:
6
diff
changeset
|
62 <!-- 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
|
63 <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
|
64 <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
|
65 <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
|
66 <xsl:choose> |
d6dae580f6a0
preliminary attempt to detect currency formatting
Henry S. Thompson <ht@markup.co.uk>
parents:
5
diff
changeset
|
67 <xsl:when test="e:currencyFormatP($code)"> |
7
fd8678fb7b4d
move to type/[class|code]
Henry S. Thompson <ht@markup.co.uk>
parents:
6
diff
changeset
|
68 <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
|
69 </xsl:when> |
d6dae580f6a0
preliminary attempt to detect currency formatting
Henry S. Thompson <ht@markup.co.uk>
parents:
5
diff
changeset
|
70 <xsl:otherwise> |
d6dae580f6a0
preliminary attempt to detect currency formatting
Henry S. Thompson <ht@markup.co.uk>
parents:
5
diff
changeset
|
71 <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
|
72 <xsl:value-of select="$code"/> |
5
106bf970a867
builtin fmt and locally-defined fmtCode
Henry S. Thompson <ht@markup.co.uk>
parents:
4
diff
changeset
|
73 </xsl:attribute> |
6
d6dae580f6a0
preliminary attempt to detect currency formatting
Henry S. Thompson <ht@markup.co.uk>
parents:
5
diff
changeset
|
74 </xsl:otherwise> |
d6dae580f6a0
preliminary attempt to detect currency formatting
Henry S. Thompson <ht@markup.co.uk>
parents:
5
diff
changeset
|
75 </xsl:choose> |
7
fd8678fb7b4d
move to type/[class|code]
Henry S. Thompson <ht@markup.co.uk>
parents:
6
diff
changeset
|
76 </xsl:if> |
fd8678fb7b4d
move to type/[class|code]
Henry S. Thompson <ht@markup.co.uk>
parents:
6
diff
changeset
|
77 </xsl:otherwise> |
5
106bf970a867
builtin fmt and locally-defined fmtCode
Henry S. Thompson <ht@markup.co.uk>
parents:
4
diff
changeset
|
78 </xsl:choose> |
4
fe3fc6b2d890
1st level of format type lookup
Henry S. Thompson <ht@markup.co.uk>
parents:
3
diff
changeset
|
79 <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
|
80 <xsl:apply-templates/> |
7
fd8678fb7b4d
move to type/[class|code]
Henry S. Thompson <ht@markup.co.uk>
parents:
6
diff
changeset
|
81 </c> |
3
2c115aefde6b
beginning work on elaboration of worksheets
Henry S. Thompson <ht@markup.co.uk>
parents:
diff
changeset
|
82 </xsl:template> |
5
106bf970a867
builtin fmt and locally-defined fmtCode
Henry S. Thompson <ht@markup.co.uk>
parents:
4
diff
changeset
|
83 <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
|
84 </xsl:template> |
3
2c115aefde6b
beginning work on elaboration of worksheets
Henry S. Thompson <ht@markup.co.uk>
parents:
diff
changeset
|
85 </xsl:stylesheet> |