annotate refs.xsl @ 27:8309dcfce613

preparing for variable deref
author Henry S. Thompson <ht@markup.co.uk>
date Mon, 10 Apr 2017 17:29:24 +0100
parents a5125a2e77ea
children c56a2e6990bd
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
17
a874f2a81ed2 default vis pipeline to raw xml, start extracting refs
Henry S. Thompson <ht@markup.co.uk>
parents:
diff changeset
1 <?xml version='1.0'?>
a874f2a81ed2 default vis pipeline to raw xml, start extracting refs
Henry S. Thompson <ht@markup.co.uk>
parents:
diff changeset
2 <!DOCTYPE doc SYSTEM "../../../lib/xml/xsl.dtd" >
23
bfa38afaea63 change to default ns
Henry S. Thompson <ht@markup.co.uk>
parents: 22
diff changeset
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">
27
8309dcfce613 preparing for variable deref
Henry S. Thompson <ht@markup.co.uk>
parents: 25
diff changeset
4 <xsl:param name="sheet-number"/>
8309dcfce613 preparing for variable deref
Henry S. Thompson <ht@markup.co.uk>
parents: 25
diff changeset
5 <xsl:param name="xlDir"/>
8309dcfce613 preparing for variable deref
Henry S. Thompson <ht@markup.co.uk>
parents: 25
diff changeset
6
17
a874f2a81ed2 default vis pipeline to raw xml, start extracting refs
Henry S. Thompson <ht@markup.co.uk>
parents:
diff changeset
7 <xsl:variable name="pat1">("[^"]*")|(\{[^}]+})|(,)|([^=\-+*/();:,.$&lt;>^!]+(?:\.[^=\-+*/();:,.$&lt;>^!]+)*\()|([)])|(^=|\()|((?:'[^']+')|(?:\[[0-9]+\][^!]*))|(\$?[A-Z]+\$?[0-9]+)|([a-zA-Z_\\][a-zA-Z0-9._]*)|(.)</xsl:variable>
27
8309dcfce613 preparing for variable deref
Henry S. Thompson <ht@markup.co.uk>
parents: 25
diff changeset
8 <xsl:param name="pat" select="$pat1"/><!-- xsl:param for refinement debugging by passing in the pattern -->
8309dcfce613 preparing for variable deref
Henry S. Thompson <ht@markup.co.uk>
parents: 25
diff changeset
9
8309dcfce613 preparing for variable deref
Henry S. Thompson <ht@markup.co.uk>
parents: 25
diff changeset
10 <xsl:variable name="workbook" select="document(concat($xlDir,'/workbook.xml'))/*"/>
8309dcfce613 preparing for variable deref
Henry S. Thompson <ht@markup.co.uk>
parents: 25
diff changeset
11 <xsl:variable name="sheet-name" select="$workbook/s:sheets/s:sheet[@sheetId=$sheet-number]/@name"/>
17
a874f2a81ed2 default vis pipeline to raw xml, start extracting refs
Henry S. Thompson <ht@markup.co.uk>
parents:
diff changeset
12
a874f2a81ed2 default vis pipeline to raw xml, start extracting refs
Henry S. Thompson <ht@markup.co.uk>
parents:
diff changeset
13 <xsl:template match="/">
27
8309dcfce613 preparing for variable deref
Henry S. Thompson <ht@markup.co.uk>
parents: 25
diff changeset
14 <refs sheetName="{$sheet-name}"><xsl:apply-templates select="//s:c"/></refs>
17
a874f2a81ed2 default vis pipeline to raw xml, start extracting refs
Henry S. Thompson <ht@markup.co.uk>
parents:
diff changeset
15 </xsl:template>
a874f2a81ed2 default vis pipeline to raw xml, start extracting refs
Henry S. Thompson <ht@markup.co.uk>
parents:
diff changeset
16
18
16bba7a0d0bd one form of refs output, not sure it's what is wanted...
Henry S. Thompson <ht@markup.co.uk>
parents: 17
diff changeset
17 <xsl:template match="s:c[s:f]">
22
ca98c74a7cb1 towards var handling, no lookup yet
Henry S. Thompson <ht@markup.co.uk>
parents: 21
diff changeset
18 <xsl:variable name="tokens" select="analyze-string(s:f/.,$pat)/xf:match/xf:group"/>
27
8309dcfce613 preparing for variable deref
Henry S. Thompson <ht@markup.co.uk>
parents: 25
diff changeset
19 <xsl:if test="@r='A2'"><xsl:message><xsl:value-of select="$tokens/@nr"/></xsl:message>
21
f05f0d0ee296 fix false positives
Henry S. Thompson <ht@markup.co.uk>
parents: 18
diff changeset
20 <xsl:message><xsl:value-of select="$tokens/."/></xsl:message>
f05f0d0ee296 fix false positives
Henry S. Thompson <ht@markup.co.uk>
parents: 18
diff changeset
21 </xsl:if>
22
ca98c74a7cb1 towards var handling, no lookup yet
Henry S. Thompson <ht@markup.co.uk>
parents: 21
diff changeset
22 <xsl:if test="$tokens[@nr=(7,8,9)]">
21
f05f0d0ee296 fix false positives
Henry S. Thompson <ht@markup.co.uk>
parents: 18
diff changeset
23 <xsl:variable name="n" select="count($tokens)"/>
f05f0d0ee296 fix false positives
Henry S. Thompson <ht@markup.co.uk>
parents: 18
diff changeset
24 <xsl:variable name="singles" select="for $i in (1 to $n)
23
bfa38afaea63 change to default ns
Henry S. Thompson <ht@markup.co.uk>
parents: 22
diff changeset
25 return if ($tokens[$i][@nr=(8,9)] and
bfa38afaea63 change to default ns
Henry S. Thompson <ht@markup.co.uk>
parents: 22
diff changeset
26 not($tokens[$i - 1][@nr=10 and
bfa38afaea63 change to default ns
Henry S. Thompson <ht@markup.co.uk>
parents: 22
diff changeset
27 .=(':','!')]) and
bfa38afaea63 change to default ns
Henry S. Thompson <ht@markup.co.uk>
parents: 22
diff changeset
28 not($tokens[$i + 1][@nr=10 and .=':']))
21
f05f0d0ee296 fix false positives
Henry S. Thompson <ht@markup.co.uk>
parents: 18
diff changeset
29 then translate($tokens[$i],'$','')
f05f0d0ee296 fix false positives
Henry S. Thompson <ht@markup.co.uk>
parents: 18
diff changeset
30 else ()"/>
23
bfa38afaea63 change to default ns
Henry S. Thompson <ht@markup.co.uk>
parents: 22
diff changeset
31 <!-- Note that we don't bother to treat external ranges as ranges,
bfa38afaea63 change to default ns
Henry S. Thompson <ht@markup.co.uk>
parents: 22
diff changeset
32 since we're not going to try to detect cross-document refs -->
21
f05f0d0ee296 fix false positives
Henry S. Thompson <ht@markup.co.uk>
parents: 18
diff changeset
33 <xsl:variable name="ranges" select="for $i in (1 to count($tokens))
f05f0d0ee296 fix false positives
Henry S. Thompson <ht@markup.co.uk>
parents: 18
diff changeset
34 return if ($tokens[$i][@nr=10 and .=':' and
f05f0d0ee296 fix false positives
Henry S. Thompson <ht@markup.co.uk>
parents: 18
diff changeset
35 not($i gt 2 and
f05f0d0ee296 fix false positives
Henry S. Thompson <ht@markup.co.uk>
parents: 18
diff changeset
36 $tokens[$i - 2][@nr=10 and .='!'])])
f05f0d0ee296 fix false positives
Henry S. Thompson <ht@markup.co.uk>
parents: 18
diff changeset
37 then translate(concat($tokens[$i - 1],':',$tokens[$i + 1]),'$','')
f05f0d0ee296 fix false positives
Henry S. Thompson <ht@markup.co.uk>
parents: 18
diff changeset
38 else ()"/>
f05f0d0ee296 fix false positives
Henry S. Thompson <ht@markup.co.uk>
parents: 18
diff changeset
39 <xsl:variable name="externals" select="for $i in (1 to count($tokens))
f05f0d0ee296 fix false positives
Henry S. Thompson <ht@markup.co.uk>
parents: 18
diff changeset
40 return if ($tokens[$i][@nr=7])
f05f0d0ee296 fix false positives
Henry S. Thompson <ht@markup.co.uk>
parents: 18
diff changeset
41 then
f05f0d0ee296 fix false positives
Henry S. Thompson <ht@markup.co.uk>
parents: 18
diff changeset
42 let $bit := concat($tokens[$i],'!',
f05f0d0ee296 fix false positives
Henry S. Thompson <ht@markup.co.uk>
parents: 18
diff changeset
43 translate($tokens[$i + 2],'$',''))
23
bfa38afaea63 change to default ns
Henry S. Thompson <ht@markup.co.uk>
parents: 22
diff changeset
44 return if ((($i+3) le $n) and
bfa38afaea63 change to default ns
Henry S. Thompson <ht@markup.co.uk>
parents: 22
diff changeset
45 $tokens[$i + 3][@nr=10 and .=':'])
21
f05f0d0ee296 fix false positives
Henry S. Thompson <ht@markup.co.uk>
parents: 18
diff changeset
46 then concat($bit,':',translate($tokens[$i + 4],'$',''))
f05f0d0ee296 fix false positives
Henry S. Thompson <ht@markup.co.uk>
parents: 18
diff changeset
47 else $bit
f05f0d0ee296 fix false positives
Henry S. Thompson <ht@markup.co.uk>
parents: 18
diff changeset
48 else ()"/>
23
bfa38afaea63 change to default ns
Henry S. Thompson <ht@markup.co.uk>
parents: 22
diff changeset
49 <ref c="{@r}">
25
a5125a2e77ea towards inverted map of refs
Henry S. Thompson <ht@markup.co.uk>
parents: 24
diff changeset
50 <xsl:for-each select="distinct-values($singles)">
24
87e0d620deea switch to elements from attributes and default namespace
Henry S. Thompson <ht@markup.co.uk>
parents: 23
diff changeset
51 <s><xsl:value-of select="."/></s>
87e0d620deea switch to elements from attributes and default namespace
Henry S. Thompson <ht@markup.co.uk>
parents: 23
diff changeset
52 </xsl:for-each>
25
a5125a2e77ea towards inverted map of refs
Henry S. Thompson <ht@markup.co.uk>
parents: 24
diff changeset
53 <xsl:for-each select="distinct-values($ranges)">
24
87e0d620deea switch to elements from attributes and default namespace
Henry S. Thompson <ht@markup.co.uk>
parents: 23
diff changeset
54 <r><xsl:value-of select="."/></r>
87e0d620deea switch to elements from attributes and default namespace
Henry S. Thompson <ht@markup.co.uk>
parents: 23
diff changeset
55 </xsl:for-each>
25
a5125a2e77ea towards inverted map of refs
Henry S. Thompson <ht@markup.co.uk>
parents: 24
diff changeset
56 <xsl:for-each select="distinct-values($externals)">
24
87e0d620deea switch to elements from attributes and default namespace
Henry S. Thompson <ht@markup.co.uk>
parents: 23
diff changeset
57 <e><xsl:value-of select="."/></e>
87e0d620deea switch to elements from attributes and default namespace
Henry S. Thompson <ht@markup.co.uk>
parents: 23
diff changeset
58 </xsl:for-each>
23
bfa38afaea63 change to default ns
Henry S. Thompson <ht@markup.co.uk>
parents: 22
diff changeset
59 </ref></xsl:if>
17
a874f2a81ed2 default vis pipeline to raw xml, start extracting refs
Henry S. Thompson <ht@markup.co.uk>
parents:
diff changeset
60 </xsl:template>
18
16bba7a0d0bd one form of refs output, not sure it's what is wanted...
Henry S. Thompson <ht@markup.co.uk>
parents: 17
diff changeset
61
16bba7a0d0bd one form of refs output, not sure it's what is wanted...
Henry S. Thompson <ht@markup.co.uk>
parents: 17
diff changeset
62 <xsl:template match="s:c"/>
17
a874f2a81ed2 default vis pipeline to raw xml, start extracting refs
Henry S. Thompson <ht@markup.co.uk>
parents:
diff changeset
63 </xsl:stylesheet>