view refs2.xsl @ 53:8000dbed09df

better, now failing on [1]\!'AES,DIVIDEND'
author Henry S. Thompson <ht@markup.co.uk>
date Tue, 16 May 2017 19:09:03 +0100
parents 3e9a3e51627e
children adeb9575b273
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:xs="http://www.w3.org/2001/XMLSchema" xmlns:e="http://markup.co.uk/excel" exclude-result-prefixes="xs e" xmlns="http://markup.co.uk/excel">
 <!-- Invert the singleton references extracted from formulae by refs.xsl 
      Input e:refs/e:ref/(e:s|e:r)  e:ref[@r] contains one or more e:s or e:r
                                        for each singleton/range reference
                                        to [e:r/]e:s/@r in @r's formula
      Output e:refs/e:i/e:r e:i[@r] contains one e:r for each cell which
                                     references r -->
 
 <xsl:include href="n2a.xsl"/>
 <xsl:include href="a2n.xsl"/>
 
 <xsl:key name="ref" match="e:ref[e:s]" use="for $s in e:s return translate($s/@r,'$','')"/>
 <xsl:key name="rrefTL" match="e:ref[e:r]" use="for $s in e:r/(e:s[1]) return translate($s/@r,'$','')"/>
 <xsl:key name="rrefBR" match="e:ref[e:r]" use="for $s in e:r/(e:s[2]) return translate($s/@r,'$','')"/>
 
 <xsl:template match="e:refs">
  <xsl:variable name="refs" select="."/>
  <xsl:variable name="invert">
  <xsl:for-each select="distinct-values(
                        for $s in e:ref//e:s return translate($s/@r,'$',''))">
   <xsl:variable name="r" select="."/>
   <i r="{$r}">
    <xsl:for-each select="key('ref',$r,$refs)">
     <r><xsl:value-of select="@r"/></r>
    </xsl:for-each>
    <xsl:for-each select="key('rrefTL',$r,$refs)">
     <r>&lt;<xsl:value-of select="@r"/></r>
    </xsl:for-each>
    <xsl:for-each select="key('rrefBR',$r,$refs)">
     <r><xsl:value-of select="@r"/>&gt;</r>
    </xsl:for-each>
   </i>
  </xsl:for-each>
   <!-- We want to be able to sort by frequency, so just d-v isn't enough -->
  <xsl:for-each-group select="e:nf" group-by="text()">
   <nf i="{position()}" n="{count(current-group())}"><xsl:value-of select="current-group()[1]/text()"/></nf>
  </xsl:for-each-group>
 </xsl:variable>
  <xsl:copy>
   <xsl:copy-of select="$invert"/>
  </xsl:copy>
 </xsl:template>
</xsl:stylesheet>