Document a lot of setCellProperties.
[pspp] / spv-file-format.texi
1 @node SPSS Viewer File Format
2 @chapter SPSS Viewer File Format
3
4 SPSS Viewer or @file{.spv} files, here called SPV files, are written
5 by SPSS 16 and later to represent the contents of its output editor.
6 This chapter documents the format, based on examination of a corpus of
7 about 500 files from a variety of sources.  This description is
8 detailed enough to read SPV files, but probably not enough to write
9 them.
10
11 SPSS 15 and earlier versions use a completely different output format
12 based on the Microsoft Compound Document Format.  This format is not
13 documented here.
14
15 An SPV file is a Zip archive that can be read with @command{zipinfo}
16 and @command{unzip} and similar programs.  The final member in the Zip
17 archive is a file named @file{META-INF/MANIFEST.MF}.  This structure
18 makes SPV files resemble Java ``JAR'' files (and ODF files), but
19 whereas a JAR manifest contains a sequence of colon-delimited
20 key/value pairs, an SPV manifest contains the string
21 @samp{allowPivoting=true}, without a new-line.  (This string may be
22 the best way to identify an SPV file; it is invariant across the
23 corpus.)
24
25 The rest of the members in an SPV file's Zip archive fall into two
26 categories: @dfn{structure} and @dfn{detail} members.  Structure
27 member names begin with @file{outputViewer@var{nnnnnnnnnn}}, where
28 each @var{n} is a decimal digit, and end with @file{.xml}, and often
29 include the string @file{_heading} in between.  Each of these members
30 represents some kind of output item (a table, a heading, a block of
31 text, etc.) or a group of them.  The member whose output goes at the
32 beginning of the document is numbered 0, the next member in the output
33 is numbered 1, and so on.
34
35 Structure members contain XML.  This XML is sometimes self-contained,
36 but it often references detail members in the Zip archive, which are
37 named as follows:
38
39 @table @asis
40 @item @file{@var{prefix}_table.xml} and @file{@var{prefix}_tableData.bin}
41 @itemx @file{@var{prefix}_lightTableData.bin}
42 The structure of a table plus its data.  Older SPV files pair a
43 @file{@var{prefix}_table.xml} file that describes the table's
44 structure with a binary @file{@var{prefix}_tableData.bin} file that
45 gives its data.  Newer SPV files (the majority of those in the corpus)
46 instead include a single @file{@var{prefix}_lightTableData.bin} file
47 that incorporates both into a single binary format.
48
49 @item @file{@var{prefix}_warning.xml} and @file{@var{prefix}_warningData.bin}
50 @itemx @file{@var{prefix}_lightWarningData.bin}
51 Same format used for tables, with a different name.
52
53 @item @file{@var{prefix}_notes.xml} and @file{@var{prefix}_notesData.bin}
54 @itemx @file{@var{prefix}_lightNotesData.bin}
55 Same format used for tables, with a different name.
56
57 @item @file{@var{prefix}_chartData.bin} and @file{@var{prefix}_chart.xml}
58 The structure of a chart plus its data.  Charts do not have a
59 ``light'' format.
60
61 @item @file{@var{prefix}_pmml.scf}
62 @itemx @file{@var{prefix}_stats.scf}
63 @item @file{@var{prefix}_model.xml}
64 Not yet investigated.  The corpus contains few examples.
65 @end table
66
67 The @file{@var{prefix}} in the names of the detail members is
68 typically an 11-digit decimal number that increases for each item,
69 tending to skip values.  Older SPV files use different naming
70 conventions.  Structure member refer to detail members by name, and so
71 their exact names do not matter to readers as long as they are unique.
72
73 @menu
74 * SPV Structure Member Format::
75 * SPV Light Detail Member Format::
76 * SPV Legacy Detail Member Binary Format::
77 * SPV Legacy Detail Member XML Format::
78 @end menu
79
80 @node SPV Structure Member Format
81 @section Structure Member Format
82
83 Structure members' XML files claim conformance with a collection of
84 XML Schemas.  These schemas are distributed, under a nonfree license,
85 with SPSS binaries.  Fortunately, the schemas are not necessary to
86 understand the structure members.  To a degree, the schemas can even
87 be deceptive because they document elements and attributes that are
88 not in the corpus and do not document elements and attributes that are
89 commonly found there.
90
91 Structure members use a different XML namespace for each schema, but
92 these namespaces are not entirely consistent.  In some SPV files, for
93 example, the @code{viewer-tree} schema is associated with namespace
94 @indicateurl{http://xml.spss.com/spss/viewer-tree} and in others with
95 @indicateurl{http://xml.spss.com/spss/viewer/viewer-tree} (note the
96 additional @file{viewer/}).  Under either name, the schema URIs are
97 not resolvable to obtain the schemas themselves.
98
99 One may ignore all of the above in interpreting a structure member.
100 The actual XML has a simple and straightforward form that does not
101 require a reader to take schemas or namespaces into account.
102
103 The elements found in structure members are documented below.  For
104 each element, we note the possible parent elements and the element's
105 contents.  The contents are specified as pseudo-regular expressions
106 with the following conventions:
107
108 @table @asis
109 @item text
110 XML text content.
111
112 @item CDATA
113 XML CDATA content.
114
115 @item @code{element}
116 The named element.
117
118 @item (@dots{})
119 Grouping multiple elements.
120
121 @item [@var{x}]
122 An optional @var{x}.
123
124 @item @var{a} @math{|} @var{b}
125 A choice between @var{a} and @var{b}.
126
127 @item @var{x}*
128 Zero or more @var{x}.
129 @end table
130
131 @ifnottex
132 For a diagram illustrating the hierarchy of elements within an SPV
133 structure member, please refer to a PDF version of the manual.
134 @end ifnottex
135
136 @iftex
137 The following diagram shows the hierarchy of elements within an SPV
138 structure member.  Edges point from parent to child elements.
139 Unlabeled edges indicate that the child appears exactly once; edges
140 labeled with *, zero or more times; edges labeled with ?, zero or one
141 times.
142 @center @image{dev/spv-structure, 5in}
143 @end iftex
144
145 @menu
146 * SPV Structure heading Element::
147 * SPV Structure label Element::
148 * SPV Structure container Element::
149 * SPV Structure text Element (Inside @code{container})::
150 * SPV Structure html Element::
151 * SPV Structure table Element::
152 * SPV Structure tableStructure Element::
153 * SPV Structure dataPath Element::
154 * SPV Structure pageSetup Element::
155 * SPV Structure pageHeader and pageFooter Elements::
156 * SPV Structure pageParagraph Element::
157 * SPV Structure @code{text} Element (Inside @code{pageParagraph})::
158 @end menu
159
160 @node SPV Structure heading Element
161 @subsection The @code{heading} Element
162
163 Parent: Document root or @code{heading} @*
164 Contents: @code{pageSetup}? @code{label} (@code{container} @math{|} @code{heading})*
165
166 The root of a structure member is a @code{heading}, which represents a
167 section of output beginning with a title (the @code{label}) and
168 ordinarily followed by content containers or further nested
169 (sub)-sections of output.
170
171 The document root heading, only, may also contain a @code{pageSetup}
172 element.
173
174 The following attributes have been observed on both document root and
175 nested @code{heading} elements.
176
177 @defvr {Optional} creator-version
178 The version of the software that created this SPV file.  A string of
179 the form @code{xxyyzzww} represents software version xx.yy.zz.ww,
180 e.g.@: @code{21000001} is version 21.0.0.1.  Trailing pairs of zeros
181 are sometimes omitted, so that @code{21}, @code{210000}, and
182 @code{21000000} are all version 21.0.0.0 (and the corpus contains all
183 three of those forms).
184 @end defvr
185
186 @noindent
187 The following attributes have been observed on document root
188 @code{heading} elements only:
189
190 @defvr {Optional} @code{creator}
191 The directory in the file system of the software that created this SPV
192 file.
193 @end defvr
194
195 @defvr {Optional} @code{creation-date-time}
196 The date and time at which the SPV file was written, in a
197 locale-specific format, e.g. @code{Friday, May 16, 2014 6:47:37 PM
198 PDT} or @code{lunedì 17 marzo 2014 3.15.48 CET} or even @code{Friday,
199 December 5, 2014 5:00:19 o'clock PM EST}.
200 @end defvr
201
202 @defvr {Optional} @code{lockReader}
203 Whether a reader should be allowed to edit the output.  The possible
204 values are @code{true} and @code{false}, but the corpus only contains
205 @code{false}.
206 @end defvr
207
208 @defvr {Optional} @code{schemaLocation}
209 This is actually an XML Namespace attribute.  A reader may ignore it.
210 @end defvr
211
212 @noindent
213 The following attributes have been observed only on nested
214 @code{heading} elements:
215
216 @defvr {Required} @code{commandName}
217 The locale-invariant name of the command that produced the output,
218 e.g.@: @code{Frequencies}, @code{T-Test}, @code{Non Par Corr}.
219 @end defvr
220
221 @defvr {Optional} @code{visibility}
222 To what degree the output represented by the element is visible.  The
223 only observed value is @code{collapsed}.
224 @end defvr
225
226 @defvr {Optional} @code{locale}
227 The locale used for output, in Windows format, which is similar to the
228 format used in Unix with the underscore replaced by a hyphen, e.g.@:
229 @code{en-US}, @code{en-GB}, @code{el-GR}, @code{sr-Cryl-RS}.
230 @end defvr
231
232 @defvr {Optional} @code{olang}
233 The output language, e.g.@: @code{en}, @code{it}, @code{es},
234 @code{de}, @code{pt-BR}.
235 @end defvr
236
237 @node SPV Structure label Element
238 @subsection The @code{label} Element
239
240 Parent: @code{heading} or @code{container} @*
241 Contents: text
242
243 Every @code{heading} and @code{container} holds a @code{label} as its
244 first child.  The root @code{heading} in a structure member always
245 contains the string ``Output''.  Otherwise, the text in @code{label}
246 describes what it labels, often by naming the statistical procedure
247 that was executed, e.g.@: ``Frequencies'' or ``T-Test''.  Labels are
248 often very generic, especially within a @code{container}, e.g.@:
249 ``Title'' or ``Warnings'' or ``Notes''.  Label text is localized
250 according to the output language, e.g.@: in Italian a frequency table
251 procedure is labeled ``Frequenze''.
252
253 The corpus contains one example of an empty label, one that contains
254 no text.
255
256 This element has no attributes.
257
258 @node SPV Structure container Element
259 @subsection The @code{container} Element
260
261 Parent: @code{heading} @*
262 Contents: @code{label} (@code{table} @math{|} @code{text})?
263
264 A @code{container} serves to label a @code{table} or a @code{text}
265 item.
266
267 This element has the following attributes.
268
269 @defvr {Required} @code{visibility}
270 Either @code{visible} or @code{hidden}, this indicates whether the
271 container's content is displayed.
272 @end defvr
273
274 @defvr {Optional} @code{text-align}
275 Presumably indicates the alignment of text within the container.  The
276 only observed value is @code{left}.  Observed with nested @code{table}
277 and @code{text} elements.
278 @end defvr
279
280 @defvr {Optional} @code{width}
281 The width of the container in the form @code{@var{n}px}, e.g.@:
282 @code{1097px}.
283 @end defvr
284
285 @node SPV Structure text Element (Inside @code{container})
286 @subsection The @code{text} Element (Inside @code{container})
287
288 Parent: @code{container} @*
289 Contents: @code{html}
290
291 This @code{text} element is nested inside a @code{container}.  There
292 is a different @code{text} element that is nested inside a
293 @code{pageParagraph}.
294
295 This element has the following attributes.
296
297 @defvr {Required} @code{type}
298 One of @code{title}, @code{log}, or @code{text}.
299 @end defvr
300
301 @defvr {Optional} @code{commandName}
302 As on the @code{heading} element.  For output not specific to a
303 command, this is simply @code{log}.  The corpus contains one example
304 of where @code{commandName} is present but set to the empty string.
305 @end defvr
306
307 @defvr {Optional} @code{creator-version}
308 As on the @code{heading} element.
309 @end defvr
310
311 @node SPV Structure html Element
312 @subsection The @code{html} Element
313
314 Parent: @code{text} @*
315 Contents: CDATA
316
317 The CDATA contains an HTML document.  In some cases, the document
318 starts with @code{<html>} and ends with @code{</html}; in others the
319 @code{html} element is implied.  Generally the HTML includes a
320 @code{head} element with a CSS stylesheet.  The HTML body often begins
321 with @code{<BR>}.  The actual content ranges from trivial to simple:
322 just discarding the CSS and tags yields readable results.
323
324 This element has the following attributes.
325
326 @defvr {Required} @code{lang}
327 This always contains @code{en} in the corpus.
328 @end defvr
329
330 @node SPV Structure table Element
331 @subsection The @code{table} Element
332
333 Parent: @code{container} @*
334 Contents: @code{tableStructure}
335
336 This element has the following attributes.
337
338 @defvr {Required} @code{commandName}
339 As on the @code{heading} element.
340 @end defvr
341
342 @defvr {Required} @code{type}
343 One of @code{table}, @code{note}, or @code{warning}.
344 @end defvr
345
346 @defvr {Required} @code{subType}
347 The locale-invariant name for the particular kind of output that this
348 table represents in the procedure.  This can be the same as
349 @code{commandName} e.g.@: @code{Frequencies}, or different, e.g.@:
350 @code{Case Processing Summary}.  Generic subtypes @code{Notes} and
351 @code{Warnings} are often used.
352 @end defvr
353
354 @defvr {Required} @code{tableId}
355 A number that uniquely identifies the table within the SPV file,
356 typically a large negative number such as @code{-4147135649387905023}.
357 @end defvr
358
359 @defvr {Optional} @code{creator-version}
360 As on the @code{heading} element.  In the corpus, this is only present
361 for version 21 and up and always includes all 8 digits.
362 @end defvr
363
364 @node SPV Structure tableStructure Element
365 @subsection The @code{tableStructure} Element
366
367 Parent: @code{table} @*
368 Contents: @code{dataPath}
369
370 This element has no attributes.
371
372 @node SPV Structure dataPath Element
373 @subsection The @code{dataPath} Element
374
375 Parent: @code{tableStructure} @*
376 Contents: text
377
378 Contains the name of the Zip member that holds the table details,
379 e.g.@: @code{0000000001437_lightTableData.bin}.
380
381 This element has no attributes.
382
383 @node SPV Structure pageSetup Element
384 @subsection The @code{pageSetup} Element
385
386 Parent: @code{heading} @*
387 Contents: @code{pageHeader} @code{pageFooter}
388
389 This element has the following attributes.
390
391 @defvr {Required} @code{initial-page-number}
392 Always @code{1}.
393 @end defvr
394
395 @defvr {Optional} @code{chart-size}
396 Always @code{as-is} or a localization (!) of it (e.g.@: @code{dimensione
397 attuale}, @code{Wie vorgegeben}).
398 @end defvr
399
400 @defvr {Optional} @code{margin-left}
401 @defvrx {Optional} @code{margin-right}
402 @defvrx {Optional} @code{margin-top}
403 @defvrx {Optional} @code{margin-bottom}
404 Margin sizes in the form @code{@var{size}in}, e.g.@: @code{0.25in}.
405 @end defvr
406
407 @defvr {Optional} @code{paper-height}
408 @defvrx {Optional} @code{paper-width}
409 Paper sizes in the form @code{@var{size}in}, e.g.@: @code{8.5in} by
410 @code{11in} for letter paper or @code{8.267in} by @code{11.692in} for
411 A4 paper.
412 @end defvr
413
414 @defvr {Optional} @code{reference-orientation}
415 Always @code{0deg}.
416 @end defvr
417
418 @defvr {Optional} @code{space-after}
419 Always @code{12pt}.
420 @end defvr
421
422 @node SPV Structure pageHeader and pageFooter Elements
423 @subsection The @code{pageHeader} and @code{pageFooter} Elements
424
425 Parent: @code{pageSetup} @*
426 Contents: @code{pageParagraph}*
427
428 This element has no attributes.
429
430 @node SPV Structure pageParagraph Element
431 @subsection The @code{pageParagraph} Element
432
433 Parent: @code{pageHeader} or @code{pageFooter} @*
434 Contents: @code{text}
435
436 Text to go at the top or bottom of a page, respectively.
437
438 This element has no attributes.
439
440 @node SPV Structure @code{text} Element (Inside @code{pageParagraph})
441 @subsection The @code{text} Element (Inside @code{pageParagraph})
442
443 Parent: @code{pageParagraph}
444 Contents: CDATA?
445
446 This @code{text} element is nested inside a @code{pageParagraph}.  There
447 is a different @code{text} element that is nested inside a
448 @code{container}.
449
450 The element is either empty, or contains CDATA that holds almost-XHTML
451 text: in the corpus, either an @code{html} or @code{p} element.  It is
452 @emph{almost}-XHTML because the @code{html} element designates the
453 default namespace as
454 @code{http://xml.spss.com/spss/viewer/viewer-tree} instead of an XHTML
455 namespace, and because the CDATA can contain substitution variables:
456 @code{&[Page]} for the page number and @code{&[PageTitle]} for the
457 page title.
458
459 Typical contents (indented for clarity):
460
461 @example
462 <html xmlns="http://xml.spss.com/spss/viewer/viewer-tree">
463     <head></head>
464     <body>
465         <p style="text-align:right; margin-top: 0">Page &[Page]</p>
466     </body>
467 </html>
468 @end example
469
470 This element has the following attributes.
471
472 @defvr {Required} @code{type}
473 Always @code{text}.
474 @end defvr
475
476 @node SPV Light Detail Member Format
477 @section Light Detail Member Format
478
479 This section describes the format of ``light'' detail @file{.bin}
480 members.  These members have a binary format which we describe here in
481 terms of a context-free grammar using the following conventions:
482
483 @table @asis
484 @item NonTerminal @result{} @dots{}
485 Nonterminals have CamelCaps names, and @result{} indicates a
486 production.  The right-hand side of a production is often broken
487 across multiple lines.  Break points are chosen for aesthetics only
488 and have no semantic significance.
489
490 @item 00, 01, @dots{}, ff.
491 Bytes with fixed values are written in hexadecimal:
492
493 @item i0, i1, @dots{}, i9, i10, i11, @dots{}
494 32-bit integers with fixed values are written in decimal, prefixed by
495 @samp{i}.
496
497 @item byte
498 An arbitrary byte.
499
500 @item int
501 An arbitrary 32-bit integer.
502
503 @item double
504 An arbitrary 64-bit IEEE floating-point number.
505
506 @item string
507 A 32-bit integer followed by the specified number of bytes of
508 character data.  (The encoding is indicated by the Formats
509 nonterminal.)
510
511 @item @var{x}?
512 @var{x} is optional, e.g.@: 00? is an optional zero byte.
513
514 @item @var{x}*@var{n}
515 @var{x} is repeated @var{n} times, e.g. byte*10 for ten arbitrary bytes.
516
517 @item @var{x}[@var{name}]
518 Gives @var{x} the specified @var{name}.  Names are used in textual
519 explanations.  They are also used, also bracketed, to indicate counts,
520 e.g.@: int[@t{n}] byte*[@t{n}] for a 32-bit integer followed by the
521 specified number of arbitrary bytes.
522
523 @item @var{a} @math{|} @var{b}
524 Either @var{a} or @var{b}.
525
526 @item (@var{x})
527 Parentheses are used for grouping to make precedence clear, especially
528 in the presence of @math{|}, e.g.@: in 00 (01 @math{|} 02 @math{|} 03)
529 00.
530
531 @item count(@var{x})
532 A 32-bit integer that indicates the number of bytes in @var{x},
533 followed by @var{x} itself.
534
535 @item v1(@var{x})
536 In a version 1 @file{.bin} member, @var{x}; in version 3, nothing.
537 (The @file{.bin} header indicates the version.)
538
539 @item v3(@var{x})
540 In a version 3 @file{.bin} member, @var{x}; in version 1, nothing.
541 @end table
542
543 All integer and floating-point values in this format use little-endian
544 byte order.
545
546 A ``light'' detail member @file{.bin} consists of a number of sections
547 concatenated together, terminated by a byte 01:
548
549 @cartouche
550 @format
551 LightMember @result{} Header Title Caption Footnotes Fonts Formats Dimensions Data 01
552 @end format
553 @end cartouche
554
555 The following sections go into more detail.
556
557 @menu
558 * SPV Light Member Header::
559 * SPV Light Member Title::
560 * PSV Light Member Caption::
561 * SPV Light Member Footnotes::
562 * SPV Light Member Fonts::
563 * SPV Light Member Formats::
564 * SPV Light Member Dimensions::
565 * SPV Light Member Categories::
566 * SPV Light Member Data::
567 * SPV Light Member Value::
568 * SPV Light Member ValueMod::
569 @end menu
570
571 @node SPV Light Member Header
572 @subsection Header
573
574 An SPV file begins with an 39-byte header:
575
576 @cartouche
577 @format
578 Header @result{}
579     01 00
580     (i1 @math{|} i3)[@t{version}]
581     01 (00 @math{|} 01) byte*21 00 00
582     int[@t{table-id}] byte*4
583 @end format
584 @end cartouche
585
586 @code{version} is a version number that affects the interpretation of
587 some of the other data in the member.  We will refer to ``version 1''
588 and ``version 3'' later on and use v1(@dots{}) and v3(@dots{}) for
589 version-specific formatting (as described previously).
590
591 @code{table-id} is a binary version of the @code{tableId} attribute in
592 the structure member that refers to the detail member.  For example,
593 if @code{tableId} is @code{-4154297861994971133}, then @code{table-id}
594 would be 0xdca00003.
595
596 The meaning of the other variable parts of the header is not known.
597
598 @node SPV Light Member Title
599 @subsection Title
600
601 @cartouche
602 @format
603 Title @result{}
604     Value[@t{title1}] 01?
605     Value[@t{c}] 01? 31
606     Value[@t{title2}] 01? 00? 58
607 @end format
608 @end cartouche
609
610 The Title, which follows the Header, specifies the pivot table's title
611 twice, as @code{title1} and @code{title2}.  In the corpus, they are
612 always the same.
613
614 Whereas the Value in @code{title1} and in @code{title2} are
615 appropriate for presentation, and localized to the user's language,
616 @code{c} is in English, sometimes less specific, and sometimes less
617 well formatted.  For example, for a frequency table, @code{title1} and
618 @code{title2} name the variable and @code{c} is simply ``Frequencies''.
619
620 @node PSV Light Member Caption
621 @subsection Caption
622
623 @cartouche
624 @format
625 Caption @result{} 58 @math{|} 31 Value[@t{caption}]
626 @end format
627 @end cartouche
628
629 The @code{caption}, if presented, is shown below the table.
630
631 @node SPV Light Member Footnotes
632 @subsection Footnotes
633
634 @cartouche
635 @format
636 Footnotes @result{} int[@t{n}] Footnote*[@t{n}]
637 Footnote @result{} Value[@t{text}] (58 @math{|} 31 Value[@t{marker}]) byte*4
638 @end format
639 @end cartouche
640
641 Each footnote has @code{text} and an optional customer @code{marker}
642 (such as @samp{*}).
643
644 @node SPV Light Member Fonts
645 @subsection Fonts
646
647 @cartouche
648 @format
649 Fonts @result{} 00 Font*8
650 Font @result{}
651     byte[@t{index}] 31 string[@t{typeface}] 00 00
652     (10 @math{|} 20 @math{|} 40 @math{|} 50 @math{|} 70 @math{|} 80)[@t{f1}] 41
653     (i0 @math{|} i1 @math{|} i2)[@t{f2}] 00
654     (i0 @math{|} i2 @math{|} i64173)[@t{f3}]
655     (i0 @math{|} i1 @math{|} i2 @math{|} i3)[@t{f4}]
656     string[@t{fgcolor}] string[@t{bgcolor}] i0 i0 00
657     v3(int[@t{f5}] int[@t{f6}] int[@t{f7}] int[@t{f8}]))
658 @end format
659 @end cartouche
660
661 Each Font represents the font style for a different element, in the
662 following order: title, caption, footnote, row labels, column labels,
663 corner labels, data, and layers.
664
665 @code{index} is the 1-based index of the Font, i.e. 1 for the first
666 Font, through 8 for the final Font.
667
668 @code{typeface} is the string name of the font.  In the corpus, this
669 is @code{SansSerif} in over 99% of instances and @code{Times New
670 Roman} in the rest.
671
672 @code{fgcolor} and @code{bgcolor} are the foreground color and
673 background color, respectively.  In the corpus, these are always
674 @code{#000000} and @code{#ffffff}, respectively.
675
676 The meaning of the remaining data is unknown.  It seems likely to
677 include font sizes, horizontal and vertical alignment, attributes such
678 as bold or italic, and margins.
679
680 The table below lists the values observed in the corpus.  When a cell
681 contains a single value, then 99@math{+}% of the corpus contains that value.
682 When a cell contains a pair of values, then the first value is seen in
683 about two-thirds of the corpus and the second value in about the
684 remaining one-third.  In fonts that include multiple pairs, values are
685 correlated, that is, for font 3, f5 = 24, f6 = 24, f7 = 2 appears
686 about two-thirds of the time, as does the combination of f4 = 0, f6 =
687 10 for font 7.
688
689 @multitable {font} {40} {f2} {64173} {0/1} {24/11} {10/11} {2/3} {f8}
690 @headitem font @tab f1 @tab f2 @tab f3 @tab f4 @tab f5 @tab f6 @tab f7 @tab f8
691 @item 1 @tab 40 @tab 1 @tab     0 @tab   0 @tab 8 @tab 10/11 @tab   1 @tab 8
692 @item 2 @tab 40 @tab 0 @tab     2 @tab   1 @tab 8 @tab 10/11 @tab   1 @tab 1
693 @item 3 @tab 40 @tab 0 @tab     2 @tab 1 @tab 24/11 @tab 24/ 8 @tab 2/3 @tab 4
694 @item 4 @tab 40 @tab 0 @tab     2 @tab   3 @tab 8 @tab 10/11 @tab   1 @tab 1
695 @item 5 @tab 40 @tab 0 @tab     0 @tab   1 @tab 8 @tab 10/11 @tab   1 @tab 4
696 @item 6 @tab 40 @tab 0 @tab     2 @tab   1 @tab 8 @tab 10/11 @tab   1 @tab 4
697 @item 7 @tab 40 @tab 0 @tab 64173 @tab 0/1 @tab 8 @tab 10/11 @tab   1 @tab 1
698 @item 8 @tab 40 @tab 0 @tab     2 @tab   3 @tab 8 @tab 10/11 @tab   1  @tab 4
699 @end multitable
700
701 @node SPV Light Member Formats
702 @subsection Formats
703
704 @cartouche
705 @format
706 Formats @result{}
707     int[@t{n1}] byte*[@t{n1}]
708     int[@t{n2}] byte*[@t{n2}]
709     int[@t{n3}] byte*[@t{n3}]
710     int[@t{n4}] int*[@t{n4}]
711     string[@t{encoding}]
712     (i0 @math{|} i-1) (00 @math{|} 01) 00 (00 @math{|} 01)
713     int
714     byte[@t{decimal}] byte[@t{grouping}]
715     int[@t{n-ccs}] string*[@t{n-ccs}]
716     v1(i0)
717     v3(count(count(X5) count(X6)))
718
719 X5 @result{} byte*33 int[@t{n}] int*[@t{n}]
720 X6 @result{}
721     01 00 (03 @math{|} 04) 00 00 00
722     string[@t{command}] string[@t{subcommand}]
723     string[@t{language}] string[@t{charset}] string[@t{locale}]
724     (00 @math{|} 01) 00 (00 @math{|} 01) (00 @math{|} 01)
725     int
726     byte[@t{decimal}] byte[@t{grouping}]
727     byte*8 01
728     (string[@t{dataset}] string[@t{datafile}] i0 int i0)?
729     int[@t{n-ccs}] string*[@t{n-ccs}]
730     2e (00 @math{|} 01) (i2000000 i0)?
731 @end format
732 @end cartouche
733
734 In every example in the corpus, @code{n1} is 240.  The meaning of the
735 bytes that follow it is unknown.
736
737 In every example in the corpus, @code{n2} is 18 and the bytes that
738 follow it are @code{00 00 00 01 00 00 00 00 00 00 00 00 00 02 00 00 00
739 00}.  The meaning of these bytes is unknown.
740
741 In every example in the corpus for version 1, @code{n3} is 16 and the
742 bytes that follow it are @code{00 00 00 01 00 00 00 01 00 00 00 00 01
743 01 01 01}.  In version 3, observed @code{n3} varies from 117 to 150,
744 and its bytes include a 1-byte count at offset 0x34.  When the count
745 is nonzero, a text string of that length at offset 0x35 is the name of
746 a ``TableLook'', e.g. ``Default'' or ``Academic''.
747
748 Observed values of @code{n4} vary from 0 to 17.  Out of 7,060 examples
749 in the corpus, it is nonzero only 36 times.
750
751 @code{encoding} is a character encoding, usually a Windows code page
752 such as @code{en_US.windows-1252} or @code{it_IT.windows-1252}.  The
753 rest of the character strings in the member use this encoding.  The
754 encoding string is itself encoded in US-ASCII.
755
756 @code{decimal} is the decimal point character.  The observed values
757 are @samp{.} and @samp{,}.
758
759 @code{grouping} is the grouping character.  Usually, it is @samp{,} if
760 @code{decimal} is @samp{.}, and vice versa.  Other observed values are
761 @samp{'} (apostrophe), @samp{ } (space), and zero (presumably
762 indicating that digits should not be grouped).
763
764 @code{n-ccs} is observed as either 0 or 5.  When it is 5, the
765 following strings are CCA through CCE format strings.  @xref{Custom
766 Currency Formats,,, pspp, PSPP}.  Most commonly these are all
767 @code{-,,,} but other strings occur.
768
769 @node SPV Light Member Dimensions
770 @subsection Dimensions
771
772 A pivot table presents multidimensional data.  A Dimension identifies
773 the categories associated with each dimension.
774
775 @cartouche
776 @format
777 Dimensions @result{} int[@t{n-dims}] Dimension*[@t{n-dims}]
778 Dimension @result{} Value[@t{name}] DimUnknown int[@t{n-categories}] Category*[@t{n-categories}]
779 DimUnknown @result{}
780     byte[@t{d1}]
781     (00 @math{|} 01 @math{|} 02)[@t{d2}]
782     (i0 @math{|} i2)[@t{d3}]
783     (00 @math{|} 01)[@t{d4}]
784     (00 @math{|} 01)[@t{d5}]
785     01
786     int[@t{d6}]
787 @end format
788 @end cartouche
789
790 @code{name} is the name of the dimension, e.g. @code{Variables},
791 @code{Statistics}, or a variable name.
792
793 @code{d1} is usually 0 but many other values have been observed.
794
795 @code{d3} is 2 over 99% of the time.
796
797 @code{d5} is 0 over 99% of the time.
798
799 @code{d6} is either -1 or the 0-based index of the dimension, e.g.@: 0
800 for the first dimension, 1 for the second, and so on.  The latter is
801 the case 98% of the time in the corpus.
802
803 @node SPV Light Member Categories
804 @subsection Categories
805
806 Categories are arranged in a tree.  Only the leaf nodes in the tree
807 are really categories; the others just serve as grouping constructs.
808
809 @cartouche
810 @format
811 Category @result{} Value[@t{name}] (Leaf @math{|} Group)
812 Leaf @result{} 00 00 00 i2 int[@t{index}] i0
813 Group @result{}
814     (00 @math{|} 01)[@t{merge}] 00 01 (i0 @math{|} i2)[@t{data}]
815     i-1 int[@t{n-subcategories}] Category*[@t{n-subcategories}]
816 @end format
817 @end cartouche
818
819 @code{name} is the name of the category (or group).
820
821 A Leaf represents a leaf category.  The Leaf's @code{index} is a
822 nonnegative integer less than @code{n-categories} in the Dimension in
823 which the Category is nested (directly or indirectly).
824
825 A Group represents a Group of nested categories.  Usually a Group
826 contains at least one Category, so that @code{n-subcategories} is
827 positive, but a few Groups with @code{n-subcategories} 0 has been
828 observed.
829
830 If a Group's @code{merge} is 00, the most common value, then the group
831 is really a distinct group that should be represented as such in the
832 visual representation and user interface.  If @code{merge} is 01, the
833 categories in this group should be shown and treated as if they were
834 direct children of the group's containing group (or if it has no
835 parent group, then direct children of the dimension), and this group's
836 name is irrelevant and should not be displayed.  (Merged groups can be
837 nested!)
838
839 A Group's @code{data} appears to be i2 when all of the categories
840 within a group are leaf categories that directly represent data values
841 for a variable (e.g. in a frequency table or crosstabulation, a group
842 of values in a variable being tabulated) and i0 otherwise.
843
844 @node SPV Light Member Data
845 @subsection Data
846
847 The final part of an SPV light member contains the actual data.
848
849 @cartouche
850 @format
851 Data @result{}
852     int[@t{layers}] int[@t{rows}] int[@t{columns}] int*[@t{n-dimensions}]
853     int[@t{n-data}] Datum*[@t{n-data}]
854 Datum @result{} int64[@t{index}] v3(00?) Value
855 @end format
856 @end cartouche
857
858 The values of @code{layers}, @code{rows}, and @code{columns} each
859 specifies the number of dimensions displayed in layers, rows, and
860 columns, respectively.  Any of them may be zero.  Their values sum to
861 @code{n-dimensions} from Dimensions (@pxref{SPV Light Member
862 Dimensions}).
863
864 The @code{n-dimensions} integers are a permutation of the 0-based
865 dimension numbers.  The first @code{layers} integers specify each of
866 the dimensions represented by layers, the next @code{rows} integers
867 specify the dimensions represented by rows, and the final
868 @code{columns} integers specify the dimensions represented by columns.
869 When there is more than one dimension of a given kind, the inner
870 dimensions are given first.
871
872 The format of a Datum varies slightly from version 1 to version 3: in
873 version 1 it allows for an extra optional 00 byte.
874
875 A Datum consists of an @code{index} and a Value.  Suppose there are
876 @math{d} dimensions and dimension @math{i}, @math{0 \le i < d}, has
877 @math{n_i} categories.  Consider the datum at coordinates @math{x_i},
878 @math{0 \le i < d}, and note that @math{0 \le x_i < n_i}.  Then the
879 index is calculated by the following algorithm:
880
881 @display
882 let @i{index} = 0
883 for each @math{i} from 0 to @math{d - 1}:
884     @i{index} = (@math{n_i \times} @i{index}) @math{+} @math{x_i}
885 @end display
886
887 For example, suppose there are 3 dimensions with 3, 4, and 5
888 categories, respectively.  The datum at coordinates (1, 2, 3) has
889 index @math{5 \times (4 \times (3 \times 0 + 1) + 2) + 3 = 33}.
890
891 @node SPV Light Member Value
892 @subsection Value
893
894 Value is used throughout the SPV light member format.  It boils down
895 to a number or a string.
896
897 @cartouche
898 @format
899 Value @result{} 00? 00? 00? 00? RawValue
900 RawValue @result{}
901     01 ValueMod int[@t{format}] double[@t{x}]
902   @math{|} 02 ValueMod int[@t{format}] double[@t{x}]
903     string[@t{varname}] string[@t{vallab}] (01 @math{|} 02 @math{|} 03)
904   @math{|} 03 string[@t{local}] ValueMod string[@t{id}] string[@t{c}] (00 @math{|} 01)[@t{type}]
905   @math{|} 04 ValueMod int[@t{format}] string[@t{vallab}] string[@t{varname}]
906     (01 @math{|} 02 @math{|} 03) string[@t{s}]
907   @math{|} 05 ValueMod string[@t{varname}] string[@t{varlabel}] (01 @math{|} 02 @math{|} 03)
908   @math{|} ValueMod string[@t{format}] int[@t{n-args}] Argument*[@t{n-args}]
909 Argument @result{}
910     i0 Value
911   @math{|} int[@t{x}] i0 Value*[@t{x}@math{+}1]      /* @t{x} @math{>} 0 */
912 @end format
913 @end cartouche
914
915 There are several possible encodings, which one can distinguish by the
916 first nonzero byte in the encoding.
917
918 @table @asis
919 @item 01
920 The numeric value @code{x}, intended to be presented to the user
921 formatted according to @code{format}, which is in the format described
922 for system files.  @xref{System File Output Formats}, for details.
923 Most commonly, @code{format} has width 40 (the maximum).
924
925 An @code{x} with the maximum negative double value @code{-DBL_MAX}
926 represents the system-missing value SYSMIS.  (HIGHEST and LOWEST have
927 not been observed.)  @xref{System File Format}, for more about these
928 special values.
929
930 @item 02
931 Similar to @code{01}, with the additional information that @code{x} is
932 a value of variable @code{varname} and has value label @code{vallab}.
933 Both @code{varname} and @code{vallab} can be the empty string, the
934 latter very commonly.
935
936 The meaning of the final byte is unknown.  Possibly it is connected to
937 whether the value or the label should be displayed.
938
939 @item 03
940 A text string, in two forms: @code{c} is in English, and sometimes
941 abbreviated or obscure, and @code{local} is localized to the user's
942 locale.  In an English-language locale, the two strings are often the
943 same, and in the cases where they differ, @code{local} is more
944 appropriate for a user interface, e.g.@: @code{c} of ``Not a PxP table
945 for MCN...'' versus @code{local} of ``Computed only for a PxP table,
946 where P must be greater than 1.''
947
948 @code{c} and @code{local} are always either both empty or both
949 nonempty.
950
951 @code{id} is a brief identifying string whose form seems to resemble a
952 programming language identifier, e.g.@: @code{cumulative_percent} or
953 @code{factor_14}.  It is not unique.
954
955 @code{type} is 00 for text taken from user input, such as syntax
956 fragment, expressions, file names, data set names, and 01 for fixed
957 text strings such as names of procedures or statistics.  In the former
958 case, @code{id} is always the empty string; in the latter case,
959 @code{id} is still sometimes empty.
960
961 @item 04
962 The string value @code{s}, intended to be presented to the user
963 formatted according to @code{format}.  The format for a string is not
964 too interesting, and the corpus contains many clearly invalid formats
965 like A16.39 or A255.127 or A134.1, so readers should probably ignore
966 the format entirely.
967
968 @code{s} is a value of variable @code{varname} and has value label
969 @code{vallab}.  @code{varname} is never empty but @code{vallab} is
970 commonly empty.
971
972 The meaning of the final byte is unknown.
973
974 @item 05
975 Variable @code{varname}, which is rarely observed as empty in the
976 corpus, with variable label @code{varlabel}, which is often empty.
977
978 The meaning of the final byte is unknown.
979
980 @item 31 or 58
981 (These bytes begin a ValueMod.)  A format string, analogous to
982 @code{printf}, followed by one or more Arguments, each of which has
983 one or more values.  The format string uses the following syntax:
984
985 @table @code
986 @item \%
987 @itemx \:
988 @itemx \[
989 @itemx \]
990 Each of these expands to the character following @samp{\\}, to escape
991 characters that have special meaning in format strings.  These are
992 effective inside and outside the @code{[@dots{}]}  syntax forms
993 described below.
994
995 @item \n
996 Expands to a new-line, inside or outside the @code{[@dots{}]} forms
997 described below.
998
999 @item ^@var{i}
1000 Expands to a formatted version of argument @var{i}, which must have
1001 only a single value.  For example, @code{^1} expands to the first
1002 argument's @code{value}.
1003
1004 @item [:@var{a}:]@var{i}
1005 Expands @var{a} for each of the values in @var{i}.  @var{a}
1006 should contain one or more @code{^@var{j}} conversions, which are
1007 drawn from the values for argument @var{i} in order.  Some examples
1008 from the corpus:
1009
1010 @table @code
1011 @item [:^1:]1
1012 All of the values for the first argument, concatenated.
1013
1014 @item [:^1\n:]1
1015 Expands to the values for the first argument, each followed by
1016 a new-line.
1017
1018 @item [:^1 = ^2:]2
1019 Expands to @code{@var{x} = @var{y}} where @var{x} is the second
1020 argument's first value and @var{y} is its second value.  (This would
1021 be used only if the argument has two values.  If there were more
1022 values, the second and third values would be directly concatenated,
1023 which would look funny.)
1024 @end table
1025
1026 @item [@var{a}:@var{b}:]@var{i}
1027 This extends the previous form so that the first values are expanded
1028 using @var{a} and later values are expanded using @var{b}.  For an
1029 unknown reason, within @var{a} the @code{^@var{j}} conversions are
1030 instead written as @code{%@var{j}}.  Some examples from the corpus:
1031
1032 @table @code
1033 @item [%1:*^1:]1
1034 Expands to all of the values for the first argument, separated by
1035 @samp{*}.
1036
1037 @item [%1 = %2:, ^1 = ^2:]1
1038 Given appropriate values for the first argument, expands to @code{X =
1039 1, Y = 2, Z = 3}.
1040
1041 @item [%1:, ^1:]1
1042 Given appropriate values, expands to @code{1, 2, 3}.
1043 @end table
1044 @end table
1045
1046 The format string is localized to the user's locale.
1047 @end table
1048
1049 @node SPV Light Member ValueMod
1050 @subsection ValueMod
1051
1052 A ValueMod can specify special modifications to a Value.
1053
1054 @cartouche
1055 @format
1056 ValueMod @result{}
1057     31 i0 (i0 @math{|} i1 string[@t{subscript}])
1058     v1(00 (i1 @math{|} i2) 00 00 int 00 00)
1059     v3(count(FormatString Style ValueModUnknown))
1060   @math{|} 31 i1 int[@t{footnote-number}] Format
1061   @math{|} 31 i2 (00 @math{|} 01 @math{|} 02) 00 (i1 @math{|} i2 @math{|} i3) Format
1062   @math{|} 31 i3 00 00 01 00 i2 Format
1063   @math{|} 58
1064 Style @result{} 58 @math{|} 31 01? 00? 00? 00? 01 string[@t{fgcolor}] string[@t{bgcolor}] string[@t{typeface}] byte
1065 Format @result{} 00 00 count(FormatString Style 58)
1066 FormatString @result{} count((i0 (58 @math{|} 31 string))?)
1067 ValueModUnknown @result{} 58 @math{|} 31 i0 i0 i0 i0 01 00 (01 @math{|} 02 @math{|} 08) 00 08 00 0a 00)
1068 @end format
1069 @end cartouche
1070
1071 The @code{footnote-number}, if present, specifies a footnote that the
1072 Value references.  The footnote's marker is shown appended to the main
1073 text of the Value, as a superscript.
1074
1075 The @code{subscript}, if present, specifies a string to append to the
1076 main text of the Value, as a subscript.  The subscript text is a brief
1077 indicator, e.g.@: @samp{a} or @samp{a,b}, with its meaning indicated
1078 by the table caption.  In this usage, subscripts are similar to
1079 footnotes; one apparent difference is that a Value can only reference
1080 one footnote but a subscript can list more than one letter.
1081
1082 The Format, if present, is a format string for substitutions using the
1083 syntax explained previously.  It appears to be an English-language
1084 version of the localized format string in the Value in which the
1085 Format is nested.
1086
1087 The Style, if present, changes the style for this individual Value.
1088
1089 @node SPV Legacy Detail Member Binary Format
1090 @section Legacy Detail Member Binary Format
1091
1092 Whereas the light binary format represents everything about a given
1093 pivot table, the legacy binary format conceptually consists of a
1094 number of named sources, each of which consists of a number of named
1095 variables, each of which is a 1-dimensional array of numbers or
1096 strings or a mix.  Thus, the legacy binary member format is quite
1097 simple.
1098
1099 This section uses the same context-free grammar notation as in the
1100 previous section, with the following additions:
1101
1102 @table @asis
1103 @item vAF(@var{x})
1104 In a version 0xaf legacy member, @var{x}; in other versions, nothing.
1105 (The legacy member header indicates the version; see below.)
1106
1107 @item vB0(@var{x})
1108 In a version 0xb0 legacy member, @var{x}; in other versions, nothing.
1109 @end table
1110
1111 A legacy detail member @file{.bin} has the following overall format:
1112
1113 @cartouche
1114 @format
1115 LegacyBinary @result{}
1116     00 byte[@t{version}] int16[@t{n-sources}] int[@t{member-size}]
1117     Metadata*[@t{n-sources}] Data*[@t{n-sources}]
1118 @end format
1119 @end cartouche
1120
1121 @code{version} is a version number that affects the interpretation of
1122 some of the other data in the member.  Versions 0xaf and 0xb0 are
1123 known.  We will refer to ``version 0xaf'' and ``version 0xb0'' members
1124 later on.
1125
1126 A legacy member consists of @code{n-sources} data sources, each of
1127 which has Metadata and Data.
1128
1129 @code{member-size} is the size of the legacy binary member, in bytes.
1130
1131 The following sections go into more detail.
1132
1133 @menu
1134 * SPV Legacy Member Metadata::
1135 * SPV Legacy Member Data::
1136 @end menu
1137
1138 @node SPV Legacy Member Metadata
1139 @subsection Metadata
1140
1141 @cartouche
1142 @format
1143 Metadata @result{}
1144     int[@t{n-data}] int[@t{n-variables}] int[@t{offset}]
1145     vAF(byte*32[@t{source-name}])
1146     vB0(byte*64[@t{source-name}] int[@t{x}])
1147 @end format
1148 @end cartouche
1149
1150 A data source has @code{n-variables} variables, each with
1151 @code{n-data} data values.
1152
1153 @code{source-name} is a 32- or 64-byte string padded on the right with
1154 zero bytes.  The names that appear in the corpus are very generic:
1155 usually @code{tableData} for pivot table data or @code{source0} for
1156 chart data.
1157
1158 A given Metadata's @code{offset} is the offset, in bytes, from the
1159 beginning of the member to the start of the corresponding Data.  This
1160 allows programs to skip to the beginning of the data for a particular
1161 source; it is also important to determine whether a source includes
1162 any string data (@pxref{SPV Legacy Member Data}).
1163
1164 The meaning of @code{x} in version 0xb0 is unknown.
1165
1166 @node SPV Legacy Member Data
1167 @subsection Data
1168
1169 @cartouche
1170 @format
1171 Data @result{} NumericData*[@t{n-variables}] StringData?
1172 NumericData @result{} byte*288[@t{variable-name}] double*[@t{n-data}]
1173 @end format
1174 @end cartouche
1175
1176 Data follow the Metadata in the legacy binary format, with sources in
1177 the same order.  Each NumericSeries begins with a @code{variable-name}
1178 that generally indicates its role in the pivot table, e.g.@: ``cell'',
1179 ``cellFormat'', ``dimension0categories'', ``dimension0group0'',
1180 followed by the numeric data, one double per datum.  A double with the
1181 maximum negative double @code{-DBL_MAX} represents the system-missing
1182 value SYSMIS.
1183
1184 @cartouche
1185 @format
1186 StringData @result{} i1 string[@t{source-name}] Pairs Labels
1187
1188 Pairs @result{} int[@t{n-string-vars}] PairSeries*[@t{n-string-vars}]
1189 PairVar @result{} string[@t{pair-var-name}] int[@t{n-pairs}] Pair*[@t{n-pairs}]
1190 Pair @result{} int[@t{i}] int[@t{j}]
1191
1192 Labels @result{} int[@t{n-labels}] Label*[@t{n-labels}]
1193 Label @result{} int[@t{frequency}] int[@t{s}]
1194 @end format
1195 @end cartouche
1196
1197 A source may include a mix of numeric and string data values.  When a
1198 source includes any string data, the data values that are strings are
1199 set to SYSMIS in the NumericData, and StringData follows the
1200 NumericData.  A source that contains no string data omits the
1201 StringData.  To reliably determine whether a source includes
1202 StringData, the reader should check whether the offset following the
1203 NumericData is the offset of the next source, as indicated by its
1204 Metadata (or the end of the member, in the case of the last source).
1205
1206 StringData repeats the name of the source (from Metadata).
1207
1208 The string data overlays the numeric data.  @code{n-string-vars} is
1209 the number of variables in the source that include string data.  More
1210 precisely, it is the 1-based index of the last variable in the source
1211 that includes any string data; thus, it would be 4 if there are 5
1212 variables and only the fourth one includes string data.
1213
1214 Each PairVar consists a sequence of 0 or more Pair nonterminals, each
1215 of which maps from a 0-based index within variable @code{i} to a
1216 0-based label index @code{j}, e.g.@: pair @code{i} = 2, @code{j} = 3,
1217 means that the third data value (with value SYSMIS) is to be replaced
1218 by the string of the fourth Label.
1219
1220 The labels themselves follow the pairs.  The valuable part of each
1221 label is the string @code{s}.  Each label also includes a
1222 @code{frequency} that reports the number of pairs that reference it
1223 (although this is not useful).
1224
1225 @node SPV Legacy Detail Member XML Format
1226 @section Legacy Detail Member XML Format
1227
1228 This format is still under investigation.
1229
1230 The design of the detail XML format is not what one would end up with
1231 for describing pivot tables.  This is because it is a special case
1232 of a much more general format (``visualization XML'' or ``VizML'')
1233 that can describe a wide range of visualizations.  Most of this
1234 generality is overkill for tables, and so we end up with a funny
1235 subset of a general-purpose format.
1236
1237 The important elements of the detail XML format are:
1238
1239 @itemize @bullet
1240 @item
1241 Variables.  Variables in detail XML roughly correspond to the
1242 dimensions in a light detail member.  There is one variable for each
1243 dimension, plus one variable for each level of labeling along an axis.
1244
1245 The bulk of variables are defined with @code{sourceVariable} elements.
1246 The data for these variables comes from the associated
1247 @code{tableData.bin} member.  Some variables are defined, with
1248 @code{derivedVariable} elements, as a constant or in terms of a
1249 mapping function from a source variable.
1250
1251 @item
1252 Assignment of variables to axes.  A variable can appear as columns, or
1253 rows, or layers.  The @code{faceting} element and its sub-elements
1254 describe this assignment.
1255 @end itemize
1256
1257 All elements have an optional @code{id} attribute.  In practice many
1258 elements are assigned @code{id} attributes that are never referenced.
1259
1260 @menu
1261 * SPV Detail visualization Element::
1262 * SPV Detail userSource Element::
1263 * SPV Detail sourceVariable Element::
1264 * SPV Detail derivedVariable Element::
1265 * SPV Detail extension Element::
1266 * SPV Detail graph Element::
1267 * SPV Detail location Element::
1268 * SPV Detail coordinates Element::
1269 * SPV Detail faceting Element::
1270 * SPV Detail facetLayout Element::
1271 @end menu
1272
1273 @node SPV Detail visualization Element
1274 @subsection The @code{visualization} Element
1275
1276 @format
1277 Parent: Document root
1278 Contents:
1279      extension?
1280      userSource
1281      (sourceVariable @math{|} derivedVariable)@math{+}
1282      graph
1283      labelFrame@math{+}
1284      container?
1285      style@math{+}
1286      layerController?
1287 @end format
1288
1289 This element has the following attributes.
1290
1291 @defvr {Required} creator
1292 The version of the software that created this SPV file, as a string of
1293 the form @code{xxyyzz}, which represents software version xx.yy.zz,
1294 e.g.@: @code{160001} is version 16.0.1.  The corpus includes major
1295 versions 16 through 19.
1296 @end defvr
1297
1298 @defvr {Required} date
1299 The date on the which the file was created, as a string of the form
1300 @code{YYYY-MM-DD}.
1301 @end defvr
1302
1303 @defvr {Required} lang
1304 The locale used for output, in Windows format, which is similar to the
1305 format used in Unix with the underscore replaced by a hyphen, e.g.@:
1306 @code{en-US}, @code{en-GB}, @code{el-GR}, @code{sr-Cryl-RS}.
1307 @end defvr
1308
1309 @defvr {Required} name
1310 The title of the pivot table, localized to the output language.
1311 @end defvr
1312
1313 @defvr {Required} style
1314 The @code{id} of a @code{style} element (@pxref{SPV Detail style
1315 element}).  This is the base style for the entire pivot table.  In
1316 every example in the corpus, the value is @code{visualizationStyle}
1317 and the corresponding @code{style} element has no attributes other
1318 than @code{id}.
1319 @end defvr
1320
1321 @defvr {Required} type
1322 A floating-point number.  The meaning is unknown.
1323 @end defvr
1324
1325 @defvr {Required} version
1326 The visualization schema version number.  In the corpus, the value is
1327 one of 2.4, 2.5, 2.7, and 2.8.
1328 @end defvr
1329
1330 @node SPV Detail userSource Element
1331 @subsection The @code{userSource} Element
1332
1333 Parent: @code{visualization} @*
1334 Contents:
1335
1336 This element has the following attributes.
1337
1338 @defvr {Optional} missing
1339 Always @code{listwise}.
1340 @end defvr
1341
1342 @node SPV Detail sourceVariable Element
1343 @subsection The @code{sourceVariable} Element
1344
1345 Parent: @code{visualization} @*
1346 Contents: @code{extension}* (@code{format} @math{|} @code{stringFormat})?
1347
1348 This element defines a variable whose values can be used elsewhere in
1349 the visualization.  It ties this element's @code{id} to a variable
1350 from the @file{tableData.bin} member that corresponds to this
1351 @file{.xml}.
1352
1353 This element has the following attributes.
1354
1355 @defvr {Required} categorical
1356 Always set to @code{true}.
1357 @end defvr
1358
1359 @defvr {Required} source
1360 Always set to @code{tableData}, the @code{source-name} in the
1361 corresponding @file{tableData.bin} member (@pxref{SPV Legacy Member
1362 Metadata}).
1363 @end defvr
1364
1365 @defvr {Required} sourceName
1366 The name of a variable within the source, the @code{variable-name} in
1367 the corresponding @file{tableData.bin} member (@pxref{SPV Legacy
1368 Member Data}).
1369 @end defvr
1370
1371 @defvr {Optional} dependsOn
1372 The @code{variable-name} of a variable linked to this one, so that a
1373 viewer can work with them together.  For a group variable, this is the
1374 name of the corresponding categorical variable.
1375 @end defvr
1376
1377 @defvr {Optional} label
1378 The variable label, if any
1379 @end defvr
1380
1381 @defvr {Optional} labelVariable
1382 The @code{variable-name} of a variable whose string values correspond
1383 one-to-one with the values of this variable and are suitable for use
1384 as value labels.
1385 @end defvr
1386
1387 @node SPV Detail derivedVariable Element
1388 @subsection The @code{derivedVariable} Element
1389
1390 Parent: @code{visualization} @*
1391 Contents: @code{extension}* (@code{format} @math{|} @code{stringFormat} @code{valueMapEntry}*)
1392
1393 Like @code{sourceVariable}, this element defines a variable whose
1394 values can be used elsewhere in the visualization.  Instead of being
1395 read from a data source, the variable's data are defined by a
1396 mathematical expression.
1397
1398 This element has the following attributes.
1399
1400 @defvr {Required} categorical
1401 Always set to @code{true}.
1402 @end defvr
1403
1404 @defvr {Required} value
1405 An expression that defines the variable's value.  In theory this could
1406 be an arbitrary expression in terms of constants, functions, and other
1407 variables, e.g.@: @math{(@var{var1} + @var{var2}) / 2}.  In practice,
1408 the corpus contains only the following forms of expressions:
1409
1410 @table @code
1411 @item constant(@var{number})
1412 @itemx constant(@var{variable})
1413 A constant.  The meaning when a variable is named is unknown.
1414 Sometimes the ``variable name'' has spaces in it.
1415
1416 @item map(@var{variable})
1417 Transforms the values in the named @var{variable} using the
1418 @code{valueMapEntry}s contained within the element.
1419 @end table
1420 @end defvr
1421
1422 @defvr {Optional} dependsOn
1423 The @code{variable-name} of a variable linked to this one, so that a
1424 viewer can work with them together.  For a group variable, this is the
1425 name of the corresponding categorical variable.
1426 @end defvr
1427
1428 @menu
1429 * SPV Detail valueMapEntry Element::
1430 @end menu
1431
1432 @node SPV Detail valueMapEntry Element
1433 @subsubsection The @code{valueMapEntry} Element
1434
1435 Parent: @code{derivedVariable} @*
1436 Contents: empty
1437
1438 A @code{valueMapEntry} element defines a mapping from one or more
1439 values of a source expression to a target value.  (In the corpus, the
1440 source expression is always just the name of a variable.)  Each target
1441 value requires a separate @code{valueMapEntry}.  If multiple source
1442 values map to the same target value, they can be combined or separate.
1443
1444 @code{valueMapEntry} has the following attributes.
1445
1446 @defvr {Required} from
1447 A source value, or multiple source values separated by semicolons,
1448 e.g.@: @code{0} or @code{13;14;15;16}.
1449 @end defvr
1450
1451 @defvr {Required} to
1452 The target value.
1453 @end defvr
1454
1455 @node SPV Detail extension Element
1456 @subsection The @code{extension} Element
1457
1458 This is a general-purpose ``extension'' element.  Readers that don't
1459 understand a given extension should be able to safely ignore it.  The
1460 attributes on this element, and their meanings, vary based on the
1461 context.  Each known usage is described separately below.  The current
1462 extensions use attributes exclusively, without any nested elements.
1463
1464 @subsubheading @code{visualization} Parent Element
1465
1466 With @code{visualization} as its parent element, @code{extension} has
1467 the following attributes.
1468
1469 @defvr {Optional} numRows
1470 An integer that presumably defines the number of rows in the displayed
1471 pivot table.
1472 @end defvr
1473
1474 @defvr {Optional} showGridline
1475 Always set to @code{false} in the corpus.
1476 @end defvr
1477
1478 @defvr {Optional} minWidthSet
1479 @defvrx {Optional} maxWidthSet
1480 Always set to @code{true} in the corpus.
1481 @end defvr
1482
1483 @subsubheading @code{container} Parent Element
1484
1485 With @code{container} as its parent element, @code{extension} has the
1486 following attributes.
1487
1488 @defvr {Required} combinedFootnotes
1489 Always set to @code{true} in the corpus.
1490 @end defvr
1491
1492 @subsubheading @code{sourceVariable} and @code{derivedVariable} Parent Element
1493
1494 With @code{sourceVariable} or @code{derivedVariable} as its parent
1495 element, @code{extension} has the following attributes.  A given
1496 parent element often contains several @code{extension} elements that
1497 specify the meaning of the source data's variables or sources, e.g.@:
1498
1499 @example
1500 <extension from="0" helpId="corrected_model"/>
1501 <extension from="3" helpId="error"/>
1502 <extension from="4" helpId="total_9"/>
1503 <extension from="5" helpId="corrected_total"/>
1504 @end example
1505
1506 @defvr {Required} from
1507 An integer or a name like ``dimension0''.
1508 @end defvr
1509
1510 @defvr {Required} helpId
1511 An identifier.
1512 @end defvr
1513
1514 @node SPV Detail graph Element
1515 @subsection The @code{graph} Element
1516
1517 Parent: @code{visualization} @*
1518 Contents: @code{location}@math{+} @code{coordinates} @code{faceting} @code{facetLayout} @code{interval}
1519
1520 @code{graph} has the following attributes.
1521
1522 @defvr {Required} cellStyle
1523 @defvrx {Required} style
1524 Each of these is the @code{id} of a @code{style} element (@pxref{SPV
1525 Detail style element}).  The former is the default style for
1526 individual cells, the latter for the entire table.
1527 @end defvr
1528
1529 @node SPV Detail location Element
1530 @subsection The @code{location} Element
1531
1532 Parent: @code{graph} @*
1533 Contents: empty
1534
1535 Each instance of this element specifies where some part of the table
1536 frame is located.  All the examples in the corpus have four instances
1537 of this element, one for each of the parts @code{height},
1538 @code{width}, @code{left}, and @code{top}.  Some examples in the
1539 corpus add a fifth for part @code{bottom}, even though it is not clear
1540 how all of @code{top}, @code{bottom}, and @code{heigth} can be honored
1541 at the same time.  In any case, @code{location} seems to have little
1542 importance in representing tables; a reader can safely ignore it.
1543
1544 @defvr {Required} part
1545 One of @code{height}, @code{width}, @code{top}, @code{bottom}, or
1546 @code{left}.  Presumably @code{right} is acceptable as well but the
1547 corpus contains no examples.
1548 @end defvr
1549
1550 @defvr {Required} method
1551 How the location is determined:
1552
1553 @table @code
1554 @item sizeToContent
1555 Based on the natural size of the table.  Observed only for
1556 parts @code{height} and @code{width}.
1557
1558 @item attach
1559 Based on the location specified in @code{target}.  Observed only for
1560 parts @code{top} and @code{bottom}.
1561
1562 @item fixed
1563 Using the value in @code{value}.  Observed only for parts @code{top},
1564 @code{bottom}, and @code{left}.
1565
1566 @item same
1567 Same as the specified @code{target}.  Observed only for part
1568 @code{left}.
1569 @end table
1570 @end defvr
1571
1572 @defvr {Optional} min
1573 Minimum size.  Only observed with value @code{100pt}.  Only observed
1574 for part @code{width}.
1575 @end defvr
1576
1577 @defvr {Dependent} target
1578 Required when @code{method} is @code{attach} or @code{same}, not
1579 observed otherwise.  This is the ID of an element to attach to.
1580 Observed with the ID of @code{title}, @code{footnote}, @code{graph},
1581 and other elements.
1582 @end defvr
1583
1584 @defvr {Dependent} value
1585 Required when @code{method} is @code{fixed}, not observed otherwise.
1586 Observed values are @code{0%}, @code{0px}, @code{1px}, and @code{3px}
1587 on parts @code{top} and @code{left}, and @code{100%} on part
1588 @code{bottom}.
1589 @end defvr
1590
1591 @node SPV Detail coordinates Element
1592 @subsection The @code{coordinates} Element
1593
1594 Parent: @code{graph} @*
1595 Contents: empty
1596
1597 This element is always present and always empty, with no attributes
1598 (except @code{id}).
1599
1600 @node SPV Detail faceting Element
1601 @subsection The @code{faceting} Element
1602
1603 Parent: @code{graph} @*
1604 Contents: @code{cross} @code{layer}*
1605
1606 The @code{faceting} element describes the row, column, and layer
1607 structure of the table.  Its @code{cross} child determines the row and
1608 column structure, and each @code{layer} child (if any) represents a
1609 layer.
1610
1611 @code{faceting} has no attributes (other than @code{id}).
1612
1613 @subsubheading The @code{cross} Element
1614
1615 Parent: @code{faceting} @*
1616 Contents: @code{nest} @code{nest}
1617
1618 The @code{cross} element describes the row and column structure of the
1619 table.  It has exactly two @code{nest} children, the first of which
1620 describes the table's rows and the second the table's columns.
1621
1622 @code{cross} has no attributes (other than @code{id}).
1623
1624 @subsubheading The @code{nest} Element
1625
1626 Parent: @code{cross} @*
1627 Contents: @code{variableReference}@math{+}
1628
1629 A given @code{nest} usually consists of one or more dimensions, each
1630 of which is represented by @code{variableReference} child elements.
1631 Minimally, a dimension has two @code{variableReference} children, one
1632 for the categories, one for the data, e.g.:
1633
1634 @example
1635 <nest>
1636   <variableReference ref="dimension0categories"/>
1637   <variableReference ref="dimension0"/>
1638 </nest>
1639 @end example
1640
1641 @noindent
1642 Groups of categories introduce additional variable references, e.g.@:
1643
1644 @example
1645 <nest>
1646   <variableReference ref="dimension0categories"/>
1647   <variableReference ref="dimension0group0"/>
1648   <variableReference ref="dimension0"/>
1649 </nest>
1650 @end example
1651
1652 @noindent
1653 Grouping can be hierarchical, e.g.@:
1654
1655 @example
1656 <nest>
1657   <variableReference ref="dimension0categories"/>
1658   <variableReference ref="dimension0group1"/>
1659   <variableReference ref="dimension0group0"/>
1660   <variableReference ref="dimension0"/>
1661 </nest>
1662 @end example
1663
1664 @noindent
1665 XXX what are group maps?
1666
1667 @example
1668 <nest id="nest_1973">
1669   <variableReference ref="dimension1categories"/>
1670   <variableReference ref="dimension1group1map"/>
1671   <variableReference ref="dimension1group0map"/>
1672   <variableReference ref="dimension1"/>
1673 </nest>
1674 <nest>
1675   <variableReference ref="dimension0categories"/>
1676   <variableReference ref="dimension0group0map"/>
1677   <variableReference ref="dimension0"/>
1678 </nest>
1679 @end example
1680
1681 @noindent
1682 A @code{nest} can contain multiple dimensions:
1683
1684 @example
1685 <nest>
1686   <variableReference ref="dimension1categories"/>
1687   <variableReference ref="dimension1group0"/>
1688   <variableReference ref="dimension1"/>
1689   <variableReference ref="dimension0categories"/>
1690   <variableReference ref="dimension0"/>
1691 </nest>
1692 @end example
1693
1694 One @code{nest} within a given @code{cross} may have no dimensions, in
1695 which case it still has one @code{variableReference} child, which
1696 references a @code{derivedVariable} whose @code{value} attribute is
1697 @code{constant(0)}.  In the corpus, such a @code{derivedVariable} has
1698 @code{row} or @code{column}, respectively, as its @code{id}.
1699
1700 @code{nest} has no attributes (other than @code{id}).
1701
1702 @subsubheading The @code{variableReference} Element
1703
1704 Parent: @code{nest} @*
1705 Contents: empty
1706
1707 @code{variableReference} has one attribute.
1708
1709 @defvr {Required} ref
1710 The @code{id} of a @code{sourceVariable} or @code{derivedVariable}
1711 element.
1712 @end defvr
1713
1714 @subsubheading The @code{layer} Element
1715
1716 Parent: @code{faceting} @*
1717 Contents: empty
1718
1719 Each layer is represented by a pair of @code{layer} elements.  The
1720 first of this pair is for a category variable, the second for the data
1721 variable, e.g.:
1722
1723 @example
1724 <layer value="0" variable="dimension0categories" visible="true"/>
1725 <layer value="dimension0" variable="dimension0" visible="false"/>
1726 @end example
1727
1728 @noindent
1729 @code{layer} has the following attributes.
1730
1731 @defvr {Required} variable
1732 The @code{id} of a @code{sourceVariable} or @code{derivedVariable}
1733 element.
1734 @end defvr
1735
1736 @defvr {Required} value
1737 The value to select.  For a category variable, this is always
1738 @code{0}; for a data variable, it is the same as the @code{variable}
1739 attribute.
1740 @end defvr
1741
1742 @defvr {Optional} visible
1743 Whether the layer is visible.  Generally, category layers are visible
1744 and data layers are not, but sometimes this attribute is omitted.
1745 @end defvr
1746
1747 @defvr {Optional} method
1748 When present, this is always @code{nest}.
1749 @end defvr
1750
1751 @node SPV Detail facetLayout Element
1752 @subsection The @code{facetLayout} Element
1753
1754 Parent: @code{graph} @*
1755 Contents: @code{tableLayout} @code{facetLevel}@math{+} @code{setCellProperties}*
1756
1757 @subsubheading The @code{tableLayout} Element
1758
1759 Parent: @code{facetLayout} @*
1760 Contents: empty
1761
1762 @defvr {Required} verticalTitlesInCorner
1763 Always set to @code{true}.
1764 @end defvr
1765
1766 @defvr {Optional} style
1767 The @code{id} of a @code{style} element.
1768 @end defvr
1769
1770 @defvr {Optional} fitCells
1771 Always set to @code{ticks}.
1772 @end defvr
1773
1774 @subsubheading The @code{facetLevel} Element
1775
1776 Parent: @code{facetLayout}
1777 Contents: @code{axis}
1778
1779 Each @code{facetLevel} describes a @code{variableReference} or
1780 @code{layer}, and a table has one @code{facetLevel} element for
1781 each such element.  For example, an SPV detail member that contains
1782 four @code{variableReference} elements and two @code{layer} elements
1783 will contain six @code{facetLevel} elements.
1784
1785 In the corpus, @code{facetLevel} elements and the elements that they
1786 describe are always in the same order.  The correspondence may also be
1787 observed in two other ways.  First, one may use the @code{level}
1788 attribute, described below.  Second, in the corpus, a
1789 @code{facetLevel} always has an @code{id} that is the same as the
1790 @code{id} of the element it describes with @code{_facetLevel}
1791 appended.  One should not formally rely on this, of course, but it is
1792 usefully indicative.
1793
1794 @defvr {Required} level
1795 A 1-based index into the @code{variableReference} and @code{layer}
1796 elements, e.g.@: a @code{facetLayout} with a @code{level} of 1
1797 describes the first @code{variableReference} in the SPV detail member,
1798 and in a member with four @code{variableReference} elements, a
1799 @code{facetLayout} with a @code{level} of 5 describes the first
1800 @code{layer} in the member.
1801 @end defvr
1802
1803 @defvr {Required} gap
1804 Always observed as @code{0pt}.
1805 @end defvr
1806
1807 @subsubheading The @code{setCellProperties} Element
1808
1809 Parent: @code{facetLayout} @*
1810 Contents: @code{setMetaData} @code{setStyle}* @code{setFormat}@math{+} @code{union}?
1811
1812 This element sets style properties of cells designated by the
1813 @code{target} attribute of its child elements.
1814
1815 @defvr {Optional} applyToConverse
1816 If present, always @code{true}.  This appears to invert the meaning of
1817 the @code{target} of sub-elements: the selected cells are the ones
1818 @emph{not} designated by @code{target}.
1819 @end defvr
1820
1821 @subsubheading The @code{setMetaData} Element
1822
1823 Parent: @code{setCellProperties} @*
1824 Contents: empty
1825
1826 It's really not clear what visible effect this element has, if any.
1827
1828 @defvr {Required} target
1829 The @code{id} of an element whose metadata is to be set.  In the
1830 corpus, this is always @code{graph}, the @code{id} used for the
1831 @code{graph} element.
1832 @end defvr
1833
1834 @defvr {Required} key
1835 @defvrx {Required} value
1836 A key-value pair to set for the target.
1837
1838 In the corpus, @code{key} is @code{cellPropId} or, rarely,
1839 @code{diagProps}, and @code{value} is always the @code{id} of the
1840 parent @code{setCellProperties}.
1841 @end defvr
1842
1843 @subsubheading The @code{setStyle} Element
1844
1845 Parent: @code{setCellProperties} @*
1846 Contents: empty
1847
1848 This element associates a style with the target.
1849
1850 @defvr {Required} target
1851 The @code{id} of an element whose style is to be set.  In the corpus,
1852 this is always the @code{id} of an @code{interval}, @code{labeling},
1853 or, rarely, @code{graph} element.
1854 @end defvr
1855
1856 @defvr {Required} style
1857 The @code{id} of a @code{style} element that identifies the style to
1858 set on the target.
1859 @end defvr
1860
1861 @subsubheading The @code{setFormat} Element
1862
1863 @format
1864 Parent: @code{setCellProperties}
1865 Contents:
1866     @code{format}
1867   @math{|} @code{numberFormat}
1868   @math{|} @code{stringFormat}@math{+}
1869   @math{|} @code{dateTimeFormat}
1870 @end format
1871
1872 This element sets the format of the target, ``format'' in this case
1873 meaning an the SPSS print format for a variable.
1874
1875 The details of this element vary depending on the schema version, as
1876 declared in the root @code{visualization} element's @code{version}
1877 attribute (@pxref{SPV Detail visualization Element}).  In version 2.5
1878 and earlier, @code{setFormat} contains one of a number of child
1879 elements that correspond to the different varieties of print formats.
1880 In version 2.7 and later, @code{setFormat} instead always contains a
1881 @code{format} element.