view merge.xsl @ 57:a783afa2b109

much richer annotatation as json-formatted comment
author Henry S. Thompson <ht@markup.co.uk>
date Wed, 31 May 2017 17:41:18 +0100
parents 5d9806f90896
children f90bbd38b8f6
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 e s xpf" 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:variable name="refs" select="collection()[2]/*"/>
 <xsl:variable name="nfs">
  <xsl:for-each select="$refs/e:nf">
   <xsl:sort select="@n" order="descending" data-type="number"/>
   <xsl:message><xsl:value-of select="@n"/>|<xsl:value-of select="position()"/>|<xsl:value-of select="text()"/></xsl:message>
   <e:nf i="{position()}" n="{@n}"><xsl:value-of select="text()"/></e:nf>
  </xsl:for-each>
 </xsl:variable>
 
 <xsl:key name="ref" match="e:i" use="@r"/>
 <xsl:key name="nf" match="e:nf" use="text()"/>
 
 <xsl:template match="/xxx"><a><xsl:copy-of select="$nfs"/>|<xsl:value-of select="count($refs/e:i)"/>|<xsl:value-of select="count($nfs/e:nf)"/>|<xsl:value-of select="count(key('nf','SUM(&#170;2&#170;7:&#170;3&#170;7)',$nfs))"/>|<xsl:value-of select="count($nfs/e:nf[.='SUM(&#170;2&#170;7:&#170;3&#170;7)'])"/>
  <xsl:apply-templates/></a>
 </xsl:template>

 <xsl:template match="e:r/e:c">
  <xsl:variable name="row" select="../@r"/>
  <xsl:variable name="col" select="@c"/>
  <xsl:variable name="reffed" select="key('ref',concat(e:n2a($col),$row),$refs)"/>
  <c>
   <xsl:apply-templates select="@*"/>
   <xsl:if test="e:f">
    <xsl:attribute name="fi"><xsl:value-of select="key('nf',e:nf/text(),$nfs)/@i"/></xsl:attribute>
   </xsl:if>
  <xsl:if test="$reffed"><xsl:copy-of select="$reffed"/></xsl:if>
   <xsl:apply-templates select="node()"/>
  </c>
 </xsl:template>
 
 <xsl:template match="@*|node()"><xsl:copy><xsl:apply-templates select="@*|node()"/></xsl:copy>
 </xsl:template>
</xsl:stylesheet>