annotate format.xsl @ 6:d6dae580f6a0

preliminary attempt to detect currency formatting
author Henry S. Thompson <ht@markup.co.uk>
date Sun, 02 Apr 2017 16:49:48 +0800
parents 106bf970a867
children fd8678fb7b4d
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"/>
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 -->
d6dae580f6a0 preliminary attempt to detect currency formatting
Henry S. Thompson <ht@markup.co.uk>
parents: 5
diff changeset
14 <xsl:value-of select="matches($format,concat('^[&quot;',&quot;'&quot;,'][£$&#162;-&#165;]'))"/>
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">
106bf970a867 builtin fmt and locally-defined fmtCode
Henry S. Thompson <ht@markup.co.uk>
parents: 4
diff changeset
18 <worksheet xmlns:r="http://schemas.openxmlformats.org/officeDocument/2006/relationships" xmlns:x14ac="http://schemas.microsoft.com/office/spreadsheetml/2009/9/ac"><xsl:apply-templates select="@*|node()"/></worksheet>
106bf970a867 builtin fmt and locally-defined fmtCode
Henry S. Thompson <ht@markup.co.uk>
parents: 4
diff changeset
19 </xsl:template>
4
fe3fc6b2d890 1st level of format type lookup
Henry S. Thompson <ht@markup.co.uk>
parents: 3
diff changeset
20 <xsl:template match="s:c">
fe3fc6b2d890 1st level of format type lookup
Henry S. Thompson <ht@markup.co.uk>
parents: 3
diff changeset
21 <xsl:if test="@s">
5
106bf970a867 builtin fmt and locally-defined fmtCode
Henry S. Thompson <ht@markup.co.uk>
parents: 4
diff changeset
22 <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
23 <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
24 <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
25 <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
26 <c>
106bf970a867 builtin fmt and locally-defined fmtCode
Henry S. Thompson <ht@markup.co.uk>
parents: 4
diff changeset
27 <xsl:choose>
106bf970a867 builtin fmt and locally-defined fmtCode
Henry S. Thompson <ht@markup.co.uk>
parents: 4
diff changeset
28 <xsl:when test="$biClass">
6
d6dae580f6a0 preliminary attempt to detect currency formatting
Henry S. Thompson <ht@markup.co.uk>
parents: 5
diff changeset
29 <xsl:attribute namespace="http://markup.co.uk/excel" name="fClass">
5
106bf970a867 builtin fmt and locally-defined fmtCode
Henry S. Thompson <ht@markup.co.uk>
parents: 4
diff changeset
30 <xsl:value-of select="$biClass"/>
106bf970a867 builtin fmt and locally-defined fmtCode
Henry S. Thompson <ht@markup.co.uk>
parents: 4
diff changeset
31 </xsl:attribute>
106bf970a867 builtin fmt and locally-defined fmtCode
Henry S. Thompson <ht@markup.co.uk>
parents: 4
diff changeset
32 </xsl:when>
106bf970a867 builtin fmt and locally-defined fmtCode
Henry S. Thompson <ht@markup.co.uk>
parents: 4
diff changeset
33 <xsl:when test="$nfs[@numFmtId=$nfi]">
6
d6dae580f6a0 preliminary attempt to detect currency formatting
Henry S. Thompson <ht@markup.co.uk>
parents: 5
diff changeset
34 <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
35 <xsl:choose>
d6dae580f6a0 preliminary attempt to detect currency formatting
Henry S. Thompson <ht@markup.co.uk>
parents: 5
diff changeset
36 <xsl:when test="e:currencyFormatP($code)">
d6dae580f6a0 preliminary attempt to detect currency formatting
Henry S. Thompson <ht@markup.co.uk>
parents: 5
diff changeset
37 <xsl:attribute namespace="http://markup.co.uk/excel" name="fClass">cur</xsl:attribute>
d6dae580f6a0 preliminary attempt to detect currency formatting
Henry S. Thompson <ht@markup.co.uk>
parents: 5
diff changeset
38 </xsl:when>
d6dae580f6a0 preliminary attempt to detect currency formatting
Henry S. Thompson <ht@markup.co.uk>
parents: 5
diff changeset
39 <xsl:otherwise>
d6dae580f6a0 preliminary attempt to detect currency formatting
Henry S. Thompson <ht@markup.co.uk>
parents: 5
diff changeset
40 <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
41 <xsl:value-of select="$code"/>
5
106bf970a867 builtin fmt and locally-defined fmtCode
Henry S. Thompson <ht@markup.co.uk>
parents: 4
diff changeset
42 </xsl:attribute>
6
d6dae580f6a0 preliminary attempt to detect currency formatting
Henry S. Thompson <ht@markup.co.uk>
parents: 5
diff changeset
43 </xsl:otherwise>
d6dae580f6a0 preliminary attempt to detect currency formatting
Henry S. Thompson <ht@markup.co.uk>
parents: 5
diff changeset
44 </xsl:choose>
5
106bf970a867 builtin fmt and locally-defined fmtCode
Henry S. Thompson <ht@markup.co.uk>
parents: 4
diff changeset
45 </xsl:when>
106bf970a867 builtin fmt and locally-defined fmtCode
Henry S. Thompson <ht@markup.co.uk>
parents: 4
diff changeset
46 </xsl:choose>
4
fe3fc6b2d890 1st level of format type lookup
Henry S. Thompson <ht@markup.co.uk>
parents: 3
diff changeset
47 <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
48 <xsl:apply-templates/>
5
106bf970a867 builtin fmt and locally-defined fmtCode
Henry S. Thompson <ht@markup.co.uk>
parents: 4
diff changeset
49 </c>
4
fe3fc6b2d890 1st level of format type lookup
Henry S. Thompson <ht@markup.co.uk>
parents: 3
diff changeset
50 </xsl:if>
3
2c115aefde6b beginning work on elaboration of worksheets
Henry S. Thompson <ht@markup.co.uk>
parents:
diff changeset
51 </xsl:template>
5
106bf970a867 builtin fmt and locally-defined fmtCode
Henry S. Thompson <ht@markup.co.uk>
parents: 4
diff changeset
52 <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
53 </xsl:template>
3
2c115aefde6b beginning work on elaboration of worksheets
Henry S. Thompson <ht@markup.co.uk>
parents:
diff changeset
54 </xsl:stylesheet>