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