comparison 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
comparison
equal deleted inserted replaced
5:106bf970a867 6:d6dae580f6a0
5 <xsl:variable name="xldir" select="replace(base-uri(),'/[^/]*/[^/]*$','')"/> 5 <xsl:variable name="xldir" select="replace(base-uri(),'/[^/]*/[^/]*$','')"/>
6 <xsl:variable name="fmts" select="document(concat($elabDir,'/fmt.xml'))/fmts/fmt"/> 6 <xsl:variable name="fmts" select="document(concat($elabDir,'/fmt.xml'))/fmts/fmt"/>
7 <xsl:variable name="styles" select="document(concat($xldir,'/styles.xml'))/*"/> 7 <xsl:variable name="styles" select="document(concat($xldir,'/styles.xml'))/*"/>
8 <xsl:variable name="xfs" select="$styles//s:cellXfs/s:xf"/> 8 <xsl:variable name="xfs" select="$styles//s:cellXfs/s:xf"/>
9 <xsl:variable name="nfs" select="$styles//s:numFmts/s:numFmt"/> 9 <xsl:variable name="nfs" select="$styles//s:numFmts/s:numFmt"/>
10
11 <xsl:function name="e:currencyFormatP" as="xs:boolean">
12 <xsl:param name="format"/>
13 <!-- Really need a unicode block check -->
14 <xsl:value-of select="matches($format,concat('^[&quot;',&quot;'&quot;,'][£$&#162;-&#165;]'))"/>
15 </xsl:function>
16
10 <xsl:template match="s:worksheet"> 17 <xsl:template match="s:worksheet">
11 <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> 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>
12 </xsl:template> 19 </xsl:template>
13 <xsl:template match="s:c"> 20 <xsl:template match="s:c">
14 <xsl:if test="@s"> 21 <xsl:if test="@s">
17 <xsl:variable name="builtin" select="$fmts[@i=$nfi]"/> 24 <xsl:variable name="builtin" select="$fmts[@i=$nfi]"/>
18 <xsl:variable name="biClass" select="$builtin/@class"/> 25 <xsl:variable name="biClass" select="$builtin/@class"/>
19 <c> 26 <c>
20 <xsl:choose> 27 <xsl:choose>
21 <xsl:when test="$biClass"> 28 <xsl:when test="$biClass">
22 <xsl:attribute namespace="http://markup.co.uk/excel" name="class"> 29 <xsl:attribute namespace="http://markup.co.uk/excel" name="fClass">
23 <xsl:value-of select="$biClass"/> 30 <xsl:value-of select="$biClass"/>
24 </xsl:attribute> 31 </xsl:attribute>
25 </xsl:when> 32 </xsl:when>
26 <xsl:when test="$nfs[@numFmtId=$nfi]"> 33 <xsl:when test="$nfs[@numFmtId=$nfi]">
27 <xsl:attribute namespace="http://markup.co.uk/excel" name="code"> 34 <xsl:variable name="code" select="$nfs[@numFmtId=$nfi]/@formatCode"/>
28 <xsl:value-of select="$nfs[@numFmtId=$nfi]/@formatCode"/> 35 <xsl:choose>
36 <xsl:when test="e:currencyFormatP($code)">
37 <xsl:attribute namespace="http://markup.co.uk/excel" name="fClass">cur</xsl:attribute>
38 </xsl:when>
39 <xsl:otherwise>
40 <xsl:attribute namespace="http://markup.co.uk/excel" name="code">
41 <xsl:value-of select="$code"/>
29 </xsl:attribute> 42 </xsl:attribute>
43 </xsl:otherwise>
44 </xsl:choose>
30 </xsl:when> 45 </xsl:when>
31 </xsl:choose> 46 </xsl:choose>
32 <xsl:for-each select="@*"><xsl:copy/></xsl:for-each> 47 <xsl:for-each select="@*"><xsl:copy/></xsl:for-each>
33 <xsl:apply-templates/> 48 <xsl:apply-templates/>
34 </c> 49 </c>