comparison refs.xsl @ 23:bfa38afaea63

change to default ns
author Henry S. Thompson <ht@markup.co.uk>
date Thu, 06 Apr 2017 16:47:53 +0100
parents ca98c74a7cb1
children 87e0d620deea
comparison
equal deleted inserted replaced
22:ca98c74a7cb1 23:bfa38afaea63
1 <?xml version='1.0'?> 1 <?xml version='1.0'?>
2 <!DOCTYPE doc SYSTEM "../../../lib/xml/xsl.dtd" > 2 <!DOCTYPE doc SYSTEM "../../../lib/xml/xsl.dtd" >
3 <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" xmlns="http://schemas.openxmlformats.org/spreadsheetml/2006/main" xmlns:xf="http://www.w3.org/2005/xpath-functions"> 3 <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 e xf" xmlns="http://markup.co.uk/excel" xmlns:xf="http://www.w3.org/2005/xpath-functions">
4 <xsl:variable name="pat1">("[^"]*")|(\{[^}]+})|(,)|([^=\-+*/();:,.$&lt;>^!]+(?:\.[^=\-+*/();:,.$&lt;>^!]+)*\()|([)])|(^=|\()|((?:'[^']+')|(?:\[[0-9]+\][^!]*))|(\$?[A-Z]+\$?[0-9]+)|([a-zA-Z_\\][a-zA-Z0-9._]*)|(.)</xsl:variable> 4 <xsl:variable name="pat1">("[^"]*")|(\{[^}]+})|(,)|([^=\-+*/();:,.$&lt;>^!]+(?:\.[^=\-+*/();:,.$&lt;>^!]+)*\()|([)])|(^=|\()|((?:'[^']+')|(?:\[[0-9]+\][^!]*))|(\$?[A-Z]+\$?[0-9]+)|([a-zA-Z_\\][a-zA-Z0-9._]*)|(.)</xsl:variable>
5 <xsl:param name="pat" select="$pat1"/> 5 <xsl:param name="pat" select="$pat1"/>
6 6
7 <xsl:template match="/"> 7 <xsl:template match="/">
8 <e:refs><xsl:apply-templates select="//s:c"/></e:refs> 8 <refs><xsl:apply-templates select="//s:c"/></refs>
9 </xsl:template> 9 </xsl:template>
10 10
11 <xsl:template match="s:c[s:f]"> 11 <xsl:template match="s:c[s:f]">
12 <xsl:variable name="tokens" select="analyze-string(s:f/.,$pat)/xf:match/xf:group"/> 12 <xsl:variable name="tokens" select="analyze-string(s:f/.,$pat)/xf:match/xf:group"/>
13 <xsl:if test="@r='B4'"><xsl:message><xsl:value-of select="$tokens/@nr"/></xsl:message> 13 <xsl:if test="@r='B4'"><xsl:message><xsl:value-of select="$tokens/@nr"/></xsl:message>
14 <xsl:message><xsl:value-of select="$tokens/."/></xsl:message> 14 <xsl:message><xsl:value-of select="$tokens/."/></xsl:message>
15 </xsl:if> 15 </xsl:if>
16 <xsl:if test="$tokens[@nr=(7,8,9)]"> 16 <xsl:if test="$tokens[@nr=(7,8,9)]">
17 <xsl:variable name="n" select="count($tokens)"/> 17 <xsl:variable name="n" select="count($tokens)"/>
18 <xsl:variable name="singles" select="for $i in (1 to $n) 18 <xsl:variable name="singles" select="for $i in (1 to $n)
19 return if ($tokens[$i][@nr=(8,9)] and not($tokens[$i - 1][@nr=10 and .=(':','!')]) and not($tokens[$i + 1][@nr=10 and .=':'])) 19 return if ($tokens[$i][@nr=(8,9)] and
20 not($tokens[$i - 1][@nr=10 and
21 .=(':','!')]) and
22 not($tokens[$i + 1][@nr=10 and .=':']))
20 then translate($tokens[$i],'$','') 23 then translate($tokens[$i],'$','')
21 else ()"/> 24 else ()"/>
25 <!-- Note that we don't bother to treat external ranges as ranges,
26 since we're not going to try to detect cross-document refs -->
22 <xsl:variable name="ranges" select="for $i in (1 to count($tokens)) 27 <xsl:variable name="ranges" select="for $i in (1 to count($tokens))
23 return if ($tokens[$i][@nr=10 and .=':' and 28 return if ($tokens[$i][@nr=10 and .=':' and
24 not($i gt 2 and 29 not($i gt 2 and
25 $tokens[$i - 2][@nr=10 and .='!'])]) 30 $tokens[$i - 2][@nr=10 and .='!'])])
26 then translate(concat($tokens[$i - 1],':',$tokens[$i + 1]),'$','') 31 then translate(concat($tokens[$i - 1],':',$tokens[$i + 1]),'$','')
28 <xsl:variable name="externals" select="for $i in (1 to count($tokens)) 33 <xsl:variable name="externals" select="for $i in (1 to count($tokens))
29 return if ($tokens[$i][@nr=7]) 34 return if ($tokens[$i][@nr=7])
30 then 35 then
31 let $bit := concat($tokens[$i],'!', 36 let $bit := concat($tokens[$i],'!',
32 translate($tokens[$i + 2],'$','')) 37 translate($tokens[$i + 2],'$',''))
33 return if ((($i+3) le $n) and $tokens[$i + 3][@nr=10 and .=':']) 38 return if ((($i+3) le $n) and
39 $tokens[$i + 3][@nr=10 and .=':'])
34 then concat($bit,':',translate($tokens[$i + 4],'$','')) 40 then concat($bit,':',translate($tokens[$i + 4],'$',''))
35 else $bit 41 else $bit
36 else ()"/> 42 else ()"/>
37 <e:ref c="{@r}" r="{$singles}" rr="{$ranges}" er="{$externals}"/></xsl:if> 43 <ref c="{@r}">
44 <!-- Assumes that space doesn't occur in variable names
45 Might occur in external names (who knows!) but I'm assuming we're
46 never going to split the value of @er back out... -->
47 <xsl:if test="count($singles)>0"><xsl:attribute name="r"><xsl:value-of select="distinct-values($singles)"/></xsl:attribute></xsl:if>
48 <xsl:if test="count($ranges)>0"><xsl:attribute name="rr"><xsl:value-of select="distinct-values($ranges)"/></xsl:attribute></xsl:if>
49 <xsl:if test="count($externals)>0"><xsl:attribute name="er"><xsl:value-of select="distinct-values($externals)"/></xsl:attribute></xsl:if>
50 </ref></xsl:if>
38 </xsl:template> 51 </xsl:template>
39 52
40 <xsl:template match="s:c"/> 53 <xsl:template match="s:c"/>
41 </xsl:stylesheet> 54 </xsl:stylesheet>