Delete trailing whitespace at line endings.
[pspp] / doc / dev / spv-file-format.texi
1 @c PSPP - a program for statistical analysis.
2 @c Copyright (C) 2019 Free Software Foundation, Inc.
3 @c Permission is granted to copy, distribute and/or modify this document
4 @c under the terms of the GNU Free Documentation License, Version 1.3
5 @c or any later version published by the Free Software Foundation;
6 @c with no Invariant Sections, no Front-Cover Texts, and no Back-Cover Texts.
7 @c A copy of the license is included in the section entitled "GNU
8 @c Free Documentation License".
9 @c
10
11 @node SPSS Viewer File Format
12 @appendix SPSS Viewer File Format
13
14 SPSS Viewer or @file{.spv} files, here called SPV files, are written
15 by SPSS 16 and later to represent the contents of its output editor.
16 This chapter documents the format, based on examination of a corpus of
17 about 3,000 files from a variety of sources.  This description is
18 detailed enough to both read and write SPV files.
19
20 SPSS 15 and earlier versions instead use @file{.spo} files, which have
21 a completely different output format based on the Microsoft Compound
22 Document Format.  This format is not documented here.
23
24 An SPV file is a Zip archive that can be read with @command{zipinfo}
25 and @command{unzip} and similar programs.  The final member in the Zip
26 archive is the @dfn{manifest}, a file named
27 @file{META-INF/MANIFEST.MF}.  This structure makes SPV files resemble
28 Java ``JAR'' files (and ODF files), but whereas a JAR manifest
29 contains a sequence of colon-delimited key/value pairs, an SPV
30 manifest contains the string @samp{allowPivoting=true}, without a
31 new-line.  PSPP uses this string to identify an SPV file; it is
32 invariant across the corpus.
33
34 The rest of the members in an SPV file's Zip archive fall into two
35 categories: @dfn{structure} and @dfn{detail} members.  Structure
36 member names begin with @file{outputViewer@var{nnnnnnnnnn}}, where
37 each @var{n} is a decimal digit, and end with @file{.xml}, and often
38 include the string @file{_heading} in between.  Each of these members
39 represents some kind of output item (a table, a heading, a block of
40 text, etc.) or a group of them.  The member whose output goes at the
41 beginning of the document is numbered 0, the next member in the output
42 is numbered 1, and so on.
43
44 Structure members contain XML.  This XML is sometimes self-contained,
45 but it often references detail members in the Zip archive, which are
46 named as follows:
47
48 @table @asis
49 @item @file{@var{prefix}_table.xml} and @file{@var{prefix}_tableData.bin}
50 @itemx @file{@var{prefix}_lightTableData.bin}
51 The structure of a table plus its data.  Older SPV files pair a
52 @file{@var{prefix}_table.xml} file that describes the table's
53 structure with a binary @file{@var{prefix}_tableData.bin} file that
54 gives its data.  Newer SPV files (the majority of those in the corpus)
55 instead include a single @file{@var{prefix}_lightTableData.bin} file
56 that incorporates both into a single binary format.
57
58 @item @file{@var{prefix}_warning.xml} and @file{@var{prefix}_warningData.bin}
59 @itemx @file{@var{prefix}_lightWarningData.bin}
60 Same format used for tables, with a different name.
61
62 @item @file{@var{prefix}_notes.xml} and @file{@var{prefix}_notesData.bin}
63 @itemx @file{@var{prefix}_lightNotesData.bin}
64 Same format used for tables, with a different name.
65
66 @item @file{@var{prefix}_chartData.bin} and @file{@var{prefix}_chart.xml}
67 The structure of a chart plus its data.  Charts do not have a
68 ``light'' format.
69
70 @item @file{@var{prefix}_pmml.scf}
71 @itemx @file{@var{prefix}_stats.scf}
72 @item @file{@var{prefix}_model.xml}
73 Not yet investigated.  The corpus contains few examples.
74 @end table
75
76 The @file{@var{prefix}} in the names of the detail members is
77 typically an 11-digit decimal number that increases for each item,
78 tending to skip values.  Older SPV files use different naming
79 conventions.  Structure member refer to detail members by name, and so
80 their exact names do not matter to readers as long as they are unique.
81
82 SPSS tolerates corrupted Zip archives that Zip reader libraries tend
83 to reject.  These can be fixed up with @command{zip -FF}.
84
85 @menu
86 * SPV Structure Member Format::
87 * SPV Light Detail Member Format::
88 * SPV Legacy Detail Member Binary Format::
89 * SPV Legacy Detail Member XML Format::
90 @end menu
91
92 @node SPV Structure Member Format
93 @section Structure Member Format
94
95 A structure member lays out the high-level structure for a group of
96 output items such as heading, tables, and charts.  Structure members
97 do not include the details of tables and charts but instead refer to
98 them by their member names.
99
100 Structure members' XML files claim conformance with a collection of
101 XML Schemas.  These schemas are distributed, under a nonfree license,
102 with SPSS binaries.  Fortunately, the schemas are not necessary to
103 understand the structure members.  The schemas can even
104 be deceptive because they document elements and attributes that are
105 not in the corpus and do not document elements and attributes that are
106 commonly found in the corpus.
107
108 Structure members use a different XML namespace for each schema, but
109 these namespaces are not entirely consistent.  In some SPV files, for
110 example, the @code{viewer-tree} schema is associated with namespace
111 @indicateurl{http://xml.spss.com/spss/viewer-tree} and in others with
112 @indicateurl{http://xml.spss.com/spss/viewer/viewer-tree} (note the
113 additional @file{viewer/}).  Under either name, the schema URIs are
114 not resolvable to obtain the schemas themselves.
115
116 One may ignore all of the above in interpreting a structure member.
117 The actual XML has a simple and straightforward form that does not
118 require a reader to take schemas or namespaces into account.  A
119 structure member's root is @code{heading} element, which contains
120 @code{heading} or @code{container} elements (or a mix), forming a
121 tree.  In turn, @code{container} holds a @code{label} and one more
122 child, usually @code{text} or @code{table}.
123
124 The following sections document the elements found in structure
125 members in a context-free grammar-like fashion.  Consider the
126 following example, which specifies the attributes and content for the
127 @code{container} element:
128
129 @example
130 container
131    :visibility=(visible | hidden)
132    :page-break-before=(always)?
133    :text-align=(left | center)?
134    :width=dimension
135 => label (table | container_text | graph | model | object | image)
136 @end example
137
138 Each attribute specification begins with @samp{:} followed by the
139 attribute's name.  If the attribute's value has an easily specified
140 form, then @samp{=} and its description follows the name.  Finally, if
141 the attribute is optional, the specification ends with @samp{?}.  The
142 following value specifications are defined:
143
144 @table @code
145 @item (@var{a} | @var{b} | @dots{})
146 One of the listed literal strings.  If only one string is listed, it
147 is the only acceptable value.  If @code{OTHER} is listed, then any
148 string not explicitly listed is also accepted.
149
150 @item bool
151 Either @code{true} or @code{false}.
152
153 @item dimension
154 A floating-point number followed by a unit, e.g.@: @code{10pt}.  Units
155 in the corpus include @code{in} (inch), @code{pt} (points, 72/inch),
156 @code{px} (``device-independent pixels'', 96/inch), and @code{cm}.
157 The corpus also contains localized names for units: @code{인치} for
158 inch, @code{пт} for points, and @code{см} for centimeters.  If the
159 unit is omitted then points should be assumed.  The number and unit
160 may be separated by white space.
161
162 @item real
163 A floating-point number.
164
165 @item int
166 An integer.
167
168 @item color
169 A color in one of the forms @code{#@var{rr}@var{gg}@var{bb}} or
170 @code{@var{rr}@var{gg}@var{bb}}, or the string @code{transparent}, or
171 one of the standard Web color names.
172
173 @item ref
174 @item ref @var{element}
175 @itemx ref(@var{elem1} | @var{elem2} | @dots{})
176 The name from the @code{id} attribute in some element.  If one or more
177 elements are named, the name must refer to one of those elements,
178 otherwise any element is acceptable.
179 @end table
180
181 All elements have an optional @code{id} attribute.  If present, its
182 value must be unique.  In practice many elements are assigned
183 @code{id} attributes that are never referenced.
184
185 The content specification for an element supports the following
186 syntax:
187
188 @table @code
189 @item @var{element}
190 An element.
191
192 @item @var{a} @var{b}
193 @var{a} followed by @var{b}.
194
195 @item @var{a} | @var{b} | @var{c}
196 One of @var{a} or @var{b} or @var{c}.
197
198 @item @var{a}?
199 Zero or one instances of @var{a}.
200
201 @item @var{a}*
202 Zero or more instances of @var{a}.
203
204 @item @var{b}+
205 One or more instances of @var{a}.
206
207 @item (@var{subexpression})
208 Grouping for a subexpression.
209
210 @item EMPTY
211 No content.
212
213 @item TEXT
214 Text and CDATA.
215 @end table
216
217 Element and attribute names are sometimes suffixed by another name in
218 square brackets to distinguish different uses of the same name.  For
219 example, structure XML has two @code{text} elements, one inside
220 @code{container}, the other inside @code{pageParagraph}.  The former
221 is defined as @code{text[container_text]} and referenced as
222 @code{container_text}, the latter defined as
223 @code{text[pageParagraph_text]} and referenced as
224 @code{pageParagraph_text}.
225
226 This language is used in the PSPP source code for parsing structure
227 and detail XML members.  Refer to
228 @file{src/output/spv/structure-xml.grammar} and
229 @file{src/output/spv/detail-xml.grammar} for the full grammars.
230
231 The following example shows the contents of a typical structure member
232 for a @cmd{DESCRIPTIVES} procedure.  A real structure member is not
233 indented.  This example also omits most attributes, all XML namespace
234 information, and the CSS from the embedded HTML:
235
236 @example
237 <?xml version="1.0" encoding="utf-8"?>
238 <heading>
239   <label>Output</label>
240   <heading commandName="Descriptives">
241     <label>Descriptives</label>
242     <container>
243       <label>Title</label>
244       <text commandName="Descriptives" type="title">
245         <html lang="en">
246 <![CDATA[<head><style type="text/css">...</style></head><BR>Descriptives]]>
247         </html>
248       </text>
249     </container>
250     <container visibility="hidden">
251       <label>Notes</label>
252       <table commandName="Descriptives" subType="Notes" type="note">
253         <tableStructure>
254           <dataPath>00000000001_lightNotesData.bin</dataPath>
255         </tableStructure>
256       </table>
257     </container>
258     <container>
259       <label>Descriptive Statistics</label>
260       <table commandName="Descriptives" subType="Descriptive Statistics"
261              type="table">
262         <tableStructure>
263           <dataPath>00000000002_lightTableData.bin</dataPath>
264         </tableStructure>
265       </table>
266     </container>
267   </heading>
268 </heading>
269 @end example
270
271 @menu
272 * SPV Structure heading Element::
273 * SPV Structure label Element::
274 * SPV Structure container Element::
275 * SPV Structure text Element (Inside @code{container})::
276 * SPV Structure html Element::
277 * SPV Structure table Element::
278 * SPV Structure graph Element::
279 * SPV Structure model Element::
280 * SPV Structure dataPath and path Elements::
281 * SPV Structure pageSetup Element::
282 * SPV Structure @code{text} Element (Inside @code{pageParagraph})::
283 @end menu
284
285 @node SPV Structure heading Element
286 @subsection The @code{heading} Element
287
288 @example
289 heading[root_heading]
290    :creator-version?
291    :creator?
292    :creation-date-time?
293    :lockReader=bool?
294    :schemaLocation?
295 => label pageSetup? (container | heading)*
296
297 heading
298    :creator-version?
299    :commandName?
300    :visibility[heading_visibility]=(collapsed)?
301    :locale?
302    :olang?
303 => label (container | heading)*
304 @end example
305
306 The root of a structure member is a @code{heading}, which represents a
307 section of output beginning with a title (the @code{label}) and
308 ordinarily followed by content containers or further nested
309 (sub)-sections of output.  Unlike heading elements in HTML and other
310 common document formats, which precede the content that they head,
311 @code{heading} contains the elements that appear below the heading.
312
313 The document root heading, only, may contain a @code{pageSetup}
314 element.
315
316 The following attributes have been observed on both document root and
317 nested @code{heading} elements.
318
319 @defvr {Attribute} creator-version
320 The version of the software that created this SPV file.  A string of
321 the form @code{xxyyzzww} represents software version xx.yy.zz.ww,
322 e.g.@: @code{21000001} is version 21.0.0.1.  Trailing pairs of zeros
323 are sometimes omitted, so that @code{21}, @code{210000}, and
324 @code{21000000} are all version 21.0.0.0 (and the corpus contains all
325 three of those forms).
326 @end defvr
327
328 @noindent
329 The following attributes have been observed on document root
330 @code{heading} elements only:
331
332 @defvr {Attribute} @code{creator}
333 The directory in the file system of the software that created this SPV
334 file.
335 @end defvr
336
337 @defvr {Attribute} @code{creation-date-time}
338 The date and time at which the SPV file was written, in a
339 locale-specific format, e.g.@: @code{Friday, May 16, 2014 6:47:37 PM
340 PDT} or @code{lunedì 17 marzo 2014 3.15.48 CET} or even @code{Friday,
341 December 5, 2014 5:00:19 o'clock PM EST}.
342 @end defvr
343
344 @defvr {Attribute} @code{lockReader}
345 Whether a reader should be allowed to edit the output.  The possible
346 values are @code{true} and @code{false}, but the corpus only contains
347 @code{false}.
348 @end defvr
349
350 @defvr {Attribute} @code{schemaLocation}
351 This is actually an XML Namespace attribute.  A reader may ignore it.
352 @end defvr
353
354 @noindent
355 The following attributes have been observed only on nested
356 @code{heading} elements:
357
358 @defvr {Attribute} @code{commandName}
359 A locale-invariant identifier for the command that produced the
360 output, e.g.@: @code{Frequencies}, @code{T-Test}, @code{Non Par Corr}.
361 @end defvr
362
363 @defvr {Attribute} @code{visibility}
364 To what degree the output represented by the element is visible.
365 @end defvr
366
367 @defvr {Attribute} @code{locale}
368 The locale used for output, in Windows format, which is similar to the
369 format used in Unix with the underscore replaced by a hyphen, e.g.@:
370 @code{en-US}, @code{en-GB}, @code{el-GR}, @code{sr-Cryl-RS}.
371 @end defvr
372
373 @defvr {Attribute} @code{olang}
374 The output language, e.g.@: @code{en}, @code{it}, @code{es},
375 @code{de}, @code{pt-BR}.
376 @end defvr
377
378 @node SPV Structure label Element
379 @subsection The @code{label} Element
380
381 @example
382 label => TEXT
383 @end example
384
385 Every @code{heading} and @code{container} holds a @code{label} as its
386 first child.  The root @code{heading} in a structure member always
387 contains the string ``Output'' (localized).  Otherwise, the text in
388 @code{label} describes what it labels, often by naming the statistical
389 procedure that was executed, e.g.@: ``Frequencies'' or ``T-Test''.
390 Labels are often very generic, especially within a @code{container},
391 e.g.@: ``Title'' or ``Warnings'' or ``Notes''.  Label text is
392 localized according to the output language, e.g.@: in Italian a
393 frequency table procedure is labeled ``Frequenze''.
394
395 The corpus contains a few examples of empty labels, ones that contain
396 no text.
397
398 @node SPV Structure container Element
399 @subsection The @code{container} Element
400
401 @example
402 container
403    :visibility=(visible | hidden)
404    :page-break-before=(always)?
405    :text-align=(left | center)?
406    :width=dimension
407 => label (table | container_text | graph | model | object | image)
408 @end example
409
410 A @code{container} serves to contain and label a @code{table},
411 @code{text}, or other kind of item.
412
413 This element has the following attributes.
414
415 @defvr {Attribute} @code{visibility}
416 Whether the container's content is displayed.  ``Notes'' tables are
417 often hidden; other data is usually
418 @end defvr
419
420 @defvr {Attribute} @code{text-align}
421 Alignment of text within the container.  Observed with nested
422 @code{table} and @code{text} elements.
423 @end defvr
424
425 @defvr {Attribute} @code{width}
426 The width of the container, e.g.@: @code{1097px}.
427 @end defvr
428
429 @node SPV Structure text Element (Inside @code{container})
430 @subsection The @code{text} Element (Inside @code{container})
431
432 @example
433 text[container_text]
434   :type[text_type]=(title | log | text | page-title)
435   :commandName?
436   :creator-version?
437 => html
438 @end example
439
440 This @code{text} element is nested inside a @code{container}.  There
441 is a different @code{text} element that is nested inside a
442 @code{pageParagraph}.
443
444 This element has the following attributes.
445
446 @defvr {Attribute} @code{type}
447 The semantics of the text.
448 @end defvr
449
450 @defvr {Attribute} @code{commandName}
451 As on the @code{heading} element.  For output not specific to a
452 command, this is simply @code{log}.  The corpus contains one example
453 of where @code{commandName} is present but set to the empty string.
454 @end defvr
455
456 @defvr {Attribute} @code{creator-version}
457 As on the @code{heading} element.
458 @end defvr
459
460 @node SPV Structure html Element
461 @subsection The @code{html} Element
462
463 @example
464 html :lang=(en) => TEXT
465 @end example
466
467 The element contains an HTML document as text (or, in practice, as
468 CDATA).  In some cases, the document starts with @code{<html>} and
469 ends with @code{</html>}; in others the @code{html} element is
470 implied.  Generally the HTML includes a @code{head} element with a CSS
471 stylesheet.  The HTML body often begins with @code{<BR>}.
472
473 The HTML document uses only the following elements:
474
475 @table @code
476 @item html
477 Sometimes, the document is enclosed with
478 @code{<html>}@dots{}@code{</html>}.
479
480 @item br
481 The HTML body often begins with @code{<BR>} and may contain it as well.
482
483 @item b
484 @itemx i
485 @itemx u
486 Styling.
487
488 @item font
489 The attributes @code{face}, @code{color}, and @code{size} are
490 observed.  The value of @code{color} takes one of the forms
491 @code{#@var{rr}@var{gg}@var{bb}} or @code{rgb (@var{r}, @var{g},
492 @var{b})}.  The value of @code{size} is a number between 1 and 7,
493 inclusive.
494 @end table
495
496 The CSS in the corpus is simple.  To understand it, a parser only
497 needs to be able to skip white space, @code{<!--}, and @code{-->}, and
498 parse style only for @code{p} elements.  Only @code{font-weight},
499 @code{font-style}, @code{font-decoration}, @code{font-family}, and
500 @code{font-size} matter.
501
502 This element has the following attributes.
503
504 @defvr {Attribute} @code{lang}
505 This always contains @code{en} in the corpus.
506 @end defvr
507
508 @node SPV Structure table Element
509 @subsection The @code{table} Element
510
511 @example
512 table
513    :VDPId?
514    :ViZmlSource?
515    :activePageId=int?
516    :commandName
517    :creator-version?
518    :displayFiltering=bool?
519    :maxNumCells=int?
520    :orphanTolerance=int?
521    :rowBreakNumber=int?
522    :subType
523    :tableId
524    :tableLookId?
525    :type[table_type]=(table | note | warning)
526 => tableProperties? tableStructure
527
528 tableStructure => path? dataPath
529 @end example
530
531 This element has the following attributes.
532
533 @defvr {Attribute} @code{commandName}
534 As on the @code{heading} element.
535 @end defvr
536
537 @defvr {Attribute} @code{type}
538 One of @code{table}, @code{note}, or @code{warning}.
539 @end defvr
540
541 @defvr {Attribute} @code{subType}
542 The locale-invariant command ID for the particular kind of output that
543 this table represents in the procedure.  This can be the same as
544 @code{commandName} e.g.@: @code{Frequencies}, or different, e.g.@:
545 @code{Case Processing Summary}.  Generic subtypes @code{Notes} and
546 @code{Warnings} are often used.
547 @end defvr
548
549 @defvr {Attribute} @code{tableId}
550 A number that uniquely identifies the table within the SPV file,
551 typically a large negative number such as @code{-4147135649387905023}.
552 @end defvr
553
554 @defvr {Attribute} @code{creator-version}
555 As on the @code{heading} element.  In the corpus, this is only present
556 for version 21 and up and always includes all 8 digits.
557 @end defvr
558
559 @xref{SPV Detail Legacy Properties}, for details on the
560 @code{tableProperties} element.
561
562 @node SPV Structure graph Element
563 @subsection The @code{graph} Element
564
565 @example
566 graph
567    :VDPId?
568    :ViZmlSource?
569    :commandName?
570    :creator-version?
571    :dataMapId?
572    :dataMapURI?
573    :editor?
574    :refMapId?
575    :refMapURI?
576 => dataPath? path
577 @end example
578
579 This element represents a graph.  The @code{dataPath} and @code{path}
580 elements name the Zip members that give the details of the graph.
581 Normally, both elements are present; there is only one counterexample
582 in the corpus.
583
584 @node SPV Structure model Element
585 @subsection The @code{model} Element
586
587 @example
588 model
589    :PMMLContainerId
590    :PMMLId
591    :StatXMLContainerId
592    :VDPId
593    :auxiliaryViewName
594    :commandName
595    :creator-version
596    :mainViewName
597 => ViZml? path | pmmlContainerPath statsContainerPath
598
599 pmmlContainerPath => TEXT
600
601 statsContainerPath => TEXT
602
603 ViZml :viewName? => TEXT
604 @end example
605
606 This element represents a model.  The @code{dataPath} and @code{path}
607 elements name the Zip members that give the details of the model.
608 Normally, both elements are present; there is only one counterexample
609 in the corpus.
610
611 The details are unexplored.  The @code{ViZml} element contains base-64
612 encoded text, that decodes to a binary format with some embedded text
613 strings, and @code{path} names an Zip member that contains XML.
614 Alternatively, @code{pmmlContainerPath} and @code{statsContainerPath}
615 name Zip members with @file{.scf} extension.
616
617 @node SPV Structure dataPath and path Elements
618 @subsection The @code{dataPath} and @code{path} Elements
619
620 @example
621 dataPath => TEXT
622
623 path => TEXT
624 @end example
625
626 These element contain the name of the Zip members that hold details
627 for a container.  For tables:
628
629 @itemize @bullet
630 @item
631 When a ``light'' format is used, only @code{dataPath} is present, and
632 it names a @file{.bin} member of the Zip file that has @code{light} in
633 its name, e.g.@: @code{0000000001437_lightTableData.bin} (@pxref{SPV
634 Light Detail Member Format}).
635
636 @item
637 When the legacy format is used, both are present.  In this case,
638 @code{dataPath} names a Zip member with a legacy binary format that
639 contains relevant data (@pxref{SPV Legacy Detail Member Binary
640 Format}), and @code{path} names a Zip member that uses an XML format
641 (@pxref{SPV Legacy Detail Member XML Format}).
642 @end itemize
643
644 Graphs normally follow the legacy approach described above.  The
645 corpus contains one example of a graph with @code{path} but not
646 @code{dataPath}.  The reason is unexplored.
647
648 Models use @code{path} but not @code{dataPath}.  @xref{SPV Structure
649 graph Element}, for more information.
650
651 These elements have no attributes.
652
653 @node SPV Structure pageSetup Element
654 @subsection The @code{pageSetup} Element
655
656 @example
657 pageSetup
658    :initial-page-number=int?
659    :chart-size=(as-is | full-height | half-height | quarter-height | OTHER)?
660    :margin-left=dimension?
661    :margin-right=dimension?
662    :margin-top=dimension?
663    :margin-bottom=dimension?
664    :paper-height=dimension?
665    :paper-width=dimension?
666    :reference-orientation?
667    :space-after=dimension?
668 => pageHeader pageFooter
669
670 pageHeader => pageParagraph?
671
672 pageFooter => pageParagraph?
673
674 pageParagraph => pageParagraph_text
675 @end example
676
677 The @code{pageSetup} element has the following attributes.
678
679 @defvr {Attribute} @code{initial-page-number}
680 The page number to put on the first page of printed output.  Usually
681 @code{1}.
682 @end defvr
683
684 @defvr {Attribute} @code{chart-size}
685 One of the listed, self-explanatory chart sizes,
686 @code{quarter-height}, or a localization (!) of one of these (e.g.@:
687 @code{dimensione attuale}, @code{Wie vorgegeben}).
688 @end defvr
689
690 @defvr {Attribute} @code{margin-left}
691 @defvrx {Attribute} @code{margin-right}
692 @defvrx {Attribute} @code{margin-top}
693 @defvrx {Attribute} @code{margin-bottom}
694 Margin sizes, e.g.@: @code{0.25in}.
695 @end defvr
696
697 @defvr {Attribute} @code{paper-height}
698 @defvrx {Attribute} @code{paper-width}
699 Paper sizes.
700 @end defvr
701
702 @defvr {Attribute} @code{reference-orientation}
703 Indicates the orientation of the output page.  Either @code{0deg}
704 (portrait) or @code{90deg} (landscape),
705 @end defvr
706
707 @defvr {Attribute} @code{space-after}
708 The amount of space between printed objects, typically @code{12pt}.
709 @end defvr
710
711 @node SPV Structure @code{text} Element (Inside @code{pageParagraph})
712 @subsection The @code{text} Element (Inside @code{pageParagraph})
713
714 @example
715 text[pageParagraph_text] :type=(title | text) => TEXT
716 @end example
717
718 This @code{text} element is nested inside a @code{pageParagraph}.  There
719 is a different @code{text} element that is nested inside a
720 @code{container}.
721
722 The element is either empty, or contains CDATA that holds almost-XHTML
723 text: in the corpus, either an @code{html} or @code{p} element.  It is
724 @emph{almost}-XHTML because the @code{html} element designates the
725 default namespace as
726 @indicateurl{http://xml.spss.com/spss/viewer/viewer-tree} instead of
727 an XHTML namespace, and because the CDATA can contain substitution
728 variables.  The following variables are supported:
729
730 @table @code
731 @item &[Date]
732 @itemx &[Time]
733 The current date or time in the preferred format for the locale.
734
735 @item &[Head1]
736 @itemx &[Head2]
737 @itemx &[Head3]
738 @itemx &[Head4]
739 First-, second-, third-, or fourth-level heading.
740
741 @item &[PageTitle]
742 The page title.
743
744 @item &[Filename]
745 Name of the output file.
746
747 @item &[Page]
748 The page number.
749 @end table
750
751 @code{&[Page]} for the page number and @code{&[PageTitle]} for the
752 page title.
753
754 Typical contents (indented for clarity):
755
756 @example
757 <html xmlns="http://xml.spss.com/spss/viewer/viewer-tree">
758     <head></head>
759     <body>
760         <p style="text-align:right; margin-top: 0">Page &[Page]</p>
761     </body>
762 </html>
763 @end example
764
765 This element has the following attributes.
766
767 @defvr {Attribute} @code{type}
768 Always @code{text}.
769 @end defvr
770
771 @node SPV Light Detail Member Format
772 @section Light Detail Member Format
773
774 This section describes the format of ``light'' detail @file{.bin}
775 members.  These members have a binary format which we describe here in
776 terms of a context-free grammar using the following conventions:
777
778 @table @asis
779 @item NonTerminal @result{} @dots{}
780 Nonterminals have CamelCaps names, and @result{} indicates a
781 production.  The right-hand side of a production is often broken
782 across multiple lines.  Break points are chosen for aesthetics only
783 and have no semantic significance.
784
785 @item 00, 01, @dots{}, ff.
786 A bytes with a fixed value, written as a pair of hexadecimal digits.
787
788 @item i0, i1, @dots{}, i9, i10, i11, @dots{}
789 @itemx ib0, ib1, @dots{}, ib9, ib10, ib11, @dots{}
790 A 32-bit integer in little-endian or big-endian byte order,
791 respectively, with a fixed value, written in decimal.  Prefixed by
792 @samp{i} for little-endian or @samp{ib} for big-endian.
793
794 @item byte
795 A byte.
796
797 @item bool
798 A byte with value 0 or 1.
799
800 @item int16
801 @itemx be16
802 A 16-bit integer in little-endian or big-endian byte order,
803 respectively.
804
805 @item int32
806 @itemx be32
807 A 32-bit integer in little-endian or big-endian byte order,
808 respectively.
809
810 @item int64
811 @itemx be64
812 A 64-bit integer in little-endian or big-endian byte order,
813 respectively.
814
815 @item double
816 A 64-bit IEEE floating-point number.
817
818 @item float
819 A 32-bit IEEE floating-point number.
820
821 @item string
822 @itemx bestring
823 A 32-bit integer, in little-endian or big-endian byte order,
824 respectively, followed by the specified number of bytes of character
825 data.  (The encoding is indicated by the Formats nonterminal.)
826
827 @item @var{x}?
828 @var{x} is optional, e.g.@: 00? is an optional zero byte.
829
830 @item @var{x}*@var{n}
831 @var{x} is repeated @var{n} times, e.g.@: byte*10 for ten arbitrary bytes.
832
833 @item @var{x}[@var{name}]
834 Gives @var{x} the specified @var{name}.  Names are used in textual
835 explanations.  They are also used, also bracketed, to indicate counts,
836 e.g.@: @code{int32[n] byte*[n]} for a 32-bit integer followed by the
837 specified number of arbitrary bytes.
838
839 @item @var{a} @math{|} @var{b}
840 Either @var{a} or @var{b}.
841
842 @item (@var{x})
843 Parentheses are used for grouping to make precedence clear, especially
844 in the presence of @math{|}, e.g.@: in 00 (01 @math{|} 02 @math{|} 03)
845 00.
846
847 @item count(@var{x})
848 @itemx becount(@var{x})
849 A 32-bit integer, in little-endian or big-endian byte order, respectively,
850 that indicates the number of bytes in @var{x}, followed by @var{x} itself.
851
852 @item v1(@var{x})
853 In a version 1 @file{.bin} member, @var{x}; in version 3, nothing.
854 (The @file{.bin} header indicates the version.)
855
856 @item v3(@var{x})
857 In a version 3 @file{.bin} member, @var{x}; in version 1, nothing.
858 @end table
859
860 PSPP uses this grammar to parse light detail members.  See
861 @file{src/output/spv/light-binary.grammar} in the PSPP source tree for
862 the full grammar.
863
864 Little-endian byte order is far more common in this format, but a few
865 pieces of the format use big-endian byte order.
866
867 Light detail members express linear units in two ways: points (pt), at
868 72/inch, and ``device-independent pixels'' (px), at 96/inch.  To
869 convert from pt to px, multiply by 1.33 and round up.  To convert
870 from px to pt, divide by 1.33 and round down.
871
872 A ``light'' detail member @file{.bin} consists of a number of sections
873 concatenated together, terminated by an optional byte 01:
874
875 @example
876 LightMember =>
877     Header Titles Footnotes
878     Areas Borders PrintSettings TableSettings Formats
879     Dimensions Axes Cells
880     01?
881 @end example
882
883 The following sections go into more detail.
884
885 @menu
886 * SPV Light Member Header::
887 * SPV Light Member Titles::
888 * SPV Light Member Footnotes::
889 * SPV Light Member Areas::
890 * SPV Light Member Borders::
891 * SPV Light Member Print Settings::
892 * SPV Light Member Table Settings::
893 * SPV Light Member Formats::
894 * SPV Light Member Dimensions::
895 * SPV Light Member Categories::
896 * SPV Light Member Axes::
897 * SPV Light Member Cells::
898 * SPV Light Member Value::
899 * SPV Light Member ValueMod::
900 @end menu
901
902 @node SPV Light Member Header
903 @subsection Header
904
905 An SPV light member begins with a 39-byte header:
906
907 @example
908 Header =>
909     01 00
910     (i1 @math{|} i3)[version]
911     bool[x0]
912     bool[x1]
913     bool[rotate-inner-column-labels]
914     bool[rotate-outer-row-labels]
915     bool[x2]
916     int32[x3]
917     int32[min-col-width] int32[max-col-width]
918     int32[min-row-width] int32[max-row-width]
919     int64[table-id]
920 @end example
921
922 @code{version} is a version number that affects the interpretation of
923 some of the other data in the member.  We will refer to ``version 1''
924 and ``version 3'' later on and use v1(@dots{}) and v3(@dots{}) for
925 version-specific formatting (as described previously).
926
927 If @code{rotate-inner-column-labels} is 1, then column labels closest
928 to the data are rotated to be vertical; otherwise, they are shown
929 in the normal way.
930
931 If @code{rotate-outer-row-labels} is 1, then row labels farthest from
932 the data are rotated to be vertical; otherwise, they are shown in the
933 normal way.
934
935 @code{table-id} is a binary version of the @code{tableId} attribute in
936 the structure member that refers to the detail member.  For example,
937 if @code{tableId} is @code{-4122591256483201023}, then @code{table-id}
938 would be 0xc6c99d183b300001.
939
940 @code{min-col-width} is the minimum width that a column will be
941 assigned automatically.  @code{max-col-width} is the maximum width
942 that a column will be assigned to accommodate a long column label.
943 @code{min-row-width} and @code{max-row-width} are a similar range for
944 the width of row labels.  All of these measurements are in 1/96 inch
945 units (called a ``device independent pixel'' unit in Windows).
946
947 The meaning of the other variable parts of the header is not known.  A
948 writer may safely use version 3, true for @code{x0}, false for
949 @code{x1}, true for @code{x2}, and 0x15 for @code{x3}.
950
951 @node SPV Light Member Titles
952 @subsection Titles
953
954 @example
955 Titles =>
956     Value[title] 01?
957     Value[subtype] 01? 31
958     Value[user-title] 01?
959     (31 Value[corner-text] @math{|} 58)
960     (31 Value[caption] @math{|} 58)
961 @end example
962
963 The Titles follow the Header and specify the table's title, caption,
964 and corner text.
965
966 The @code{user-title} is shown above the title and reflects any user
967 editing of the title text or style.  The @code{title} is the title
968 originally generated by the procedure.  Both of these are appropriate
969 for presentation and localized to the user's language.  For example,
970 for a frequency table, @code{title} and @code{user-title} normally
971 name the variable and @code{c} is simply ``Frequencies''.
972
973 @code{subtype} is the same as the @code{subType} attribute in the
974 @code{table} structure XML element that referred to this member.
975 @xref{SPV Structure table Element}, for details.
976
977 The @code{corner-text}, if present, is shown in the upper-left corner
978 of the table, above the row headings and to the left of the column
979 headings.  It is usually absent.  Corner text prevents row dimension
980 labels from being displayed above the dimension's group and category
981 labels (see @code{show-row-labels-in-corner}).
982
983 The @code{caption}, if present, is shown below the table.
984 @code{caption} reflects user editing of the caption.
985
986 @node SPV Light Member Footnotes
987 @subsection Footnotes
988
989 @example
990 Footnotes => int32[n-footnotes] Footnote*[n-footnotes]
991 Footnote => Value[text] (58 @math{|} 31 Value[marker]) byte*4
992 @end example
993
994 Each footnote has @code{text} and an optional custom @code{marker}
995 (such as @samp{*}).
996
997 @node SPV Light Member Areas
998 @subsection Areas
999
1000 @example
1001 Areas => 00? Area*8
1002 Area =>
1003     byte[index] 31
1004     string[typeface] float[size] int32[style] bool[underline]
1005     int32[halign] int32[valign]
1006     string[fg-color] string[bg-color]
1007     bool[alternate] string[alt-fg-color] string[alt-bg-color]
1008     v3(int32[left-margin] int32[right-margin] int32[top-margin] int32[bottom-margin])
1009 @end example
1010
1011 Each Area represents the style for a different area of the table, in
1012 the following order: title, caption, footer, corner, column labels,
1013 row labels, data, and layers.
1014
1015 @code{index} is the 1-based index of the Area, i.e. 1 for the first
1016 Area, through 8 for the final Area.
1017
1018 @code{typeface} is the string name of the font used in the area.  In
1019 the corpus, this is @code{SansSerif} in over 99% of instances and
1020 @code{Times New Roman} in the rest.
1021
1022 @code{size} is the size of the font, in px (@pxref{SPV Light Detail
1023 Member Format}) The most common size in the corpus is 12 px.  Even
1024 though @code{size} has a floating-point type, in the corpus its values
1025 are always integers.
1026
1027 @code{style} is a bit mask.  Bit 0 (with value 1) is set for bold, bit
1028 1 (with value 2) is set for italic.
1029
1030 @code{underline} is 1 if the font is underlined, 0 otherwise.
1031
1032 @code{halign} specifies horizontal alignment: 0 for center, 2 for
1033 left, 4 for right, 61453 for decimal, 64173 for mixed.  Mixed
1034 alignment varies according to type: string data is left-justified,
1035 numbers and most other formats are right-justified.
1036
1037 @code{valign} specifies vertical alignment: 0 for center, 1 for top, 3
1038 for bottom.
1039
1040 @code{fg-color} and @code{bg-color} are the foreground color and
1041 background color, respectively.  In the corpus, these are always
1042 @code{#000000} and @code{#ffffff}, respectively.
1043
1044 @code{alternate} is 1 if rows should alternate colors, 0 if all rows
1045 should be the same color.  When @code{alternate} is 1,
1046 @code{alt-fg-color} and @code{alt-bg-color} specify the colors for the
1047 alternate rows; otherwise they are empty strings.
1048
1049 @code{left-margin}, @code{right-margin}, @code{top-margin}, and
1050 @code{bottom-margin} are measured in px.
1051
1052 @node SPV Light Member Borders
1053 @subsection Borders
1054
1055 @example
1056 Borders =>
1057     count(
1058         ib1[endian]
1059         be32[n-borders] Border*[n-borders]
1060         bool[show-grid-lines]
1061         00 00 00)
1062
1063 Border =>
1064     be32[border-type]
1065     be32[stroke-type]
1066     be32[color]
1067 @end example
1068
1069 The Borders reflect how borders between regions are drawn.
1070
1071 The fixed value of @code{endian} can be used to validate the
1072 endianness.
1073
1074 @code{show-grid-lines} is 1 to draw grid lines, otherwise 0.
1075
1076 Each Border describes one kind of border.  @code{n-borders} seems to
1077 always be 19.  Each @code{border-type} appears once (although in an
1078 unpredictable order) and correspond to the following borders:
1079
1080 @table @asis
1081 @item 0
1082 Title.
1083 @item 1@dots{}4
1084 Left, top, right, and bottom outer frame.
1085 @item 5@dots{}8
1086 Left, top, right, and bottom inner frame.
1087 @item 9, 10
1088 Left and top of data area.
1089 @item 11, 12
1090 Horizontal and vertical dimension rows.
1091 @item 13, 14
1092 Horizontal and vertical dimension columns.
1093 @item 15, 16
1094 Horizontal and vertical category rows.
1095 @item 17, 18
1096 Horizontal and vertical category columns.
1097 @end table
1098
1099 @code{stroke-type} describes how a border is drawn, as one of:
1100
1101 @table @asis
1102 @item 0
1103 No line.
1104 @item 1
1105 Solid line.
1106 @item 2
1107 Dashed line.
1108 @item 3
1109 Thick line.
1110 @item 4
1111 Thin line.
1112 @item 5
1113 Double line.
1114 @end table
1115
1116 @code{color} is an RGB color.  Bits 24--31 are alpha, bits 16--23 are
1117 red, 8--15 are green, 0--7 are blue.  An alpha of 255 indicates an
1118 opaque color, therefore opaque black is 0xff000000.
1119
1120 @node SPV Light Member Print Settings
1121 @subsection Print Settings
1122
1123 @example
1124 PrintSettings =>
1125     count(
1126         ib1[endian]
1127         bool[all-layers]
1128         bool[paginate-layers]
1129         bool[fit-width]
1130         bool[fit-length]
1131         bool[top-continuation]
1132         bool[bottom-continuation]
1133         be32[n-orphan-lines]
1134         bestring[continuation-string])
1135 @end example
1136
1137 The PrintSettings reflect settings for printing.  The fixed value of
1138 @code{endian} can be used to validate the endianness.
1139
1140 @code{all-layers} is 1 to print all layers, 0 to print only the
1141 visible layers.
1142
1143 @code{paginate-layers} is 1 to print each layer at the start of a new
1144 page, 0 otherwise.  (This setting is honored only @code{all-layers} is
1145 1, since otherwise only one layer is printed.)
1146
1147 @code{fit-width} and @code{fit-length} control whether the table is
1148 shrunk to fit within a page's width or length, respectively.
1149
1150 @code{n-orphan-lines} is the minimum number of rows or columns to put
1151 in one part of a table that is broken across pages.
1152
1153 If @code{top-continuation} is 1, then @code{continuation-string} is
1154 printed at the top of a page when a table is broken across pages for
1155 printing; similarly for @code{bottom-continuation} and the bottom of a
1156 page.  Usually, @code{continuation-string} is empty.
1157
1158 @node SPV Light Member Table Settings
1159 @subsection Table Settings
1160
1161 @example
1162 TableSettings =>
1163     count(
1164       v3(
1165         ib1[endian]
1166         be32[x5]
1167         be32[current-layer]
1168         bool[omit-empty]
1169         bool[show-row-labels-in-corner]
1170         bool[show-alphabetic-markers]
1171         bool[footnote-marker-superscripts]
1172         byte[x6]
1173         becount(
1174           Breakpoints[row-breaks] Breakpoints[column-breaks]
1175           Keeps[row-keeps] Keeps[column-keeps]
1176           PointKeeps[row-point-keeps] PointKeeps[column-point-keeps]
1177         )
1178         bestring[notes]
1179         bestring[table-look]
1180         00...))
1181
1182 Breakpoints => be32[n-breaks] be32*[n-breaks]
1183
1184 Keeps => be32[n-keeps] Keep*[n-keeps]
1185 Keep => be32[offset] be32[n]
1186
1187 PointKeeps => be32[n-point-keeps] PointKeep*[n-point-keeps]
1188 PointKeep => be32[offset] be32 be32
1189 @end example
1190
1191 The TableSettings reflect display settings.  The fixed value of
1192 @code{endian} can be used to validate the endianness.
1193
1194 @code{current-layer} is the displayed layer.  The interpretation when
1195 there is more than one layer dimension is not yet known.
1196
1197 If @code{omit-empty} is 1, empty rows or columns (ones with nothing in
1198 any cell) are hidden; otherwise, they are shown.
1199
1200 If @code{show-row-labels-in-corner} is 1, then row labels are shown in
1201 the upper left corner; otherwise, they are shown nested.
1202
1203 If @code{show-alphabetic-markers} is 1, markers are shown as letters
1204 (e.g.@: @samp{a}, @samp{b}, @samp{c}, @dots{}); otherwise, they are
1205 shown as numbers starting from 1.
1206
1207 When @code{footnote-marker-superscripts} is 1, footnote markers are shown
1208 as superscripts, otherwise as subscripts.
1209
1210 The Breakpoints are rows or columns after which there is a page break;
1211 for example, a row break of 1 requests a page break after the second
1212 row.  Usually no breakpoints are specified, indicating that page
1213 breaks should be selected automatically.
1214
1215 The Keeps are ranges of rows or columns to be kept together without a
1216 page break; for example, a row Keep with @code{offset} 1 and @code{n}
1217 10 requests that the 10 rows starting with the second row be kept
1218 together.  Usually no Keeps are specified.
1219
1220 The PointKeeps seem to be generated automatically based on
1221 user-specified Keeps.  They seems to indicate a conversion from rows
1222 or columns to pixel or point offsets.
1223
1224 @code{notes} is a text string that contains user-specified notes.  It
1225 is displayed when the user hovers the cursor over the table, like
1226 ``alt text'' on a webpage.  It is not printed.  It is usually empty.
1227
1228 @code{table-look} is the name of a SPSS ``TableLook'' table style,
1229 such as ``Default'' or ``Academic''; it is often empty.
1230
1231 TableSettings ends with an arbitrary number of null bytes.  A writer
1232 may safely write 82 null bytes.
1233
1234 A writer may safely use 4 for @code{x5} and 0 for @code{x6}.
1235
1236 @node SPV Light Member Formats
1237 @subsection Formats
1238
1239 @example
1240 Formats =>
1241     int32[n-widths] int32*[n-widths]
1242     string[locale]
1243     int32[current-layer]
1244     bool bool bool
1245     Y0
1246     CustomCurrency
1247     count(
1248       v1(X0?)
1249       v3(count(X1 count(X2)) count(X3)))
1250 Y0 => int32[epoch] byte[decimal] byte[grouping]
1251 CustomCurrency => int32[n-ccs] string*[n-ccs]
1252 @end example
1253
1254 If @code{n-widths} is nonzero, then the accompanying integers are
1255 column widths as manually adjusted by the user.
1256
1257 @code{locale} is a locale including an encoding, such as
1258 @code{en_US.windows-1252} or @code{it_IT.windows-1252}.  The rest of
1259 the character strings in the member use this encoding.  The encoding
1260 string is itself encoded in US-ASCII.
1261
1262 @code{epoch} is the year that starts the epoch.  A 2-digit year is
1263 interpreted as belonging to the 100 years beginning at the epoch.  The
1264 default epoch year is 69 years prior to the current year; thus, in
1265 2017 this field by default contains 1948.  In the corpus, @code{epoch}
1266 ranges from 1943 to 1948, plus some contain -1.
1267
1268 @code{decimal} is the decimal point character.  The observed values
1269 are @samp{.} and @samp{,}.
1270
1271 @code{grouping} is the grouping character.  Usually, it is @samp{,} if
1272 @code{decimal} is @samp{.}, and vice versa.  Other observed values are
1273 @samp{'} (apostrophe), @samp{ } (space), and zero (presumably
1274 indicating that digits should not be grouped).
1275
1276 @code{n-ccs} is observed as either 0 or 5.  When it is 5, the
1277 following strings are CCA through CCE format strings.  @xref{Custom
1278 Currency Formats,,, pspp, PSPP}.  Most commonly these are all
1279 @code{-,,,} but other strings occur.
1280
1281 @subsubheading X0
1282
1283 X0 only appears, optionally, in version 1 members.
1284
1285 @example
1286 X0 => byte*14 Y1 Y2
1287 Y1 =>
1288     string[command] string[command-local]
1289     string[language] string[charset] string[locale]
1290     bool bool bool bool
1291     Y0
1292 Y2 => CustomCurrency byte[missing] bool[x16]
1293 @end example
1294
1295 @code{command} describes the statistical procedure that generated the
1296 output, in English.  It is not necessarily the literal syntax name of
1297 the procedure: for example, NPAR TESTS becomes ``Nonparametric
1298 Tests.''  @code{command-local} is the procedure's name, translated
1299 into the output language; it is often empty and, when it is not,
1300 sometimes the same as @code{command}.
1301
1302 @code{dataset} is the name of the dataset analyzed to produce the
1303 output, e.g.@: @code{DataSet1}, and @code{datafile} the name of the
1304 file it was read from, e.g.@: @file{C:\Users\foo\bar.sav}.  The latter
1305 is sometimes the empty string.
1306
1307 @code{missing} is the character used to indicate that a cell contains
1308 a missing value.  It is always observed as @samp{.}.
1309
1310 X0 repeats @code{decimal}, @code{grouping}, CustomCurrency, and
1311 @code{missing} already included in Formats.
1312
1313 A writer may safely use false for @code{x16}.
1314
1315 @subsubheading X1
1316
1317 X1 only appears in version 3 members.
1318
1319 @example
1320 X1 =>
1321     00 byte[x14] bool[x15]
1322     byte[lang]
1323     byte[show-variables]
1324     byte[show-values]
1325     int32[x17] int32[x18]
1326     00*17
1327     bool[x19]
1328     01
1329 @end example
1330
1331 @code{lang} may indicate the language in use.  Some values seem to be
1332 0: @t{en}, 1: @t{de}, 2: @t{es}, 3: @t{it}, 5: @t{ko}, 6: @t{pl}, 8:
1333 @t{zh-tw}, 10: @t{pt_BR}, 11: @t{fr}.  The @code{locale} in Formats
1334 and the @code{language}, @code{charset}, and @code{locale} in X0 are
1335 more likely to be useful in practice.
1336
1337 @code{show-variables} determines how variables are displayed by
1338 default.  A value of 1 means to display variable names, 2 to display
1339 variable labels when available, 3 to display both (name followed by
1340 label, separated by a space).  The most common value is 0, which
1341 probably means to use a global default.
1342
1343 @code{show-values} is a similar setting for values.  A value of 1
1344 means to display the value, 2 to display the value label when
1345 available, 3 to display both.  Again, the most common value is 0,
1346 which probably means to use a global default.
1347
1348 A writer may safely use 1 for @code{x14}, false for @code{x15}, -1 for
1349 @code{x17} and @code{x18}, and false for @code{x19}.
1350
1351 @subsubheading X2
1352
1353 X2 only appears in version 3 members.
1354
1355 @example
1356 X2 =>
1357     int32[n-row-heights] int32*[n-row-heights]
1358     int32[n-style-map] StyleMap*[n-style-map]
1359     int32[n-styles] StylePair*[n-styles]
1360     count((i0 i0)?)
1361 StyleMap => int64[cell-index] int16[style-index]
1362 @end example
1363
1364 If present, @code{n-row-heights} and the accompanying integers are row
1365 heights as manually adjusted by the user.
1366
1367 The rest of X2 specifies styles for data cells.  At first glance this
1368 is odd, because each data cell can have its own style embedded as part
1369 of the data, but in practice X2 specifies a style for a cell only if
1370 that cell is empty (and thus does not appear in the data at all).
1371 Each StyleMap specifies the index of a blank cell, calculated the same
1372 was as in the Cells (@pxref{SPV Light Member Cells}), along with a
1373 0-based index into the accompanying StylePair array.
1374
1375 A writer may safely omit the optional @code{i0 i0} inside the
1376 @code{count(@dots{})}.
1377
1378 @subsubheading X3
1379
1380 X3 only appears in version 3 members.
1381
1382 @example
1383 X3 =>
1384     01 00 byte[x20] 00 00 00
1385     Y1
1386     double[small] 01
1387     (string[dataset] string[datafile] i0 int32[date] i0)?
1388     Y2
1389     (int32 i0)?
1390 @end example
1391
1392 @code{date} is a date, as seconds since the epoch, i.e.@: since
1393 January 1, 1970.  Pivot tables within an SPV file often have dates a
1394 few minutes apart, so this is probably a creation date for the table
1395 rather than for the file.
1396
1397 X3 repeats @code{decimal}, @code{grouping}, CustomCurrency, and
1398 @code{missing} already included in Formats.  @code{command},
1399 @code{command-local}, @code{language}, @code{charset}, and
1400 @code{locale} have the same meaning as in X0.
1401
1402 @code{small} is a small real number, e.g.@: .001.  Numbers smaller
1403 than this in absolute value are displayed in scientific notation.
1404
1405 Sometimes @code{dataset}, @code{datafile}, and @code{date} are present
1406 and other times they are absent.  The reader can distinguish by
1407 assuming that they are present and then checking whether the
1408 presumptive @code{dataset} contains a null byte (a valid string never
1409 will).
1410
1411 A writer may safely use 4 for @code{x20} and omit the optional bytes
1412 at the end.
1413
1414 @node SPV Light Member Dimensions
1415 @subsection Dimensions
1416
1417 A pivot table presents multidimensional data.  A Dimension identifies
1418 the categories associated with each dimension.
1419
1420 @example
1421 Dimensions => int32[n-dims] Dimension*[n-dims]
1422 Dimension =>
1423     Value[name] DimProperties
1424     int32[n-categories] Category*[n-categories]
1425 DimProperties =>
1426     byte[x1]
1427     byte[x2]
1428     int32[x3]
1429     bool[hide-dim-label]
1430     bool[hide-all-labels]
1431     01 int32[dim-index]
1432 @end example
1433
1434 @code{name} is the name of the dimension, e.g.@: @code{Variables},
1435 @code{Statistics}, or a variable name.
1436
1437 The meanings of @code{x1} and @code{x3} are unknown.  @code{x1} is
1438 usually 0 but many other values have been observed.  A writer may
1439 safely use 0 for @code{x1} and 2 for @code{x3}.
1440
1441 @code{x2} is 0, 1, or 2.  For a pivot table with @var{L} layer
1442 dimensions, @var{R} row dimensions, and @var{C} column dimensions,
1443 @code{x2} is 2 for the first @var{L} dimensions, 0 for the next
1444 @var{R} dimensions, and 1 for the remaining @var{C} dimensions.  This
1445 does not mean that the layer dimensions must be presented first,
1446 followed by the row dimensions, followed by the column dimensions---on
1447 the contrary, they are frequently in a different order---but @code{x2}
1448 must follow this pattern to prevent the pivot table from being
1449 misinterpreted.
1450
1451 If @code{hide-dim-label} is 00, the pivot table displays a label for
1452 the dimension itself.  Because usually the group and category labels
1453 are enough explanation, it is usually 01.
1454
1455 If @code{hide-all-labels} is 01, the pivot table omits all labels for
1456 the dimension, including group and category labels.  It is usually 00.
1457 When @code{hide-all-labels} is 01, @code{show-dim-label} is ignored.
1458
1459 @code{dim-index} is usually the 0-based index of the dimension, e.g.@:
1460 0 for the first dimension, 1 for the second, and so on.  Sometimes it
1461 is -1.  There is no visible difference.
1462
1463 @node SPV Light Member Categories
1464 @subsection Categories
1465
1466 Categories are arranged in a tree.  Only the leaf nodes in the tree
1467 are really categories; the others just serve as grouping constructs.
1468
1469 @example
1470 Category => Value[name] (Leaf @math{|} Group)
1471 Leaf => 00 00 00 i2 int32[leaf-index] i0
1472 Group =>
1473     bool[merge] 00 01 int32[x22]
1474     i-1 int32[n-subcategories] Category*[n-subcategories]
1475 @end example
1476
1477 @code{name} is the name of the category (or group).
1478
1479 A Leaf represents a leaf category.  The Leaf's @code{leaf-index} is a
1480 nonnegative integer unique within the Dimension and less than
1481 @code{n-categories} in the Dimension.  If the user does not sort or
1482 rearrange the categories, then @code{leaf-index} starts at 0 for the
1483 first Leaf in the dimension and increments by 1 with each successive
1484 Leaf.  If the user does sorts or rearrange the categories, then the
1485 order of categories in the file reflects that change and
1486 @code{leaf-index} reflects the original order.
1487
1488 Occasionally a dimension has no leaf categories at all.  A table that
1489 contains such a dimension necessarily has no data at all.
1490
1491 A Group is a group of nested categories.  Usually a Group contains at
1492 least one Category, so that @code{n-subcategories} is positive, but a
1493 few Groups with @code{n-subcategories} 0 has been observed.
1494
1495 If a Group's @code{merge} is 00, the most common value, then the group
1496 is really a distinct group that should be represented as such in the
1497 visual representation and user interface.  If @code{merge} is 01, the
1498 categories in this group should be shown and treated as if they were
1499 direct children of the group's containing group (or if it has no
1500 parent group, then direct children of the dimension), and this group's
1501 name is irrelevant and should not be displayed.  (Merged groups can be
1502 nested!)
1503
1504 (For writing an SPV file, there is no need to use the @code{merge}
1505 feature unless it is convenient.)
1506
1507 A Group's @code{x22} appears to be i2 when all of the categories
1508 within a group are leaf categories that directly represent data values
1509 for a variable (e.g.@: in a frequency table or crosstabulation, a group
1510 of values in a variable being tabulated) and i0 otherwise.  A writer
1511 may safely write a constant 0 in this field.
1512
1513 @node SPV Light Member Axes
1514 @subsection Axes
1515
1516 After the dimensions come assignment of each dimension to one of the
1517 axes: layers, rows, and columns.
1518
1519 @example
1520 Axes =>
1521     int32[n-layers] int32[n-rows] int32[n-columns]
1522     int32*[n-layers] int32*[n-rows] int32*[n-columns]
1523 @end example
1524
1525 The values of @code{n-layers}, @code{n-rows}, and @code{n-columns}
1526 each specifies the number of dimensions displayed in layers, rows, and
1527 columns, respectively.  Any of them may be zero.  Their values sum to
1528 @code{n-dimensions} from Dimensions (@pxref{SPV Light Member
1529 Dimensions}).
1530
1531 The following @code{n-dimensions} integers, in three groups, are a
1532 permutation of the 0-based dimension numbers.  The first
1533 @code{n-layers} integers specify each of the dimensions represented by
1534 layers, the next @code{n-rows} integers specify the dimensions
1535 represented by rows, and the final @code{n-columns} integers specify
1536 the dimensions represented by columns.  When there is more than one
1537 dimension of a given kind, the inner dimensions are given first.
1538
1539 @node SPV Light Member Cells
1540 @subsection Cells
1541
1542 The final part of an SPV light member contains the actual data.
1543
1544 @example
1545 Cells => int32[n-cells] Cell*[n-cells]
1546 Cell => int64[index] v1(00?) Value
1547 @end example
1548
1549 A Cell consists of an @code{index} and a Value.  Suppose there are
1550 @math{d} dimensions, numbered 1 through @math{d} in the order given in
1551 the Dimensions previously, and that dimension @math{i}, has @math{n_i}
1552 categories.  Consider the cell at coordinates @math{x_i}, @math{1 \le
1553 i \le d}, and note that @math{0 \le x_i < n_i}.  Then the index is
1554 calculated by the following algorithm:
1555
1556 @display
1557 let @i{index} = 0
1558 for each @math{i} from 1 to @math{d}:
1559     @i{index} = (@math{n_i \times} @i{index}) @math{+} @math{x_i}
1560 @end display
1561
1562 For example, suppose there are 3 dimensions with 3, 4, and 5
1563 categories, respectively.  The cell at coordinates (1, 2, 3) has
1564 index @math{5 \times (4 \times (3 \times 0 + 1) + 2) + 3 = 33}.
1565 Within a given dimension, the index is the @code{leaf-index} in a Leaf.
1566
1567 @node SPV Light Member Value
1568 @subsection Value
1569
1570 Value is used throughout the SPV light member format.  It boils down
1571 to a number or a string.
1572
1573 @example
1574 Value => 00? 00? 00? 00? RawValue
1575 RawValue =>
1576     01 ValueMod int32[format] double[x]
1577   @math{|} 02 ValueMod int32[format] double[x]
1578     string[var-name] string[value-label] byte[show]
1579   @math{|} 03 string[local] ValueMod string[id] string[c] bool[fixed]
1580   @math{|} 04 ValueMod int32[format] string[value-label] string[var-name]
1581     byte[show] string[s]
1582   @math{|} 05 ValueMod string[var-name] string[var-label] byte[show]
1583   @math{|} ValueMod string[template] int32[n-args] Argument*[n-args]
1584 Argument =>
1585     i0 Value
1586   @math{|} int32[x] i0 Value*[x]      /* x > 0 */
1587 @end example
1588
1589 There are several possible encodings, which one can distinguish by the
1590 first nonzero byte in the encoding.
1591
1592 @table @asis
1593 @item 01
1594 The numeric value @code{x}, intended to be presented to the user
1595 formatted according to @code{format}, which is in the format described
1596 for system files, except that format 40 is a synonym for F format
1597 instead of MTIME.  @xref{System File Output Formats}, for details.
1598 Most commonly, @code{format} has width 40 (the maximum).
1599
1600 An @code{x} with the maximum negative double value @code{-DBL_MAX}
1601 represents the system-missing value SYSMIS.  (HIGHEST and LOWEST have
1602 not been observed.)  @xref{System File Format}, for more about these
1603 special values.
1604
1605 @item 02
1606 Similar to @code{01}, with the additional information that @code{x} is
1607 a value of variable @code{var-name} and has value label
1608 @code{value-label}.  Both @code{var-name} and @code{value-label} can
1609 be the empty string, the latter very commonly.
1610
1611 @code{show} determines whether to show the numeric value or the value
1612 label.  A value of 1 means to show the value, 2 to show the label, 3
1613 to show both, and 0 means to use the default specified in
1614 @code{show-values} (@pxref{SPV Light Member Formats}).
1615
1616 @item 03
1617 A text string, in two forms: @code{c} is in English, and sometimes
1618 abbreviated or obscure, and @code{local} is localized to the user's
1619 locale.  In an English-language locale, the two strings are often the
1620 same, and in the cases where they differ, @code{local} is more
1621 appropriate for a user interface, e.g.@: @code{c} of ``Not a PxP table
1622 for MCN...'' versus @code{local} of ``Computed only for a PxP table,
1623 where P must be greater than 1.''
1624
1625 @code{c} and @code{local} are always either both empty or both
1626 nonempty.
1627
1628 @code{id} is a brief identifying string whose form seems to resemble a
1629 programming language identifier, e.g.@: @code{cumulative_percent} or
1630 @code{factor_14}.  It is not unique.
1631
1632 @code{fixed} is 00 for text taken from user input, such as syntax
1633 fragment, expressions, file names, data set names, and 01 for fixed
1634 text strings such as names of procedures or statistics.  In the former
1635 case, @code{id} is always the empty string; in the latter case,
1636 @code{id} is still sometimes empty.
1637
1638 @item 04
1639 The string value @code{s}, intended to be presented to the user
1640 formatted according to @code{format}.  The format for a string is not
1641 too interesting, and the corpus contains many clearly invalid formats
1642 like A16.39 or A255.127 or A134.1, so readers should probably ignore
1643 the format entirely.
1644
1645 @code{s} is a value of variable @code{var-name} and has value label
1646 @code{value-label}.  @code{var-name} is never empty but
1647 @code{value-label} is commonly empty.
1648
1649 @code{show} has the same meaning as in the encoding for 02.
1650
1651 @item 05
1652 Variable @code{var-name}, which is rarely observed as empty in the
1653 corpus, with variable label @code{var-label}, which is often empty.
1654
1655 @code{show} determines whether to show the variable name or the
1656 variable label.  A value of 1 means to show the name, 2 to show the
1657 label, 3 to show both, and 0 means to use the default specified in
1658 @code{show-variables} (@pxref{SPV Light Member Formats}).
1659
1660 @item otherwise
1661 When the first byte of a RawValue is not one of the above, the
1662 RawValue starts with a ValueMod, whose syntax is described in the next
1663 section.  (A ValueMod always begins with byte 31 or 58.)
1664
1665 This case is a template string, analogous to @code{printf}, followed
1666 by one or more Arguments, each of which has one or more values.  The
1667 template string is copied directly into the output except for the
1668 following special syntax,
1669
1670 @table @code
1671 @item \%
1672 @itemx \:
1673 @itemx \[
1674 @itemx \]
1675 Each of these expands to the character following @samp{\\}, to escape
1676 characters that have special meaning in template strings.  These are
1677 effective inside and outside the @code{[@dots{}]}  syntax forms
1678 described below.
1679
1680 @item \n
1681 Expands to a new-line, inside or outside the @code{[@dots{}]} forms
1682 described below.
1683
1684 @item ^@var{i}
1685 Expands to a formatted version of argument @var{i}, which must have
1686 only a single value.  For example, @code{^1} expands to the first
1687 argument's @code{value}.
1688
1689 @item [:@var{a}:]@var{i}
1690 Expands @var{a} for each of the values in @var{i}.  @var{a}
1691 should contain one or more @code{^@var{j}} conversions, which are
1692 drawn from the values for argument @var{i} in order.  Some examples
1693 from the corpus:
1694
1695 @table @code
1696 @item [:^1:]1
1697 All of the values for the first argument, concatenated.
1698
1699 @item [:^1\n:]1
1700 Expands to the values for the first argument, each followed by
1701 a new-line.
1702
1703 @item [:^1 = ^2:]2
1704 Expands to @code{@var{x} = @var{y}} where @var{x} is the second
1705 argument's first value and @var{y} is its second value.  (This would
1706 be used only if the argument has two values.  If there were more
1707 values, the second and third values would be directly concatenated,
1708 which would look funny.)
1709 @end table
1710
1711 @item [@var{a}:@var{b}:]@var{i}
1712 This extends the previous form so that the first values are expanded
1713 using @var{a} and later values are expanded using @var{b}.  For an
1714 unknown reason, within @var{a} the @code{^@var{j}} conversions are
1715 instead written as @code{%@var{j}}.  Some examples from the corpus:
1716
1717 @table @code
1718 @item [%1:*^1:]1
1719 Expands to all of the values for the first argument, separated by
1720 @samp{*}.
1721
1722 @item [%1 = %2:, ^1 = ^2:]1
1723 Given appropriate values for the first argument, expands to @code{X =
1724 1, Y = 2, Z = 3}.
1725
1726 @item [%1:, ^1:]1
1727 Given appropriate values, expands to @code{1, 2, 3}.
1728 @end table
1729 @end table
1730
1731 The template string is localized to the user's locale.
1732 @end table
1733
1734 A writer may safely omit all of the optional 00 bytes at the beginning
1735 of a Value, except that it should write a single 00 byte before a
1736 templated Value.
1737
1738 @node SPV Light Member ValueMod
1739 @subsection ValueMod
1740
1741 A ValueMod can specify special modifications to a Value.
1742
1743 @example
1744 ValueMod =>
1745     58
1746   @math{|} 31
1747     int32[n-refs] int16*[n-refs]
1748     (i0 | i1 string[subscript])
1749     v1(00 (i1 | i2) 00? 00? int32 00? 00?)
1750     v3(count(TemplateString StylePair))
1751
1752 TemplateString => count((count((i0 58)?) (58 @math{|} 31 string[id]))?)
1753
1754 StylePair =>
1755     (31 FontStyle | 58)
1756     (31 CellStyle | 58)
1757
1758 FontStyle =>
1759     bool[bold] bool[italic] bool[underline] bool[show]
1760     string[fg-color] string[bg-color]
1761     string[typeface] byte[size]
1762
1763 CellStyle =>
1764     int32[halign] int32[valign] double[decimal-offset]
1765     int16[left-margin] int16[right-margin]
1766     int16[top-margin] int16[bottom-margin]
1767 @end example
1768
1769 A ValueMod that begins with ``31'' specifies special modifications to
1770 a Value.
1771
1772 Each of the @code{n-refs} integers is a reference to a Footnote
1773 (@pxref{SPV Light Member Footnotes}) by 0-based index.  Footnote
1774 markers are shown appended to the main text of the Value, as
1775 superscripts.
1776
1777 The @code{subscript}, if present, is a string to append to the main
1778 text of the Value, as a subscript.  The subscript text is a brief
1779 indicator, e.g.@: @samp{a} or @samp{a,b}, with its meaning indicated
1780 by the table caption.
1781
1782 The @code{id} inside the TemplateString, if present, is a template
1783 string for substitutions using the syntax explained previously.  It
1784 appears to be an English-language version of the localized template
1785 string in the Value in which the Template is nested.  A writer may
1786 safely omit the optional fixed data in TemplateString.
1787
1788 FontStyle and CellStyle, if present, change the style for this
1789 individual Value.  In FontStyle, @code{bold}, @code{italic}, and
1790 @code{underline} control the particular style.  @code{show} is
1791 ordinarily 1; if it is 0, then the cell data is not shown.
1792 @code{fg-color} and @code{bg-color} are strings in the format
1793 @code{#rrggbb}, e.g.@: @code{#ff0000} for red or @code{#ffffff} for
1794 white.  The empty string is occasionally observed also.  The
1795 @code{size} is a font size in units of 1/128 inch.
1796
1797 In CellStyle, @code{halign} is 0 for center, 2 for left, 4 for right,
1798 6 for decimal, 0xffffffad for mixed.  For decimal alignment,
1799 @code{decimal-offset} is the decimal point's offset from the right
1800 side of the cell, in pt (@pxref{SPV Light Detail Member Format}).
1801 @code{valign} specifies vertical alignment: 0 for center, 1 for top, 3
1802 for bottom.  @code{left-margin}, @code{right-margin},
1803 @code{top-margin}, and @code{bottom-margin} are in pt.
1804
1805 @node SPV Legacy Detail Member Binary Format
1806 @section Legacy Detail Member Binary Format
1807
1808 Whereas the light binary format represents everything about a given
1809 pivot table, the legacy binary format conceptually consists of a
1810 number of named sources, each of which consists of a number of named
1811 variables, each of which is a 1-dimensional array of numbers or
1812 strings or a mix.  Thus, the legacy binary member format is quite
1813 simple.
1814
1815 This section uses the same context-free grammar notation as in the
1816 previous section, with the following additions:
1817
1818 @table @asis
1819 @item vAF(@var{x})
1820 In a version 0xaf legacy member, @var{x}; in other versions, nothing.
1821 (The legacy member header indicates the version; see below.)
1822
1823 @item vB0(@var{x})
1824 In a version 0xb0 legacy member, @var{x}; in other versions, nothing.
1825 @end table
1826
1827 A legacy detail member @file{.bin} has the following overall format:
1828
1829 @example
1830 LegacyBinary =>
1831     00 byte[version] int16[n-sources] int32[member-size]
1832     Metadata*[n-sources]
1833     #Data*[n-sources]
1834     #Strings?
1835 @end example
1836
1837 @code{version} is a version number that affects the interpretation of
1838 some of the other data in the member.  Versions 0xaf and 0xb0 are
1839 known.  We will refer to ``version 0xaf'' and ``version 0xb0'' members
1840 later on.
1841
1842 A legacy member consists of @code{n-sources} data sources, each of
1843 which has Metadata and Data.
1844
1845 @code{member-size} is the size of the legacy binary member, in bytes.
1846
1847 The Data and Strings above are commented out because the Metadata has
1848 some oddities that mean that the Data sometimes seems to start at
1849 an unexpected place.  The following section goes into detail.
1850
1851 @menu
1852 * SPV Legacy Member Metadata::
1853 * SPV Legacy Member Numeric Data::
1854 * SPV Legacy Member String Data::
1855 @end menu
1856
1857 @node SPV Legacy Member Metadata
1858 @subsection Metadata
1859
1860 @example
1861 Metadata =>
1862     int32[n-values] int32[n-variables] int32[data-offset]
1863     vAF(byte*28[source-name])
1864     vB0(byte*64[source-name] int32[x])
1865 @end example
1866
1867 A data source has @code{n-variables} variables, each with
1868 @code{n-values} data values.
1869
1870 @code{source-name} is a 28- or 64-byte string padded on the right with
1871 0-bytes.  The names that appear in the corpus are very generic:
1872 usually @code{tableData} for pivot table data or @code{source0} for
1873 chart data.
1874
1875 A given Metadata's @code{data-offset} is the offset, in bytes, from
1876 the beginning of the member to the start of the corresponding Data.
1877 This allows programs to skip to the beginning of the data for a
1878 particular source.  In every case in the corpus, the Data follow the
1879 Metadata in the same order, but it is important to use
1880 @code{data-offset} instead of reading sequentially through the file
1881 because of the exception described below.
1882
1883 One SPV file in the corpus has legacy binary members with version 0xb0
1884 but a 28-byte @code{source-name} field (and only a single source).  In
1885 practice, this means that the 64-byte @code{source-name} used in
1886 version 0xb0 has a lot of 0-bytes in the middle followed by the
1887 @code{variable-name} of the following Data.  As long as a reader
1888 treats the first 0-byte in the @code{source-name} as terminating the
1889 string, it can properly interpret these members.
1890
1891 The meaning of @code{x} in version 0xb0 is unknown.
1892
1893 @node SPV Legacy Member Numeric Data
1894 @subsection Numeric Data
1895
1896 @example
1897 Data => Variable*[n-variables]
1898 Variable => byte*288[variable-name] double*[n-values]
1899 @end example
1900
1901 Data follow the Metadata in the legacy binary format, with sources in
1902 the same order (but readers should use the @code{data-offset} in
1903 Metadata records, rather than reading sequentially).  Each Variable
1904 begins with a @code{variable-name} that generally indicates its role
1905 in the pivot table, e.g.@: ``cell'', ``cellFormat'',
1906 ``dimension0categories'', ``dimension0group0'', followed by the
1907 numeric data, one double per datum.  A double with the maximum
1908 negative double @code{-DBL_MAX} represents the system-missing value
1909 SYSMIS.
1910
1911 @node SPV Legacy Member String Data
1912 @subsection String Data
1913
1914 @example
1915 Strings => SourceMaps[maps] Labels
1916
1917 SourceMaps => int32[n-maps] SourceMap*[n-maps]
1918
1919 SourceMap => string[source-name] int32[n-variables] VariableMap*[n-variables]
1920 VariableMap => string[variable-name] int32[n-data] DatumMap*[n-data]
1921 DatumMap => int32[value-idx] int32[label-idx]
1922
1923 Labels => int32[n-labels] Label*[n-labels]
1924 Label => int32[frequency] string[label]
1925 @end example
1926
1927 Each variable may include a mix of numeric and string data values.  If
1928 a legacy binary member contains any string data, Strings is present;
1929 otherwise, it ends just after the last Data element.
1930
1931 The string data overlays the numeric data.  When a variable includes
1932 any string data, its Variable represents the string values with a
1933 SYSMIS or NaN placeholder.  (Not all such values need be
1934 placeholders.)
1935
1936 Each SourceMap provides a mapping between SYSMIS or NaN values in source
1937 @code{source-name} and the string data that they represent.
1938 @code{n-variables} is the number of variables in the source that
1939 include string data.  More precisely, it is the 1-based index of the
1940 last variable in the source that includes any string data; thus, it
1941 would be 4 if there are 5 variables and only the fourth one includes
1942 string data.
1943
1944 A VariableMap repeats its variable's name, but variables are always
1945 present in the same order as the source, starting from the first
1946 variable, without skipping any even if they have no string values.
1947 Each VariableMap contains DatumMap nonterminals, each of which maps
1948 from a 0-based index within its variable's data to a 0-based label
1949 index, e.g.@: pair @code{value-idx} = 2, @code{label-idx} = 3, means
1950 that the third data value (which must be SYSMIS or NaN) is to be
1951 replaced by the string of the fourth Label.
1952
1953 The labels themselves follow the pairs.  The valuable part of each
1954 label is the string @code{label}.  Each label also includes a
1955 @code{frequency} that reports the number of DatumMaps that reference
1956 it (although this is not useful).
1957
1958 @node SPV Legacy Detail Member XML Format
1959 @section Legacy Detail Member XML Format
1960
1961 The design of the detail XML format is not what one would end up with
1962 for describing pivot tables.  This is because it is a special case
1963 of a much more general format (``visualization XML'' or ``VizML'')
1964 that can describe a wide range of visualizations.  Most of this
1965 generality is overkill for tables, and so we end up with a funny
1966 subset of a general-purpose format.
1967
1968 An XML Schema for VizML is available, distributed with SPSS binaries,
1969 under a nonfree license.  It contains documentation that is
1970 occasionally helpful.
1971
1972 See @file{src/output/spv/detail-xml.grammar} in the PSPP source tree
1973 for the full grammar that it uses for parsing.
1974
1975 The important elements of the detail XML format are:
1976
1977 @itemize @bullet
1978 @item
1979 Variables.  @xref{SPV Detail Variable Elements}.
1980
1981 @item
1982 Assignment of variables to axes.  A variable can appear as columns, or
1983 rows, or layers.  The @code{faceting} element and its sub-elements
1984 describe this assignment.
1985
1986 @item
1987 Styles and other annotations.
1988 @end itemize
1989
1990 This description is not detailed enough to write legacy tables.
1991 Instead, write tables in the light binary format.
1992
1993 @menu
1994 * SPV Detail visualization Element::
1995 * SPV Detail Variable Elements::
1996 * SPV Detail extension Element::
1997 * SPV Detail graph Element::
1998 * SPV Detail location Element::
1999 * SPV Detail faceting Element::
2000 * SPV Detail facetLayout Element::
2001 * SPV Detail label Element::
2002 * SPV Detail setCellProperties Element::
2003 * SPV Detail setFormat Element::
2004 * SPV Detail interval Element::
2005 * SPV Detail style Element::
2006 * SPV Detail labelFrame Element::
2007 * SPV Detail Legacy Properties::
2008 @end menu
2009
2010 @node SPV Detail visualization Element
2011 @subsection The @code{visualization} Element
2012
2013 @example
2014 visualization
2015    :creator
2016    :date
2017    :lang
2018    :name
2019    :style[style_ref]=ref style
2020    :type
2021    :version
2022    :schemaLocation?
2023 => visualization_extension?
2024    userSource
2025    (sourceVariable | derivedVariable)+
2026    categoricalDomain?
2027    graph
2028    labelFrame[lf1]*
2029    container?
2030    labelFrame[lf2]*
2031    style+
2032    layerController?
2033
2034 extension[visualization_extension]
2035    :numRows=int?
2036    :showGridline=bool?
2037    :minWidthSet=(true)?
2038    :maxWidthSet=(true)?
2039 => EMPTY
2040
2041 userSource :missing=(listwise | pairwise)? => EMPTY
2042
2043 categoricalDomain => variableReference simpleSort
2044
2045 simpleSort :method[sort_method]=(custom) => categoryOrder
2046
2047 container :style=ref style => container_extension? location+ labelFrame*
2048
2049 extension[container_extension] :combinedFootnotes=(true) => EMPTY
2050
2051 layerController
2052    :source=(tableData)
2053    :target=ref label?
2054 => EMPTY
2055 @end example
2056
2057 The @code{visualization} element is the root of detail XML member.  It
2058 has the following attributes:
2059
2060 @defvr {Attribute} creator
2061 The version of the software that created this SPV file, as a string of
2062 the form @code{xxyyzz}, which represents software version xx.yy.zz,
2063 e.g.@: @code{160001} is version 16.0.1.  The corpus includes major
2064 versions 16 through 19.
2065 @end defvr
2066
2067 @defvr {Attribute} date
2068 The date on the which the file was created, as a string of the form
2069 @code{YYYY-MM-DD}.
2070 @end defvr
2071
2072 @defvr {Attribute} lang
2073 The locale used for output, in Windows format, which is similar to the
2074 format used in Unix with the underscore replaced by a hyphen, e.g.@:
2075 @code{en-US}, @code{en-GB}, @code{el-GR}, @code{sr-Cryl-RS}.
2076 @end defvr
2077
2078 @defvr {Attribute} name
2079 The title of the pivot table, localized to the output language.
2080 @end defvr
2081
2082 @defvr {Attribute} style
2083 The base style for the pivot table.  In every example in the corpus,
2084 the @code{style} element has no attributes other than @code{id}.
2085 @end defvr
2086
2087 @defvr {Attribute} type
2088 A floating-point number.  The meaning is unknown.
2089 @end defvr
2090
2091 @defvr {Attribute} version
2092 The visualization schema version number.  In the corpus, the value is
2093 one of 2.4, 2.5, 2.7, and 2.8.
2094 @end defvr
2095
2096 The @code{userSource} element has no visible effect.
2097
2098 The @code{extension} element as a child of @code{visualization} has
2099 the following attributes.
2100
2101 @defvr {Attribute} numRows
2102 An integer that presumably defines the number of rows in the displayed
2103 pivot table.
2104 @end defvr
2105
2106 @defvr {Attribute} showGridline
2107 Always set to @code{false} in the corpus.
2108 @end defvr
2109
2110 @defvr {Attribute} minWidthSet
2111 @defvrx {Attribute} maxWidthSet
2112 Always set to @code{true} in the corpus.
2113 @end defvr
2114
2115 The @code{extension} element as a child of @code{container} has the
2116 following attribute
2117
2118 @defvr {Attribute} combinedFootnotes
2119 Meaning unknown.
2120 @end defvr
2121
2122 The @code{categoricalDomain} and @code{simpleSort} elements have no
2123 visible effect.
2124
2125 The @code{layerController} element has no visible effect.
2126
2127 @node SPV Detail Variable Elements
2128 @subsection Variable Elements
2129
2130 A ``variable'' in detail XML is a 1-dimensional array of data.  Each
2131 element of the array may, independently, have string or numeric
2132 content.  All of the variables in a given detail XML member either
2133 have the same number of elements or have zero elements.
2134
2135 Two different elements define variables and their content:
2136
2137 @table @code
2138 @item sourceVariable
2139 These variables' data comes from the associated @code{tableData.bin}
2140 member.
2141
2142 @item derivedVariable
2143 These variables are defined in terms of a mapping function from a
2144 source variable, or they are empty.
2145 @end table
2146
2147 A variable named @code{cell} always exists.  This variable holds the
2148 data displayed in the table.
2149
2150 Variables in detail XML roughly correspond to the dimensions in a
2151 light detail member.  Each dimension has the following variables with
2152 stylized names, where @var{n} is a number for the dimension starting
2153 from 0:
2154
2155 @table @code
2156 @item dimension@var{n}categories
2157 The dimension's leaf categories (@pxref{SPV Light Member Categories}).
2158
2159 @item dimension@var{n}group0
2160 Present only if the dimension's categories are grouped, this variable
2161 holds the group labels for the categories.  Grouping is inferred
2162 through adjacent identical labels.  Categories that are not part of a
2163 group have empty-string data in this variable.
2164
2165 @item dimension@var{n}group1
2166 Present only if the first-level groups are further grouped, this
2167 variable holds the labels for the second-level groups.  There can be
2168 additional variables with further levels of grouping.
2169
2170 @item dimension@var{n}
2171 An empty variable.
2172 @end table
2173
2174 Determining the data for a (non-empty) variable is a multi-step
2175 process:
2176
2177 @enumerate
2178 @item
2179 Draw initial data from its source, for a @code{sourceVariable}, or
2180 from another named variable, for a @code{derivedVariable}.
2181
2182 @item
2183 Apply mappings from @code{valueMapEntry} elements within the
2184 @code{derivedVariable} element, if any.
2185
2186 @item
2187 Apply mappings from @code{relabel} elements within a @code{format} or
2188 @code{stringFormat} element in the @code{sourceVariable} or
2189 @code{derivedVariable} element, if any.
2190
2191 @item
2192 If the variable is a @code{sourceVariable} with a @code{labelVariable}
2193 attribute, and there were no mappings to apply in previous steps, then
2194 replace each element of the variable by the corresponding value in the
2195 label variable.
2196 @end enumerate
2197
2198 A single variable's data can be modified in two of the steps, if both
2199 @code{valueMapEntry} and @code{relabel} are used.  The following
2200 example from the corpus maps several integers to 2, then maps 2 in
2201 turn to the string ``Input'':
2202
2203 @example
2204 <derivedVariable categorical="true" dependsOn="dimension0categories"
2205                  id="dimension0group0map" value="map(dimension0group0)">
2206   <stringFormat>
2207     <relabel from="2" to="Input"/>
2208     <relabel from="10" to="Missing Value Handling"/>
2209     <relabel from="14" to="Resources"/>
2210     <relabel from="0" to=""/>
2211     <relabel from="1" to=""/>
2212     <relabel from="13" to=""/>
2213   </stringFormat>
2214   <valueMapEntry from="2;3;5;6;7;8;9" to="2"/>
2215   <valueMapEntry from="10;11" to="10"/>
2216   <valueMapEntry from="14;15" to="14"/>
2217   <valueMapEntry from="0" to="0"/>
2218   <valueMapEntry from="1" to="1"/>
2219   <valueMapEntry from="13" to="13"/>
2220 </derivedVariable>
2221 @end example
2222
2223 @menu
2224 * SPV Detail sourceVariable Element::
2225 * SPV Detail derivedVariable Element::
2226 * SPV Detail valueMapEntry Element::
2227 @end menu
2228
2229 @node SPV Detail sourceVariable Element
2230 @subsubsection The @code{sourceVariable} Element
2231
2232 @example
2233 sourceVariable
2234    :id
2235    :categorical=(true)
2236    :source
2237    :domain=ref categoricalDomain?
2238    :sourceName
2239    :dependsOn=ref sourceVariable?
2240    :label?
2241    :labelVariable=ref sourceVariable?
2242 => variable_extension* (format | stringFormat)?
2243 @end example
2244
2245 This element defines a variable whose data comes from the
2246 @file{tableData.bin} member that corresponds to this @file{.xml}.
2247
2248 This element has the following attributes.
2249
2250 @defvr {Attribute} id
2251 An @code{id} is always present because this element exists to be
2252 referenced from other elements.
2253 @end defvr
2254
2255 @defvr {Attribute} categorical
2256 Always set to @code{true}.
2257 @end defvr
2258
2259 @defvr {Attribute} source
2260 Always set to @code{tableData}, the @code{source-name} in the
2261 corresponding @file{tableData.bin} member (@pxref{SPV Legacy Member
2262 Metadata}).
2263 @end defvr
2264
2265 @defvr {Attribute} sourceName
2266 The name of a variable within the source, corresponding to the
2267 @code{variable-name} in the @file{tableData.bin} member (@pxref{SPV
2268 Legacy Member Numeric Data}).
2269 @end defvr
2270
2271 @defvr {Attribute} label
2272 The variable label, if any.
2273 @end defvr
2274
2275 @defvr {Attribute} labelVariable
2276 The @code{variable-name} of a variable whose string values correspond
2277 one-to-one with the values of this variable and are suitable for use
2278 as value labels.
2279 @end defvr
2280
2281 @defvr {Attribute} dependsOn
2282 This attribute doesn't affect the display of a table.
2283 @end defvr
2284
2285 @node SPV Detail derivedVariable Element
2286 @subsubsection The @code{derivedVariable} Element
2287
2288 @example
2289 derivedVariable
2290    :id
2291    :categorical=(true)
2292    :value
2293    :dependsOn=ref sourceVariable?
2294 => variable_extension* (format | stringFormat)? valueMapEntry*
2295 @end example
2296
2297 Like @code{sourceVariable}, this element defines a variable whose
2298 values can be used elsewhere in the visualization.  Instead of being
2299 read from a data source, the variable's data are defined by a
2300 mathematical expression.
2301
2302 This element has the following attributes.
2303
2304 @defvr {Attribute} id
2305 An @code{id} is always present because this element exists to be
2306 referenced from other elements.
2307 @end defvr
2308
2309 @defvr {Attribute} categorical
2310 Always set to @code{true}.
2311 @end defvr
2312
2313 @defvr {Attribute} value
2314 An expression that defines the variable's value.  In theory this could
2315 be an arbitrary expression in terms of constants, functions, and other
2316 variables, e.g.@: @math{(@var{var1} + @var{var2}) / 2}.  In practice,
2317 the corpus contains only the following forms of expressions:
2318
2319 @table @code
2320 @item constant(0)
2321 @itemx constant(@var{variable})
2322 All zeros.  The reason why a variable is sometimes named is unknown.
2323 Sometimes the ``variable name'' has spaces in it.
2324
2325 @item map(@var{variable})
2326 Transforms the values in the named @var{variable} using the
2327 @code{valueMapEntry}s contained within the element.
2328 @end table
2329 @end defvr
2330
2331 @defvr {Attribute} dependsOn
2332 This attribute doesn't affect the display of a table.
2333 @end defvr
2334
2335 @node SPV Detail valueMapEntry Element
2336 @subsubsection The @code{valueMapEntry} Element
2337
2338 @example
2339 valueMapEntry :from :to => EMPTY
2340 @end example
2341
2342 A @code{valueMapEntry} element defines a mapping from one or more
2343 values of a source expression to a target value.  (In the corpus, the
2344 source expression is always just the name of a variable.)  Each target
2345 value requires a separate @code{valueMapEntry}.  If multiple source
2346 values map to the same target value, they can be combined or separate.
2347
2348 In the corpus, all of the source and target values are integers.
2349
2350 @code{valueMapEntry} has the following attributes.
2351
2352 @defvr {Attribute} from
2353 A source value, or multiple source values separated by semicolons,
2354 e.g.@: @code{0} or @code{13;14;15;16}.
2355 @end defvr
2356
2357 @defvr {Attribute} to
2358 The target value, e.g.@: @code{0}.
2359 @end defvr
2360
2361 @node SPV Detail extension Element
2362 @subsection The @code{extension} Element
2363
2364 This is a general-purpose ``extension'' element.  Readers that don't
2365 understand a given extension should be able to safely ignore it.  The
2366 attributes on this element, and their meanings, vary based on the
2367 context.  Each known usage is described separately below.  The current
2368 extensions use attributes exclusively, without any nested elements.
2369
2370 @subsubheading @code{container} Parent Element
2371
2372 @example
2373 extension[container_extension] :combinedFootnotes=(true) => EMPTY
2374 @end example
2375
2376 With @code{container} as its parent element, @code{extension} has the
2377 following attributes.
2378
2379 @defvr {Attribute} combinedFootnotes
2380 Always set to @code{true} in the corpus.
2381 @end defvr
2382
2383 @subsubheading @code{sourceVariable} and @code{derivedVariable} Parent Element
2384
2385 @example
2386 extension[variable_extension] :from :helpId => EMPTY
2387 @end example
2388
2389 With @code{sourceVariable} or @code{derivedVariable} as its parent
2390 element, @code{extension} has the following attributes.  A given
2391 parent element often contains several @code{extension} elements that
2392 specify the meaning of the source data's variables or sources, e.g.@:
2393
2394 @example
2395 <extension from="0" helpId="corrected_model"/>
2396 <extension from="3" helpId="error"/>
2397 <extension from="4" helpId="total_9"/>
2398 <extension from="5" helpId="corrected_total"/>
2399 @end example
2400
2401 More commonly they are less helpful, e.g.@:
2402
2403 @example
2404 <extension from="0" helpId="notes"/>
2405 <extension from="1" helpId="notes"/>
2406 <extension from="2" helpId="notes"/>
2407 <extension from="5" helpId="notes"/>
2408 <extension from="6" helpId="notes"/>
2409 <extension from="7" helpId="notes"/>
2410 <extension from="8" helpId="notes"/>
2411 <extension from="12" helpId="notes"/>
2412 <extension from="13" helpId="no_help"/>
2413 <extension from="14" helpId="notes"/>
2414 @end example
2415
2416 @defvr {Attribute} from
2417 An integer or a name like ``dimension0''.
2418 @end defvr
2419
2420 @defvr {Attribute} helpId
2421 An identifier.
2422 @end defvr
2423
2424 @node SPV Detail graph Element
2425 @subsection The @code{graph} Element
2426
2427 @example
2428 graph
2429    :cellStyle=ref style
2430    :style=ref style
2431 => location+ coordinates faceting facetLayout interval
2432
2433 coordinates => EMPTY
2434 @end example
2435
2436 @code{graph} has the following attributes.
2437
2438 @defvr {Attribute} cellStyle
2439 @defvrx {Attribute} style
2440 Each of these is the @code{id} of a @code{style} element (@pxref{SPV
2441 Detail style Element}).  The former is the default style for
2442 individual cells, the latter for the entire table.
2443 @end defvr
2444
2445 @node SPV Detail location Element
2446 @subsection The @code{location} Element
2447
2448 @example
2449 location
2450    :part=(height | width | top | bottom | left | right)
2451    :method=(sizeToContent | attach | fixed | same)
2452    :min=dimension?
2453    :max=dimension?
2454    :target=ref (labelFrame | graph | container)?
2455    :value?
2456 => EMPTY
2457 @end example
2458
2459 Each instance of this element specifies where some part of the table
2460 frame is located.  All the examples in the corpus have four instances
2461 of this element, one for each of the parts @code{height},
2462 @code{width}, @code{left}, and @code{top}.  Some examples in the
2463 corpus add a fifth for part @code{bottom}, even though it is not clear
2464 how all of @code{top}, @code{bottom}, and @code{height} can be honored
2465 at the same time.  In any case, @code{location} seems to have little
2466 importance in representing tables; a reader can safely ignore it.
2467
2468 @defvr {Attribute} part
2469 The part of the table being located.
2470 @end defvr
2471
2472 @defvr {Attribute} method
2473 How the location is determined:
2474
2475 @table @code
2476 @item sizeToContent
2477 Based on the natural size of the table.  Observed only for
2478 parts @code{height} and @code{width}.
2479
2480 @item attach
2481 Based on the location specified in @code{target}.  Observed only for
2482 parts @code{top} and @code{bottom}.
2483
2484 @item fixed
2485 Using the value in @code{value}.  Observed only for parts @code{top},
2486 @code{bottom}, and @code{left}.
2487
2488 @item same
2489 Same as the specified @code{target}.  Observed only for part
2490 @code{left}.
2491 @end table
2492 @end defvr
2493
2494 @defvr {Attribute} min
2495 Minimum size.  Only observed with value @code{100pt}.  Only observed
2496 for part @code{width}.
2497 @end defvr
2498
2499 @defvr {Dependent} target
2500 Required when @code{method} is @code{attach} or @code{same}, not
2501 observed otherwise.  This identifies an element to attach to.
2502 Observed with the ID of @code{title}, @code{footnote}, @code{graph},
2503 and other elements.
2504 @end defvr
2505
2506 @defvr {Dependent} value
2507 Required when @code{method} is @code{fixed}, not observed otherwise.
2508 Observed values are @code{0%}, @code{0px}, @code{1px}, and @code{3px}
2509 on parts @code{top} and @code{left}, and @code{100%} on part
2510 @code{bottom}.
2511 @end defvr
2512
2513 @node SPV Detail faceting Element
2514 @subsection The @code{faceting} Element
2515
2516 @example
2517 faceting => layer[layers1]* cross layer[layers2]*
2518
2519 cross => (unity | nest) (unity | nest)
2520
2521 unity => EMPTY
2522
2523 nest => variableReference[vars]+
2524
2525 variableReference :ref=ref (sourceVariable | derivedVariable) => EMPTY
2526
2527 layer
2528    :variable=ref (sourceVariable | derivedVariable)
2529    :value
2530    :visible=bool?
2531    :method[layer_method]=(nest)?
2532    :titleVisible=bool?
2533 => EMPTY
2534 @end example
2535
2536 The @code{faceting} element describes the row, column, and layer
2537 structure of the table.  Its @code{cross} child determines the row and
2538 column structure, and each @code{layer} child (if any) represents a
2539 layer.  Layers may appear before or after @code{cross}.
2540
2541 The @code{cross} element describes the row and column structure of the
2542 table.  It has exactly two children, the first of which describes the
2543 table's columns and the second the table's rows.  Each child is a
2544 @code{nest} element if the table has any dimensions along the axis in
2545 question, otherwise a @code{unity} element.
2546
2547 A @code{nest} element contains of one or more dimensions listed from
2548 innermost to outermost, each represented by @code{variableReference}
2549 child elements.  Each variable in a dimension is listed in order.
2550 @xref{SPV Detail Variable Elements}, for information on the variables
2551 that comprise a dimension.
2552
2553 A @code{nest} can contain a single dimension, e.g.:
2554
2555 @example
2556 <nest>
2557   <variableReference ref="dimension0categories"/>
2558   <variableReference ref="dimension0group0"/>
2559   <variableReference ref="dimension0"/>
2560 </nest>
2561 @end example
2562
2563 @noindent
2564 A @code{nest} can contain multiple dimensions, e.g.:
2565
2566 @example
2567 <nest>
2568   <variableReference ref="dimension1categories"/>
2569   <variableReference ref="dimension1group0"/>
2570   <variableReference ref="dimension1"/>
2571   <variableReference ref="dimension0categories"/>
2572   <variableReference ref="dimension0"/>
2573 </nest>
2574 @end example
2575
2576 A @code{nest} may have no dimensions, in which case it still has one
2577 @code{variableReference} child, which references a
2578 @code{derivedVariable} whose @code{value} attribute is
2579 @code{constant(0)}.  In the corpus, such a @code{derivedVariable} has
2580 @code{row} or @code{column}, respectively, as its @code{id}.  This is
2581 equivalent to using a @code{unity} element in place of @code{nest}.
2582
2583 A @code{variableReference} element refers to a variable through its
2584 @code{ref} attribute.
2585
2586 Each @code{layer} element represents a dimension, e.g.:
2587
2588 @example
2589 <layer value="0" variable="dimension0categories" visible="true"/>
2590 <layer value="dimension0" variable="dimension0" visible="false"/>
2591 @end example
2592
2593 @noindent
2594 @code{layer} has the following attributes.
2595
2596 @defvr {Attribute} variable
2597 Refers to a @code{sourceVariable} or @code{derivedVariable} element.
2598 @end defvr
2599
2600 @defvr {Attribute} value
2601 The value to select.  For a category variable, this is always
2602 @code{0}; for a data variable, it is the same as the @code{variable}
2603 attribute.
2604 @end defvr
2605
2606 @defvr {Attribute} visible
2607 Whether the layer is visible.  Generally, category layers are visible
2608 and data layers are not, but sometimes this attribute is omitted.
2609 @end defvr
2610
2611 @defvr {Attribute} method
2612 When present, this is always @code{nest}.
2613 @end defvr
2614
2615 @node SPV Detail facetLayout Element
2616 @subsection The @code{facetLayout} Element
2617
2618 @example
2619 facetLayout => tableLayout setCellProperties[scp1]*
2620                facetLevel+ setCellProperties[scp2]*
2621
2622 tableLayout
2623    :verticalTitlesInCorner=bool
2624    :style=ref style?
2625    :fitCells=(ticks both)?
2626 => EMPTY
2627 @end example
2628
2629 The @code{facetLayout} element and its descendants control styling for
2630 the table.
2631
2632 Its @code{tableLayout} child has the following attributes
2633
2634 @defvr {Attribute} verticalTitlesInCorner
2635 If true, in the absence of corner text, row headings will be displayed
2636 in the corner.
2637 @end defvr
2638
2639 @defvr {Attribute} style
2640 Refers to a @code{style} element.
2641 @end defvr
2642
2643 @defvr {Attribute} fitCells
2644 Meaning unknown.
2645 @end defvr
2646
2647 @subsubheading The @code{facetLevel} Element
2648
2649 @example
2650 facetLevel :level=int :gap=dimension? => axis
2651
2652 axis :style=ref style => label? majorTicks
2653
2654 majorTicks
2655    :labelAngle=int
2656    :length=dimension
2657    :style=ref style
2658    :tickFrameStyle=ref style
2659    :labelFrequency=int?
2660    :stagger=bool?
2661 => gridline?
2662
2663 gridline
2664    :style=ref style
2665    :zOrder=int
2666 => EMPTY
2667 @end example
2668
2669 Each @code{facetLevel} describes a @code{variableReference} or
2670 @code{layer}, and a table has one @code{facetLevel} element for
2671 each such element.  For example, an SPV detail member that contains
2672 four @code{variableReference} elements and two @code{layer} elements
2673 will contain six @code{facetLevel} elements.
2674
2675 In the corpus, @code{facetLevel} elements and the elements that they
2676 describe are always in the same order.  The correspondence may also be
2677 observed in two other ways.  First, one may use the @code{level}
2678 attribute, described below.  Second, in the corpus, a
2679 @code{facetLevel} always has an @code{id} that is the same as the
2680 @code{id} of the element it describes with @code{_facetLevel}
2681 appended.  One should not formally rely on this, of course, but it is
2682 usefully indicative.
2683
2684 @defvr {Attribute} level
2685 A 1-based index into the @code{variableReference} and @code{layer}
2686 elements, e.g.@: a @code{facetLayout} with a @code{level} of 1
2687 describes the first @code{variableReference} in the SPV detail member,
2688 and in a member with four @code{variableReference} elements, a
2689 @code{facetLayout} with a @code{level} of 5 describes the first
2690 @code{layer} in the member.
2691 @end defvr
2692
2693 @defvr {Attribute} gap
2694 Always observed as @code{0pt}.
2695 @end defvr
2696
2697 Each @code{facetLevel} contains an @code{axis}, which in turn may
2698 contain a @code{label} for the @code{facetLevel} (@pxref{SPV Detail
2699 label Element}) and does contain a @code{majorTicks} element.
2700
2701 @defvr {Attribute} labelAngle
2702 Normally 0.  The value -90 causes inner column or outer row labels to
2703 be rotated vertically.
2704 @end defvr
2705
2706 @defvr {Attribute} style
2707 @defvrx {Attribute} tickFrameStyle
2708 Each refers to a @code{style} element.  @code{style} is the style of
2709 the tick labels, @code{tickFrameStyle} the style for the frames around
2710 the labels.
2711 @end defvr
2712
2713 @node SPV Detail label Element
2714 @subsection The @code{label} Element
2715
2716 @example
2717 label
2718    :style=ref style
2719    :textFrameStyle=ref style?
2720    :purpose=(title | subTitle | subSubTitle | layer | footnote)?
2721 => text+ | descriptionGroup
2722
2723 descriptionGroup
2724    :target=ref faceting
2725    :separator?
2726 => (description | text)+
2727
2728 description :name=(variable | value) => EMPTY
2729
2730 text
2731    :usesReference=int?
2732    :definesReference=int?
2733    :position=(subscript | superscript)?
2734    :style=ref style
2735 => TEXT
2736 @end example
2737
2738 This element represents a label on some aspect of the table.
2739
2740 @defvr {Attribute} style
2741 @defvrx {Attribute} textFrameStyle
2742 Each of these refers to a @code{style} element.  @code{style} is the
2743 style of the label text, @code{textFrameStyle} the style for the frame
2744 around the label.
2745 @end defvr
2746
2747 @defvr {Attribute} purpose
2748 The kind of entity being labeled.
2749 @end defvr
2750
2751 A @code{descriptionGroup} concatenates one or more elements to form a
2752 label.  Each element can be a @code{text} element, which contains
2753 literal text, or a @code{description} element that substitutes a value
2754 or a variable name.
2755
2756 @defvr {Attribute} target
2757 The @code{id} of an element being described.  In the corpus, this is
2758 always @code{faceting}.
2759 @end defvr
2760
2761 @defvr {Attribute} separator
2762 A string to separate the description of multiple groups, if the
2763 @code{target} has more than one.  In the corpus, this is always a
2764 new-line.
2765 @end defvr
2766
2767 Typical contents for a @code{descriptionGroup} are a value by itself:
2768 @example
2769 <description name="value"/>
2770 @end example
2771 @noindent or a variable and its value, separated by a colon:
2772 @example
2773 <description name="variable"/><text>:</text><description name="value"/>
2774 @end example
2775
2776 A @code{description} is like a macro that expands to some property of
2777 the target of its parent @code{descriptionGroup}.  The @code{name}
2778 attribute specifies the property.
2779
2780 @node SPV Detail setCellProperties Element
2781 @subsection The @code{setCellProperties} Element
2782
2783 @example
2784 setCellProperties
2785    :applyToConverse=bool?
2786 => (setStyle | setFrameStyle | setFormat | setMetaData)* union[union_]?
2787 @end example
2788
2789 The @code{setCellProperties} element sets style properties of cells or
2790 row or column labels.
2791
2792 Interpreting @code{setCellProperties} requires answering two
2793 questions: which cells or labels to style, and what styles to use.
2794
2795 @subsubheading Which Cells?
2796
2797 @example
2798 union => intersect+
2799
2800 intersect => where+ | intersectWhere | alternating | EMPTY
2801
2802 where
2803    :variable=ref (sourceVariable | derivedVariable)
2804    :include
2805 => EMPTY
2806
2807 intersectWhere
2808    :variable=ref (sourceVariable | derivedVariable)
2809    :variable2=ref (sourceVariable | derivedVariable)
2810 => EMPTY
2811
2812 alternating => EMPTY
2813 @end example
2814
2815 When @code{union} is present with @code{intersect} children, each of
2816 those children specifies a group of cells that should be styled, and
2817 the total group is all those cells taken together.  When @code{union}
2818 is absent, every cell is styled.  One attribute on
2819 @code{setCellProperties} affects the choice of cells:
2820
2821 @defvr {Attribute} applyToConverse
2822 If true, this inverts the meaning of the cell selection: the selected
2823 cells are the ones @emph{not} designated.  This is confusing, given
2824 the additional restrictions of @code{union}, but in the corpus
2825 @code{applyToConverse} is never present along with @code{union}.
2826 @end defvr
2827
2828 An @code{intersect} specifies restrictions on the cells to be matched.
2829 Each @code{where} child specifies which values of a given variable to
2830 include.  The attributes of @code{intersect} are:
2831
2832 @defvr {Attribute} variable
2833 Refers to a variable, e.g.@: @code{dimension0categories}.  Only
2834 ``categories'' variables make sense here, but other variables, e.g.@:
2835 @code{dimension0group0map}, are sometimes seen.  The reader may ignore
2836 these.
2837 @end defvr
2838
2839 @defvr {Attribute} include
2840 A value, or multiple values separated by semicolons,
2841 e.g.@: @code{0} or @code{13;14;15;16}.
2842 @end defvr
2843
2844 PSPP ignores @code{setCellProperties} when @code{intersectWhere} is
2845 present.
2846
2847 @subsubheading What Styles?
2848
2849 @example
2850 setStyle
2851    :target=ref (labeling | graph | interval | majorTicks)
2852    :style=ref style
2853 => EMPTY
2854
2855 setMetaData :target=ref graph :key :value => EMPTY
2856
2857 setFormat
2858    :target=ref (majorTicks | labeling)
2859    :reset=bool?
2860 => format | numberFormat | stringFormat+ | dateTimeFormat | elapsedTimeFormat
2861
2862 setFrameStyle
2863    :style=ref style
2864    :target=ref majorTicks
2865 => EMPTY
2866 @end example
2867
2868 The @code{set*} children of @code{setCellProperties} determine the
2869 styles to set.
2870
2871 When @code{setCellProperties} contains a @code{setFormat} whose
2872 @code{target} references a @code{labeling} element, or if it contains
2873 a @code{setStyle} that references a @code{labeling} or @code{interval}
2874 element, the @code{setCellProperties} sets the style for table cells.
2875 The format from the @code{setFormat}, if present, replaces the cells'
2876 format.  The style from the @code{setStyle} that references
2877 @code{labeling}, if present, replaces the label's font and cell
2878 styles, except that the background color is taken instead from the
2879 @code{interval}'s style, if present.
2880
2881 When @code{setCellProperties} contains a @code{setFormat} whose
2882 @code{target} references a @code{majorTicks} element, or if it
2883 contains a @code{setStyle} whose @code{target} references a
2884 @code{majorTicks}, or if it contains a @code{setFrameStyle} element,
2885 the @code{setCellProperties} sets the style for row or column labels.
2886 In this case, the @code{setCellProperties} always contains a single
2887 @code{where} element whose @code{variable} designates the variable
2888 whose labels are to be styled.  The format from the @code{setFormat},
2889 if present, replaces the labels' format.  The style from the
2890 @code{setStyle} that references @code{majorTicks}, if present,
2891 replaces the labels' font and cell styles, except that the background
2892 color is taken instead from the @code{setFrameStyle}'s style, if
2893 present.
2894
2895 When @code{setCellProperties} contains a @code{setStyle} whose
2896 @code{target} references a @code{graph} element, and one that
2897 references a @code{labeling} element, and the @code{union} element
2898 contains @code{alternating}, the @code{setCellProperties} sets the
2899 alternate foreground and background colors for the data area.  The
2900 foreground color is taken from the style referenced by the
2901 @code{setStyle} that targets the @code{graph}, the background color
2902 from the @code{setStyle} for @code{labeling}.
2903
2904 A reader may ignore a @code{setCellProperties} that only contains
2905 @code{setMetaData}, as well as @code{setMetaData} within other
2906 @code{setCellProperties}.
2907
2908 A reader may ignore a @code{setCellProperties} whose only @code{set*}
2909 child is a @code{setStyle} that targets the @code{graph} element.
2910
2911 @subsubheading The @code{setStyle} Element
2912
2913 @example
2914 setStyle
2915    :target=ref (labeling | graph | interval | majorTicks)
2916    :style=ref style
2917 => EMPTY
2918 @end example
2919
2920 This element associates a style with the target.
2921
2922 @defvr {Attribute} target
2923 The @code{id} of an element whose style is to be set.
2924 @end defvr
2925
2926 @defvr {Attribute} style
2927 The @code{id} of a @code{style} element that identifies the style to
2928 set on the target.
2929 @end defvr
2930
2931 @node SPV Detail setFormat Element
2932 @subsection The @code{setFormat} Element
2933
2934 @example
2935 setFormat
2936    :target=ref (majorTicks | labeling)
2937    :reset=bool?
2938 => format | numberFormat | stringFormat+ | dateTimeFormat | elapsedTimeFormat
2939 @end example
2940
2941 This element sets the format of the target, ``format'' in this case
2942 meaning the SPSS print format for a variable.
2943
2944 The details of this element vary depending on the schema version, as
2945 declared in the root @code{visualization} element's @code{version}
2946 attribute (@pxref{SPV Detail visualization Element}).  A reader can
2947 interpret the content without knowing the schema version.
2948
2949 The @code{setFormat} element itself has the following attributes.
2950
2951 @defvr {Attribute} target
2952 Refers to an element whose style is to be set.
2953 @end defvr
2954
2955 @defvr {Attribute} reset
2956 If this is @code{true}, this format replaces the target's previous
2957 format.  If it is @code{false}, the modifies the previous format.
2958 @end defvr
2959
2960 @menu
2961 * SPV Detail numberFormat Element::
2962 * SPV Detail stringFormat Element::
2963 * SPV Detail dateTimeFormat Element::
2964 * SPV Detail elapsedTimeFormat Element::
2965 * SPV Detail format Element::
2966 * SPV Detail affix Element::
2967 @end menu
2968
2969 @node SPV Detail numberFormat Element
2970 @subsubsection The @code{numberFormat} Element
2971
2972 @example
2973 numberFormat
2974    :minimumIntegerDigits=int?
2975    :maximumFractionDigits=int?
2976    :minimumFractionDigits=int?
2977    :useGrouping=bool?
2978    :scientific=(onlyForSmall | whenNeeded | true | false)?
2979    :small=real?
2980    :prefix?
2981    :suffix?
2982 => affix*
2983 @end example
2984
2985 Specifies a format for displaying a number.  The available options are
2986 a superset of those available from PSPP print formats.  PSPP chooses a
2987 print format type for a @code{numberFormat} as follows:
2988
2989 @enumerate
2990 @item
2991 If @code{scientific} is @code{true}, uses @code{E} format.
2992
2993 @item
2994 If @code{prefix} is @code{$}, uses @code{DOLLAR} format.
2995
2996 @item
2997 If @code{suffix} is @code{%}, uses @code{PCT} format.
2998
2999 @item
3000 If @code{useGrouping} is @code{true}, uses @code{COMMA} format.
3001
3002 @item
3003 Otherwise, uses @code{F} format.
3004 @end enumerate
3005
3006 For translating to a print format, PSPP uses
3007 @code{maximumFractionDigits} as the number of decimals, unless that
3008 attribute is missing or out of the range [0,15], in which case it uses
3009 2 decimals.
3010
3011 @defvr {Attribute} minimumIntegerDigits
3012 Minimum number of digits to display before the decimal point.  Always
3013 observed as @code{0}.
3014 @end defvr
3015
3016 @defvr {Attribute} maximumFractionDigits
3017 @defvrx {Attribute} minimumFractionDigits
3018 Maximum or minimum, respectively, number of digits to display after
3019 the decimal point.  The observed values of each attribute range from 0
3020 to 9.
3021 @end defvr
3022
3023 @defvr {Attribute} useGrouping
3024 Whether to use the grouping character to group digits in large
3025 numbers.
3026 @end defvr
3027
3028 @defvr {Attribute} scientific
3029 This attribute controls when and whether the number is formatted in
3030 scientific notation.  It takes the following values:
3031
3032 @table @code
3033 @item onlyForSmall
3034 Use scientific notation only when the number's magnitude is smaller
3035 than the value of the @code{small} attribute.
3036
3037 @item whenNeeded
3038 Use scientific notation when the number will not otherwise fit in the
3039 available space.
3040
3041 @item true
3042 Always use scientific notation.  Not observed in the corpus.
3043
3044 @item false
3045 Never use scientific notation.  A number that won't otherwise fit will
3046 be replaced by an error indication (see the @code{errorCharacter}
3047 attribute).  Not observed in the corpus.
3048 @end table
3049 @end defvr
3050
3051 @defvr {Attribute} small
3052 Only present when the @code{scientific} attribute is
3053 @code{onlyForSmall}, this is a numeric magnitude below which the
3054 number will be formatted in scientific notation.  The values @code{0}
3055 and @code{0.0001} have been observed.  The value @code{0} seems like a
3056 pathological choice, since no real number has a magnitude less than 0;
3057 perhaps in practice such a choice is equivalent to setting
3058 @code{scientific} to @code{false}.
3059 @end defvr
3060
3061 @defvr {Attribute} prefix
3062 @defvrx {Attribute} suffix
3063 Specifies a prefix or a suffix to apply to the formatted number.  Only
3064 @code{suffix} has been observed, with value @samp{%}.
3065 @end defvr
3066
3067 @node SPV Detail stringFormat Element
3068 @subsubsection The @code{stringFormat} Element
3069
3070 @example
3071 stringFormat => relabel* affix*
3072
3073 relabel :from=real :to => EMPTY
3074 @end example
3075
3076 The @code{stringFormat} element specifies how to display a string.  By
3077 default, a string is displayed verbatim, but @code{relabel} can change
3078 it.
3079
3080 The @code{relabel} element appears as a child of @code{stringFormat}
3081 (and of @code{format}, when it is used to format strings).  It
3082 specifies how to display a given value.  It is used to implement value
3083 labels and to display the system-missing value in a human-readable
3084 way.  It has the following attributes:
3085
3086 @defvr {Attribute} from
3087 The value to map.  In the corpus this is an integer or the
3088 system-missing value @code{-1.797693134862316E300}.
3089 @end defvr
3090
3091 @defvr {Attribute} to
3092 The string to display in place of the value of @code{from}.  In the
3093 corpus this is a wide variety of value labels; the system-missing
3094 value is mapped to @samp{.}.
3095 @end defvr
3096
3097 @node SPV Detail dateTimeFormat Element
3098 @subsubsection The @code{dateTimeFormat} Element
3099
3100 @example
3101 dateTimeFormat
3102    :baseFormat[dt_base_format]=(date | time | dateTime)
3103    :separatorChars?
3104    :mdyOrder=(dayMonthYear | monthDayYear | yearMonthDay)?
3105    :showYear=bool?
3106    :yearAbbreviation=bool?
3107    :showQuarter=bool?
3108    :quarterPrefix?
3109    :quarterSuffix?
3110    :showMonth=bool?
3111    :monthFormat=(long | short | number | paddedNumber)?
3112    :showWeek=bool?
3113    :weekPadding=bool?
3114    :weekSuffix?
3115    :showDayOfWeek=bool?
3116    :dayOfWeekAbbreviation=bool?
3117    :dayPadding=bool?
3118    :dayOfMonthPadding=bool?
3119    :hourPadding=bool?
3120    :minutePadding=bool?
3121    :secondPadding=bool?
3122    :showDay=bool?
3123    :showHour=bool?
3124    :showMinute=bool?
3125    :showSecond=bool?
3126    :showMillis=bool?
3127    :dayType=(month | year)?
3128    :hourFormat=(AMPM | AS_24 | AS_12)?
3129 => affix*
3130 @end example
3131
3132 This element appears only in schema version 2.5 and earlier
3133 (@pxref{SPV Detail visualization Element}).
3134
3135 Data to be formatted in date formats is stored as strings in legacy
3136 data, in the format @code{yyyy-mm-ddTHH:MM:SS.SSS} and must be parsed
3137 and reformatted by the reader.
3138
3139 The following attribute is required.
3140
3141 @defvr {Attribute} baseFormat
3142 Specifies whether a date and time are both to be displayed, or just
3143 one of them.
3144 @end defvr
3145
3146 Many of the attributes' meanings are obvious.  The following seem to
3147 be worth documenting.
3148
3149 @defvr {Attribute} separatorChars
3150 Exactly four characters.  In order, these are used for: decimal point,
3151 grouping, date separator, time separator.  Always @samp{.,-:}.
3152 @end defvr
3153
3154 @defvr {Attribute} mdyOrder
3155 Within a date, the order of the days, months, and years.
3156 @code{dayMonthYear} is the only observed value, but one would expect
3157 that @code{monthDayYear} and @code{yearMonthDay} to be reasonable as
3158 well.
3159 @end defvr
3160
3161 @defvr {Attribute} showYear
3162 @defvrx {Attribute} yearAbbreviation
3163 Whether to include the year and, if so, whether the year should be
3164 shown abbreviated, that is, with only 2 digits.  Each is @code{true}
3165 or @code{false}; only values of @code{true} and @code{false},
3166 respectively, have been observed.
3167 @end defvr
3168
3169 @defvr {Attribute} showMonth
3170 @defvrx {Attribute} monthFormat
3171 Whether to include the month (@code{true} or @code{false}) and, if so,
3172 how to format it.  @code{monthFormat} is one of the following:
3173
3174 @table @code
3175 @item long
3176 The full name of the month, e.g.@: in an English locale,
3177 @code{September}.
3178
3179 @item short
3180 The abbreviated name of the month, e.g.@: in an English locale,
3181 @code{Sep}.
3182
3183 @item number
3184 The number representing the month, e.g.@: 9 for September.
3185
3186 @item paddedNumber
3187 A two-digit number representing the month, e.g.@: 09 for September.
3188 @end table
3189
3190 Only values of @code{true} and @code{short}, respectively, have been
3191 observed.
3192 @end defvr
3193
3194 @defvr {Attribute} dayType
3195 This attribute is always @code{month} in the corpus, specifying that
3196 the day of the month is to be displayed; a value of @code{year} is
3197 supposed to indicate that the day of the year, where 1 is January 1,
3198 is to be displayed instead.
3199 @end defvr
3200
3201 @defvr {Attribute} hourFormat
3202 @code{hourFormat}, if present, is one of:
3203
3204 @table @code
3205 @item AMPM
3206 The time is displayed with an @code{am} or @code{pm} suffix, e.g.@:
3207 @code{10:15pm}.
3208
3209 @item AS_24
3210 The time is displayed in a 24-hour format, e.g.@: @code{22:15}.
3211
3212 This is the only value observed in the corpus.
3213
3214 @item AS_12
3215 The time is displayed in a 12-hour format, without distinguishing
3216 morning or evening, e.g.@: @code{10;15}.
3217 @end table
3218
3219 @code{hourFormat} is sometimes present for @code{elapsedTime} formats,
3220 which is confusing since a time duration does not have a concept of AM
3221 or PM.  This might indicate a bug in the code that generated the XML
3222 in the corpus, or it might indicate that @code{elapsedTime} is
3223 sometimes used to format a time of day.
3224 @end defvr
3225
3226 For a @code{baseFormat} of @code{date}, PSPP chooses a print format
3227 type based on the following rules:
3228
3229 @enumerate
3230 @item
3231 If @code{showQuarter} is true: @code{QYR}.
3232
3233 @item
3234 Otherwise, if @code{showWeek} is true: @code{WKYR}.
3235
3236 @item
3237 Otherwise, if @code{mdyOrder} is @code{dayMonthYear}:
3238
3239 @enumerate a
3240 @item
3241 If @code{monthFormat} is @code{number} or @code{paddedNumber}: @code{EDATE}.
3242
3243 @item
3244 Otherwise: @code{DATE}.
3245 @end enumerate
3246
3247 @item
3248 Otherwise, if @code{mdyOrder} is @code{yearMonthDay}: @code{SDATE}.
3249
3250 @item
3251 Otherwise, @code{ADATE}.
3252 @end enumerate
3253
3254 For a @code{baseFormat} of @code{dateTime}, PSPP uses @code{YMDHMS} if
3255 @code{mdyOrder} is @code{yearMonthDay} and @code{DATETIME} otherwise.
3256 For a @code{baseFormat} of @code{time}, PSPP uses @code{DTIME} if
3257 @code{showDay} is true, otherwise @code{TIME} if @code{showHour} is
3258 true, otherwise @code{MTIME}.
3259
3260 For a @code{baseFormat} of @code{date}, the chosen width is the
3261 minimum for the format type, adding 2 if @code{yearAbbreviation} is
3262 false or omitted.  For other base formats, the chosen width is the
3263 minimum for its type, plus 3 if @code{showSecond} is true, plus 4 more
3264 if @code{showMillis} is also true.  Decimals are 0 by default, or 3
3265 if @code{showMillis} is true.
3266
3267 @node SPV Detail elapsedTimeFormat Element
3268 @subsubsection The @code{elapsedTimeFormat} Element
3269
3270 @example
3271 elapsedTimeFormat
3272    :baseFormat[dt_base_format]=(date | time | dateTime)
3273    :dayPadding=bool?
3274    :hourPadding=bool?
3275    :minutePadding=bool?
3276    :secondPadding=bool?
3277    :showYear=bool?
3278    :showDay=bool?
3279    :showHour=bool?
3280    :showMinute=bool?
3281    :showSecond=bool?
3282    :showMillis=bool?
3283 => affix*
3284 @end example
3285
3286 This element specifies the way to display a time duration.
3287
3288 Data to be formatted in elapsed time formats is stored as strings in
3289 legacy data, in the format @code{H:MM:SS.SSS}, with additional hour
3290 digits as needed for long durations, and must be parsed and
3291 reformatted by the reader.
3292
3293 The following attribute is required.
3294
3295 @defvr {Attribute} baseFormat
3296 Specifies whether a day and a time are both to be displayed, or just
3297 one of them.
3298 @end defvr
3299
3300 The remaining attributes specify exactly how to display the elapsed
3301 time.
3302
3303 For @code{baseFormat} of @code{time}, PSPP converts this element to
3304 print format type @code{DTIME}; otherwise, if @code{showHour} is true,
3305 to @code{TIME}; otherwise, to @code{MTIME}.  The chosen width is the
3306 minimum for the chosen type, adding 3 if @code{showSecond} is true,
3307 adding 4 more if @code{showMillis} is also true.  Decimals are 0 by
3308 default, or 3 if @code{showMillis} is true.
3309
3310 @node SPV Detail format Element
3311 @subsubsection The @code{format} Element
3312
3313 @example
3314 format
3315    :baseFormat[f_base_format]=(date | time | dateTime | elapsedTime)?
3316    :errorCharacter?
3317    :separatorChars?
3318    :mdyOrder=(dayMonthYear | monthDayYear | yearMonthDay)?
3319    :showYear=bool?
3320    :showQuarter=bool?
3321    :quarterPrefix?
3322    :quarterSuffix?
3323    :yearAbbreviation=bool?
3324    :showMonth=bool?
3325    :monthFormat=(long | short | number | paddedNumber)?
3326    :dayPadding=bool?
3327    :dayOfMonthPadding=bool?
3328    :showWeek=bool?
3329    :weekPadding=bool?
3330    :weekSuffix?
3331    :showDayOfWeek=bool?
3332    :dayOfWeekAbbreviation=bool?
3333    :hourPadding=bool?
3334    :minutePadding=bool?
3335    :secondPadding=bool?
3336    :showDay=bool?
3337    :showHour=bool?
3338    :showMinute=bool?
3339    :showSecond=bool?
3340    :showMillis=bool?
3341    :dayType=(month | year)?
3342    :hourFormat=(AMPM | AS_24 | AS_12)?
3343    :minimumIntegerDigits=int?
3344    :maximumFractionDigits=int?
3345    :minimumFractionDigits=int?
3346    :useGrouping=bool?
3347    :scientific=(onlyForSmall | whenNeeded | true | false)?
3348    :small=real?
3349    :prefix?
3350    :suffix?
3351    :tryStringsAsNumbers=bool?
3352    :negativesOutside=bool?
3353 => relabel* affix*
3354 @end example
3355
3356 This element is the union of all of the more-specific format elements.
3357 It is interpreted in the same way as one of those format elements,
3358 using @code{baseFormat} to determine which kind of format to use.
3359
3360 There are a few attributes not present in the more specific formats:
3361
3362 @defvr {Attribute} tryStringsAsNumbers
3363 When this is @code{true}, it is supposed to indicate that string
3364 values should be parsed as numbers and then displayed according to
3365 numeric formatting rules.  However, in the corpus it is always
3366 @code{false}.
3367 @end defvr
3368
3369 @defvr {Attribute} negativesOutside
3370 If true, the negative sign should be shown before the prefix; if
3371 false, it should be shown after.
3372 @end defvr
3373
3374 @node SPV Detail affix Element
3375 @subsubsection The @code{affix} Element
3376
3377 @example
3378 affix
3379    :definesReference=int
3380    :position=(subscript | superscript)
3381    :suffix=bool
3382    :value
3383 => EMPTY
3384 @end example
3385
3386 This defines a suffix (or, theoretically, a prefix) for a formatted
3387 value.  It is used to insert a reference to a footnote.  It has the
3388 following attributes:
3389
3390 @defvr {Attribute} definesReference
3391 This specifies the footnote number as a natural number: 1 for the
3392 first footnote, 2 for the second, and so on.
3393 @end defvr
3394
3395 @defvr {Attribute} position
3396 Position for the footnote label.  Always @code{superscript}.
3397 @end defvr
3398
3399 @defvr {Attribute} suffix
3400 Whether the affix is a suffix (@code{true}) or a prefix
3401 (@code{false}).  Always @code{true}.
3402 @end defvr
3403
3404 @defvr {Attribute} value
3405 The text of the suffix or prefix.  Typically a letter, e.g.@: @code{a}
3406 for footnote 1, @code{b} for footnote 2, @enddots{}  The corpus
3407 contains other values: @code{*}, @code{**}, and a few that begin with
3408 at least one comma: @code{,b}, @code{,c}, @code{,,b}, and @code{,,c}.
3409 @end defvr
3410
3411 @node SPV Detail interval Element
3412 @subsection The @code{interval} Element
3413
3414 @example
3415 interval :style=ref style => labeling footnotes?
3416
3417 labeling
3418    :style=ref style?
3419    :variable=ref (sourceVariable | derivedVariable)
3420 => (formatting | format | footnotes)*
3421
3422 formatting :variable=ref (sourceVariable | derivedVariable) => formatMapping*
3423
3424 formatMapping :from=int => format?
3425
3426 footnotes
3427    :superscript=bool?
3428    :variable=ref (sourceVariable | derivedVariable)
3429 => footnoteMapping*
3430
3431 footnoteMapping :definesReference=int :from=int :to => EMPTY
3432 @end example
3433
3434 The @code{interval} element and its descendants determine the basic
3435 formatting and labeling for the table's cells.  These basic styles are
3436 overridden by more specific styles set using @code{setCellProperties}
3437 (@pxref{SPV Detail setCellProperties Element}).
3438
3439 The @code{style} attribute of @code{interval} itself may be ignored.
3440
3441 The @code{labeling} element may have a single @code{formatting} child.
3442 If present, its @code{variable} attribute refers to a variable whose
3443 values are format specifiers as numbers, e.g. value 0x050802 for F8.2.
3444 However, the numbers are not actually interpreted that way.  Instead,
3445 each number actually present in the variable's data is mapped by a
3446 @code{formatMapping} child of @code{formatting} to a @code{format}
3447 that specifies how to display it.
3448
3449 The @code{labeling} element may also have a @code{footnotes} child
3450 element.  The @code{variable} attribute of this element refers to a
3451 variable whose values are comma-delimited strings that list the
3452 1-based indexes of footnote references.  (Cells without any footnote
3453 references are numeric 0 instead of strings.)
3454
3455 Each @code{footnoteMapping} child of the @code{footnotes} element
3456 defines the footnote marker to be its @code{to} attribute text for the
3457 footnote whose 1-based index is given in its @code{definesReference}
3458 attribute.
3459
3460 @node SPV Detail style Element
3461 @subsection The @code{style} Element
3462
3463 @example
3464 style
3465    :color=color?
3466    :color2=color?
3467    :labelAngle=real?
3468    :border-bottom=(solid | thick | thin | double | none)?
3469    :border-top=(solid | thick | thin | double | none)?
3470    :border-left=(solid | thick | thin | double | none)?
3471    :border-right=(solid | thick | thin | double | none)?
3472    :border-bottom-color?
3473    :border-top-color?
3474    :border-left-color?
3475    :border-right-color?
3476    :font-family?
3477    :font-size?
3478    :font-weight=(regular | bold)?
3479    :font-style=(regular | italic)?
3480    :font-underline=(none | underline)?
3481    :margin-bottom=dimension?
3482    :margin-left=dimension?
3483    :margin-right=dimension?
3484    :margin-top=dimension?
3485    :textAlignment=(left | right | center | decimal | mixed)?
3486    :labelLocationHorizontal=(positive | negative | center)?
3487    :labelLocationVertical=(positive | negative | center)?
3488    :decimal-offset=dimension?
3489    :size?
3490    :width?
3491    :visible=bool?
3492 => EMPTY
3493 @end example
3494
3495 A @code{style} element has an effect only when it is referenced by
3496 another element to set some aspect of the table's style.  Most of the
3497 attributes are self-explanatory.  The rest are described below.
3498
3499 @defvr {Attribute} {color}
3500 In some cases, the text color; in others, the background color.
3501 @end defvr
3502
3503 @defvr {Attribute} {color2}
3504 Not used.
3505 @end defvr
3506
3507 @defvr {Attribute} {labelAngle}
3508 Normally 0.  The value -90 causes inner column or outer row labels to
3509 be rotated vertically.
3510 @end defvr
3511
3512 @defvr {Attribute} {labelLocationHorizontal}
3513 Not used.
3514 @end defvr
3515
3516 @defvr {Attribute} {labelLocationVertical}
3517 The value @code{positive} corresponds to vertically aligning text to
3518 the top of a cell, @code{negative} to the bottom, @code{center} to the
3519 middle.
3520 @end defvr
3521
3522 @node SPV Detail labelFrame Element
3523 @subsection The @code{labelFrame} Element
3524
3525 @example
3526 labelFrame :style=ref style => location+ label? paragraph?
3527
3528 paragraph :hangingIndent=dimension? => EMPTY
3529 @end example
3530
3531 A @code{labelFrame} element specifies content and style for some
3532 aspect of a table.  Only @code{labelFrame} elements that have a
3533 @code{label} child are important.  The @code{purpose} attribute in the
3534 @code{label} determines what the @code{labelFrame} affects:
3535
3536 @table @code
3537 @item title
3538 The table's title and its style.
3539
3540 @item subTitle
3541 The table's caption and its style.
3542
3543 @item footnote
3544 The table's footnotes and the style for the footer area.
3545
3546 @item layer
3547 The style for the layer area.
3548
3549 @item subSubTitle
3550 Ignored.
3551 @end table
3552
3553 The @code{style} attribute references the style to use for the area.
3554
3555 The @code{label}, if present, specifies the text to put into the title
3556 or caption or footnotes.  For footnotes, the label has two @code{text}
3557 children for every footnote, each of which has a @code{usesReference}
3558 attribute identifying the 1-based index of a footnote.  The first,
3559 third, fifth, @dots{} @code{text} child specifies the content for a
3560 footnote; the second, fourth, sixth, @dots{} child specifies the
3561 marker.  Content tends to end in a new-line, which the reader may wish
3562 to trim; similarly, markers tend to end in @samp{.}.
3563
3564 The @code{paragraph}, if present, may be ignored, since it is always
3565 empty.
3566
3567 @node SPV Detail Legacy Properties
3568 @subsection Legacy Properties
3569
3570 The detail XML format has features for styling most of the aspects of
3571 a table.  It also inherits defaults for many aspects from structure
3572 XML, which has the following @code{tableProperties} element:
3573
3574 @example
3575 tableProperties
3576 => generalProperties footnoteProperties cellFormatProperties borderProperties printingProperties
3577
3578 generalProperties
3579    :hideEmptyRows=bool?
3580    :maximumColumnWidth=dimension?
3581    :maximumRowWidth=dimension?
3582    :minimumColumnWidth=dimension?
3583    :minimumRowWidth=dimension?
3584    :rowDimensionLabels=(inCorner | nested)?
3585 => EMPTY
3586
3587 footnoteProperties
3588    :markerPosition=(superscript | subscript)?
3589    :numberFormat=(alphabetic | numeric)?
3590 => EMPTY
3591
3592 cellFormatProperties => cell_style+
3593
3594 any[cell_style]
3595    :alternatingColor=color?
3596    :alternatingTextColor=color?
3597 => style
3598
3599 style
3600    :color=color?
3601    :color2=color?
3602    :font-family?
3603    :font-size?
3604    :font-style=(regular | italic)?
3605    :font-weight=(regular | bold)?
3606    :labelLocationVertical=(positive | negative | center)?
3607    :margin-bottom=dimension?
3608    :margin-left=dimension?
3609    :margin-right=dimension?
3610    :margin-top=dimension?
3611    :textAlignment=(left | right | center | decimal | mixed)?
3612    :decimal-offset=dimension?
3613 => EMPTY
3614
3615 borderProperties => border_style+
3616
3617 any[border_style]
3618    :borderStyleType=(none | solid | dashed | thick | thin | double)?
3619    :color=color?
3620 => EMPTY
3621
3622 printingProperties
3623    :printAllLayers=bool?
3624    :rescaleLongTableToFitPage=bool?
3625    :rescaleWideTableToFitPage=bool?
3626    :windowOrphanLines=int?
3627    :continuationText?
3628    :continuationTextAtBottom=bool?
3629    :continuationTextAtTop=bool?
3630    :printEachLayerOnSeparatePage=bool?
3631 => EMPTY
3632 @end example