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