changeset 33:27bffc66ce10

external vars preserved, [0]!... == internal handled, but note that children of ref may not be contiguous by name anymore
author Henry S. Thompson <ht@markup.co.uk>
date Wed, 12 Apr 2017 17:43:54 +0100
parents f4432c1faf7f
children 93fd0d532754
files refs.xsl
diffstat 1 files changed, 27 insertions(+), 12 deletions(-) [+]
line wrap: on
line diff
--- a/refs.xsl	Wed Apr 12 14:33:47 2017 +0100
+++ b/refs.xsl	Wed Apr 12 17:43:54 2017 +0100
@@ -49,7 +49,7 @@
                                 not($l[@nr=10 and
                                        .=(':','!')]) and
                                 not($r[@nr=10 and .=':']))
-                             then e:single($t)
+                             then e:single($t,false())
                              else (),
                   $ranges := for $i in (1 to count($tokens)) return
                             let $t := $tokens[$i] return
@@ -58,19 +58,25 @@
                                        $tokens[$i - 2][@nr=10 and .='!'])])
                              then let $l := $tokens[$i - 1],
                                       $r := $tokens[$i + 1]
-                                      return e:range(e:single($l),
-                                                     e:single($r))
+                                      return e:range(e:single($l,false()),
+                                                     e:single($r,false()))
                              else (),
                   $externals := for $i in (1 to count($tokens)) return
                             let $t := $tokens[$i] return
                             if ($t/@nr=7)
                              then 
-                              let $ref := e:single($tokens[$i + 2]) return
-                               if ((($i+3) le $n) and
-                                   $tokens[$i + 3][@nr=10 and .=':'])
-                                then e:external($t,e:range($ref,
-                                                       e:single($tokens[$i+4])))
-                                else e:external($t,$ref)
+                              let $ext := $t!='[0]',
+                                  $ref := e:single($tokens[$i + 2],
+                                                   $ext),
+                                  $res := if ((($i+3) le $n) and
+                                              $tokens[$i + 3][@nr=10 and .=':'])
+                                           then e:range($ref,
+                                                        e:single($tokens[$i+4],
+                                                                 $ext))
+                                           else $ref return
+                              if ($ext)
+                               then e:external($t,$res)
+                               else $res
                              else ()
                   return [($singles,for $a in $recur return $a?1),
                           ($ranges,for $a in $recur return $a?2),
@@ -78,11 +84,20 @@
              else ()"/>
  </xsl:function>
  
- <xsl:function name="e:single" as="element(e:s)">
-  <xsl:param name="group" as="element(xf:group)" required="yes"/>
+ <xsl:function name="e:single" as="element(*)">
+  <xsl:param name="group" as="element(xf:group)"/>
+  <xsl:param name="external" as="xs:boolean"/>
   <xsl:variable name="val" select="if ($group/@nr=9) then e:lookup($group)
                                              else string($group)"/>
-  <s><xsl:value-of select="$val"/></s>
+  <xsl:choose>
+   <xsl:when test="count($val)>0 or not($external)">
+    <s><xsl:value-of select="$val"/></s>
+   </xsl:when>
+   <xsl:otherwise>
+    <v><xsl:value-of select="$group"/></v>
+   </xsl:otherwise>
+  </xsl:choose>
+  
  </xsl:function>
  
  <xsl:function name="e:range" as="element(e:r)">