Mercurial > hg > ooxml
diff format.xsl @ 5:106bf970a867
builtin fmt and locally-defined fmtCode
author | Henry S. Thompson <ht@markup.co.uk> |
---|---|
date | Sat, 01 Apr 2017 23:50:20 +0800 |
parents | fe3fc6b2d890 |
children | d6dae580f6a0 |
line wrap: on
line diff
--- a/format.xsl Sat Apr 01 21:44:19 2017 +0800 +++ b/format.xsl Sat Apr 01 23:50:20 2017 +0800 @@ -1,17 +1,39 @@ <?xml version='1.0'?> <!DOCTYPE doc SYSTEM "../../../lib/xml/xsl.dtd" > -<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"> +<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"> <xsl:param name="elabDir"/> <xsl:variable name="xldir" select="replace(base-uri(),'/[^/]*/[^/]*$','')"/> - <xsl:variable name="fmts" select="document($elabDir/fmt.xml)/fmts/fmt"/> - <xsl:variable name="styles" select="document(concat($xldir,'/styles.xml'))/*"></xsl:variable> + <xsl:variable name="fmts" select="document(concat($elabDir,'/fmt.xml'))/fmts/fmt"/> + <xsl:variable name="styles" select="document(concat($xldir,'/styles.xml'))/*"/> <xsl:variable name="xfs" select="$styles//s:cellXfs/s:xf"/> + <xsl:variable name="nfs" select="$styles//s:numFmts/s:numFmt"/> + <xsl:template match="s:worksheet"> + <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> + </xsl:template> <xsl:template match="s:c"> <xsl:if test="@s"> - <s:c e:type="{$xfs[position()=current()/@s]/@numFmtId}"> + <xsl:variable name="i" select="number(@s)"/> + <xsl:variable name="nfi" select="$xfs[position()-1=$i]/@numFmtId"/> + <xsl:variable name="builtin" select="$fmts[@i=$nfi]"/> + <xsl:variable name="biClass" select="$builtin/@class"/> + <c> + <xsl:choose> + <xsl:when test="$biClass"> + <xsl:attribute namespace="http://markup.co.uk/excel" name="class"> + <xsl:value-of select="$biClass"/> + </xsl:attribute> + </xsl:when> + <xsl:when test="$nfs[@numFmtId=$nfi]"> + <xsl:attribute namespace="http://markup.co.uk/excel" name="code"> + <xsl:value-of select="$nfs[@numFmtId=$nfi]/@formatCode"/> + </xsl:attribute> + </xsl:when> + </xsl:choose> <xsl:for-each select="@*"><xsl:copy/></xsl:for-each> <xsl:apply-templates/> - </s:c> + </c> </xsl:if> </xsl:template> + <xsl:template match="@*|node()"><xsl:copy><xsl:apply-templates select="@*|node()"/></xsl:copy> + </xsl:template> </xsl:stylesheet>