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