Mercurial > hg > ooxml
view rect.xsl @ 72:0654e37583b5
appears to read kdir.js correctly
author | Henry S. Thompson <ht@markup.co.uk> |
---|---|
date | Thu, 29 Jun 2017 17:58:06 +0100 |
parents | d3569a8cbf7a |
children |
line wrap: on
line source
<?xml version='1.0'?> <!DOCTYPE doc SYSTEM "../../../lib/xml/xsl.dtd" > <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="3.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 xpf e" xmlns="http://markup.co.uk/excel" xmlns:xpf="http://www.w3.org/2005/xpath-functions"> <xsl:strip-space elements="s:sheetData"/> <xsl:include href="a2n.xsl"/> <xsl:include href="n2a.xsl"/> <xsl:include href="tokenise.xsl"/> <xsl:variable name="shared"> <xsl:apply-templates select="collection()[2]/*"/> </xsl:variable> <xsl:key name="shared" match="e:master" use="@si"/> <xsl:variable name="dim" select="//s:dimension/@ref"/> <xsl:function name="e:analyse" as="element(*)*"> <xsl:param name="formula" as="xs:string"/> <xsl:param name="row" as="xs:integer"/> <xsl:param name="col" as="xs:integer"/> <xsl:variable name="toks" select="e:tokenise($formula,$row,$col)"/> <xsl:sequence> <f> <xsl:copy-of select="$toks"/> </f> <nf><xsl:copy-of select="e:fnf($toks)"/></nf> </xsl:sequence> </xsl:function> <xsl:template match="e:master"> <xsl:variable name="rp" select="e:pr(@r)"/> <xsl:copy> <xsl:copy-of select="@si"/> <xsl:sequence select="e:analyse(text(),xs:integer($rp//xpf:group[@nr=4]), e:a2n($rp//xpf:group[@nr=2]))"/> </xsl:copy> </xsl:template> <xsl:template match="/"> <xsl:apply-templates select="//s:sheetData"/> </xsl:template> <xsl:template match="s:sheetData"> <xsl:if test="s:row"> <xsl:variable name="dims" select="analyze-string($dim,'([A-Z]+)([0-9]+):([A-Z]+)([0-9]+)')"/> <xsl:variable name="height" select="1+xs:integer($dims//xpf:group[@nr='4'])-xs:integer($dims//xpf:group[@nr='2'])"/> <xsl:variable name="width" select="1+e:a2n($dims//xpf:group[@nr='3'])-e:a2n($dims//xpf:group[@nr='1'])"/> <!-- Brute force! --> <xsl:variable name="sheet" select="."/> <a> <xsl:text> </xsl:text> <xsl:for-each select="(1 to $height)"><xsl:variable name="row" select="."/> <r r="{$row}"> <xsl:variable select="$sheet/s:row[@r=$row]/s:c" name="cells"/> <xsl:if test="$cells/*"> <xsl:for-each select="(1 to $width)"> <xsl:variable name="col" select="."/> <xsl:variable name="r" select="concat(e:n2a($col),string($row))"/> <xsl:variable name="c" select="$cells[@r=$r]"/> <c c="{$col}"> <xsl:if test="$c/*"> <xsl:if test="$c/@e:class"><xsl:attribute name="t"><xsl:value-of select="substring($c/@e:class,1,1)"/></xsl:attribute></xsl:if> <xsl:if test="$c/@e:code"><xsl:attribute name="l"><xsl:value-of select="$c/@e:code"/></xsl:attribute></xsl:if> <xsl:variable name="si" select="$c/s:f/@si"/> <xsl:copy-of select="$si"/> <xsl:choose> <xsl:when test="$c/s:f/text()"> <xsl:sequence select="e:analyse($c/s:f/text(),$row,$col)"/> </xsl:when> <xsl:when test="$c/s:f/@si"> <xsl:variable name="s" select="key('shared',$si,$shared)"/> <xsl:for-each select="$s/e:f"><xsl:call-template name="shift"> <xsl:with-param name="row" select="$row"/> <xsl:with-param name="col" select="$col"/> </xsl:call-template></xsl:for-each> <xsl:copy-of select="$s/e:nf"/> </xsl:when> </xsl:choose> <xsl:value-of select="substring($c/@e:type,1,1)"/> </xsl:if> </c> </xsl:for-each></xsl:if> </r> <xsl:text> </xsl:text></xsl:for-each> </a> </xsl:if> </xsl:template> </xsl:stylesheet>