1: Accessing the XML in Crosstabs
First, open Crosstabs for your project.
To access the XML for a saved crosstab, locate the crosstab and click "Edit Crosstab".
Then click "XML".
To access the XML for a new crosstab, select "Build Crosstab".
Then click "XML".
Edit the crosstab using XML. If you are familiar with coding, this can be an easy way to edit or modify the report and find errors not always visible from the graphical user interface (GUI). Select "Update" once you have completed your edits. Click "Cancel" or X to revert your code back to its previous content (any changes you made will be lost).
2: Logic Syntax
Note that the labels in the XML are case sensitive.
All tags that are open must also be closed, using the forward slash ( / ).
2.1: XML Tags & Their Attributes
The outer most tag that defines that you have a crosstab
- name - The crosstab name (default: "New Crosstab")
- description - The description of the crosstab (default: none)
Creates a group heading and can contain multiple segments <seg>
- name - The group name (default: "New Group")
- showHeader - Show or hide the group as a heading in the report table (set to true or false; default: true)
Defines a specific banner point within your custom crosstab
- name - The segment name (default: "New Segment")
Outlines the specific logic (i.e., condition) that defines your specific banner point
- <cond> (ALL) - The segment logic represents all respondents in the crosstab
- <cond> (ALL_IN_GROUP) - The segment logic represents the count/percentages of the segments within a group. Otherwise, count/percentages is based on all segments in the crosstab.
- <and /> Joins two <cond> tags with AND, which filters respondent data where both conditions must be true.
- <or /> Joins two <cond> tags with OR, which filters respondent data where either condition can be true.
- <and-not /> Joins two <cond> tags with AND NOT, which filters respondent data where the first condition must be true and the second condition must be false.
- <or-not /> Joins two <cond> tags with OR NOT, which filters respondent data where the first condition can be true or the second condition can be false.
2.2: Logic Syntax for Conditions
2.2.1: Closed-end Questions
1-dimensional single select, multi-select or dropdown menu question:
Checks checks "r1" was selected in q3
2-dimensional single select, multi-select or dropdown menu question:
Checks if for r1 in q3, "c1" was selected
Checks within r1 of q4 if any option was selected
Checks if anything within q4, but excluding q4.r1 was selected
<cond>q4.count > 2</cond>
Checks if the number of checkboxes checked was greater than 2
2.2.2: Open-ended Questions
Text and Essay questions:
Matches Q2's textual value against this string (not case sensitive) within the question (ASCII character set only)
Number and Float questions:
<cond>(Q3.check('1-100')) or (Q3.check('>399')) or ( Q3.check('<50'))</cond>
Checks for items within the range, 400 and above, or less than 50
<cond>Q5.sum > 25</cond>
Checks if the sum of the numeric question is greater than 25
Excludes empty data fields from the logic (when applicable). Otherwise empty data fields will be evaluated to "0" and included in the logic.
date_range(start, end) checks whether the completion date is within that range, in the server's time zone.
- The dates can be one of "01-mar-2013", "01-mar-2013 14:32" or "01-mar-2013 14:32:00"
- The month is case insensitive
- The time is 24H time
- If the end time is a day, it's assumed to be end of that day (so specifying 14-mar-2013 as end time means until the 23:59:59 on that day). Leave out end to default to the end of the start day.
- Use 'now' as a dynamic end date to reference "today". This logic is only accessible in the XML, it is not supported in the logic editor.
Example of respondents completing on 3/25/14:
date_days(start, end)checks for a rolling date range.
- "start" equal to 0 means beginning of today, 14 means beginning of the day 14 days ago
- The end defaults to now if left out, otherwise it's the end of the day specified as using the start syntax
- This syntax correctly accounts for daylights saving time
Example of respondents completing in the last 7 days:
2.2.4: Nested Logic
Segment logic can use parentheses or a logic joiner to change logic precedence, which creates nested boolean logic.
The example below shows multiple ways that logic for Males (
q1.r1) who selected either "Brand A" (
q3.r1) or "is 35-44" (
q2.r4) can be entered in the XML.
Using a single condition:
<cond> (q1.r1) and (q2.r4 or q3.r1)</cond>
Using conditions separated with a logic joiner:
<cond>(q1.r1)</cond> <and /> <cond>(q2.r4 or q3.r1)</cond>
2.3: Combining Tags & Conditions
The XML file is a series of nested XML tags. There will be only one set of <xtab></xtab> tags that surround all of your segments and groups.
<xtab name="New Crosstab"> <seg name="Total"> <cond>(ALL)</cond> </seg> </xtab>
Inside each report, you must use the <seg></seg> and <cond></cond> tags to define your banners. There is one <seg></seg> for each banner point you want to include in your report, and must include a name (name=""). The <cond></cond> tags are then nested to define the logic for each banner point; you can have one or more <cond></cond> tags inside each <seg></seg>, linked with the condition joiners.
<seg name="Male 18-34"> <cond>(q1.r1)</cond> <and /> <cond>(q2.r1 or q2.r2)</cond> </seg> <seg name="Male 44 or under"> <cond>(q1.r1)</cond> <and-not/> <cond>(q2.r5)</cond> </seg>
2.4: Defining the Variable Names
In the above example using the <cond></cond> tags, the logic was defined using the syntax
(q1.r1). These references, "q1" and "r1" are specific variable names used within the survey. To find the appropriate variable references, you can download the survey datamap, available in the download feature of the report. You can use the "direct to browser" option, which loads the datamap in your current browser. The datamap shows each question and the associated label. For more information on how to find the proper report, click here.
Tip: If your project utilizes alternate (alt) labels, you must reference the original question label.
The labels and conditions are used to create the proper logic for specifying each segment. Using a portion of a datamap, below is the description of custom segments using the <cond></cond> tags.
- r1 - Male
- r2 - Female
- r1 - Under 18
- r2 - 18-24
- r3 - 25-34
- r4 - 35-44
- r5 - 45 or older
- 0 - Unchecked
- 1 - Checked
- r1 - Brand A
- r2 - Brand B
- r3 - Brand C
- r4 - Brand D
<seg name="Male"> <cond>(q1.r1)</cond> </seg>
<seg name="Male and not (45 or older)"> <cond>(q1.r1)</cond> <and-not /> <cond>(q2.r5)</cond> </seg>
<seg name="Male and (Brand A or B)"> <cond>(q1.r1)</cond> <and /> <cond>(q3.r1 or q3.r2)</cond> </seg>
<seg name="Male and (Brand A and B)"> <cond>(q1.r1)</cond> <and /> <cond>(q3.r1 and q3.r2)</cond> </seg>
3: Tips & Tricks
One of the best ways to learn the proper syntax is to build out custom reports using the report builder, then go back and review the code it generated.
The XML editor will also optimize the code when you save it. You don't have to separate out the logic for the segment. If you enter:
<cond>(q1.r1 or q2.r1) and q3.r1</cond>
the XML editor will save and update it to the nested logic:
<cond>(q1.r1 or q2.r1)</cond> <and /> <cond>q3.r1</cond>
- Use CTRL + ENTER to update the XML and close the editor.