changeset 24:87e0d620deea

switch to elements from attributes and default namespace
author Henry S. Thompson <ht@markup.co.uk>
date Thu, 06 Apr 2017 17:24:30 +0100
parents bfa38afaea63
children a5125a2e77ea
files notes.txt rect.xsl refs.xsl
diffstat 3 files changed, 23 insertions(+), 19 deletions(-) [+]
line wrap: on
line diff
--- a/notes.txt	Thu Apr 06 16:47:53 2017 +0100
+++ b/notes.txt	Thu Apr 06 17:24:30 2017 +0100
@@ -46,7 +46,7 @@
 there was content before.
 -----------
 Using attributes to hold space-separated lists is risky, as in
-refs.xsl output, is risky!
+refs.xsl output, is risky!  Fixed, see below.
 -----------
 Not handling variables as references.  Not catching external
 references to variables.  Not catching naked [n]! as external
@@ -55,7 +55,8 @@
  The definition table is in workbook.xml definedNames/definedName[@name=$name]/.
   Sheet name to filename mapping for locals is in workbook.xml sheets/sheet[@name=$sname]/@sheetId
 -----------
-Switch to default namespace in order to reduce size and improve readability
+Switch to default namespace in order to reduce size and improve
+readability, and to elements instead of attributes
 -----------
 Should put another step after refs.xsl to compute a map from
 distinct-values of all targets to all the cells which use them
--- a/rect.xsl	Thu Apr 06 16:47:53 2017 +0100
+++ b/rect.xsl	Thu Apr 06 17:24:30 2017 +0100
@@ -1,11 +1,11 @@
 <?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" xmlns="http://schemas.openxmlformats.org/spreadsheetml/2006/main" xmlns:xpf="http://www.w3.org/2005/xpath-functions">
+<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" xmlns="http://markup.co.uk/excel" xmlns:xpf="http://www.w3.org/2005/xpath-functions">
  <xsl:strip-space elements="s:sheetData"/>
  
  <xsl:variable name="refs" select="collection()[2]/*"/>
  
- <xsl:key name="ref" match="e:ref" use="tokenize(@r)"/>
+ <xsl:key name="ref" match="e:ref" use="e:s"/>
  
  <xsl:function name="e:a2n" as="xs:integer">
   <!-- Convert an alphabetic excel column 'index' into a number,
@@ -45,10 +45,10 @@
    <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="."/>
-   <e:a>
+   <a>
     <xsl:text>&#10;</xsl:text>
     <xsl:for-each select="(1 to $height)"><xsl:variable name="row" select="."/>
-     <e:r r="{$row}">
+     <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)">
@@ -56,15 +56,15 @@
        <xsl:variable name="r" select="concat(e:n2a($col),string($row))"/>
        <xsl:variable name="c" select="$cells[@r=$r]"/>
         <xsl:variable name="reffed" select="key('ref',$r,$refs)"/>
-       <e:c c="{$col}">
+       <c c="{$col}">
         <xsl:if test="$c/s:f"><xsl:attribute name="f">1</xsl:attribute></xsl:if>
-        <xsl:if test="$reffed"><xsl:attribute name="r"><xsl:value-of select="$reffed/@c"/></xsl:attribute></xsl:if>
-        <xsl:if test="$c/*"><xsl:value-of select="substring($c/@e:type,1,1)"/></xsl:if>
-       </e:c>
+        <xsl:if test="$c/*"><t><xsl:value-of select="substring($c/@e:type,1,1)"/></t></xsl:if>
+        <xsl:if test="$reffed"><xsl:for-each select="$reffed/@c"><r><xsl:value-of select="."/></r></xsl:for-each></xsl:if>
+       </c>
       </xsl:for-each></xsl:if>
-     </e:r>
+     </r>
      <xsl:text>&#10;</xsl:text></xsl:for-each>
-   </e:a>
+   </a>
   </xsl:if>
  </xsl:template>
 </xsl:stylesheet>
--- a/refs.xsl	Thu Apr 06 16:47:53 2017 +0100
+++ b/refs.xsl	Thu Apr 06 17:24:30 2017 +0100
@@ -10,7 +10,7 @@
  
  <xsl:template match="s:c[s:f]">
   <xsl:variable name="tokens" select="analyze-string(s:f/.,$pat)/xf:match/xf:group"/>
-  <xsl:if test="@r='B4'"><xsl:message><xsl:value-of select="$tokens/@nr"/></xsl:message>
+  <xsl:if test="@r='xxx'"><xsl:message><xsl:value-of select="$tokens/@nr"/></xsl:message>
 <xsl:message><xsl:value-of select="$tokens/."/></xsl:message>
   </xsl:if>
   <xsl:if test="$tokens[@nr=(7,8,9)]">
@@ -41,12 +41,15 @@
                 else $bit
             else ()"/>
    <ref c="{@r}">
-    <!-- Assumes that space doesn't occur in variable names
-         Might occur in external names (who knows!) but I'm assuming we're
-           never going to split the value of @er back out... -->
-    <xsl:if test="count($singles)>0"><xsl:attribute name="r"><xsl:value-of select="distinct-values($singles)"/></xsl:attribute></xsl:if>
-    <xsl:if test="count($ranges)>0"><xsl:attribute name="rr"><xsl:value-of select="distinct-values($ranges)"/></xsl:attribute></xsl:if>
-    <xsl:if test="count($externals)>0"><xsl:attribute name="er"><xsl:value-of select="distinct-values($externals)"/></xsl:attribute></xsl:if>
+    <xsl:for-each select="$singles">
+     <s><xsl:value-of select="."/></s>
+    </xsl:for-each>
+    <xsl:for-each select="$ranges">
+     <r><xsl:value-of select="."/></r>
+    </xsl:for-each>
+    <xsl:for-each select="$externals">
+     <e><xsl:value-of select="."/></e>
+    </xsl:for-each>
    </ref></xsl:if>
  </xsl:template>