Altova StyleVision 2025 Enterprise Edition

Example: Group-By (Scores.sps)

Home Prev Top Next

The Scores.sps example is based on the Scores.xsd schema and uses Scores.xml as its Working XML File. It is located in the (My) Documents folder, C:\Documents and Settings\<username>\My Documents\Altova\StyleVision2025\StyleVisionExamples\Tutorial\Grouping\Scores\. The XML document structure is as follows: a results document element contains one or more group elements and one or more match elements. A group element contains one or more team elements, and a match element is structured according to this example:

 

<match group="A" date="2007-10-12">

 <team name="Brazil" for="2" points="3"/>

 <team name="Germany" for="1" points="0"/>

</match>

 

The design consists of three parts (screenshot below): (i) the match results presented by day (grouped on //match/@date); (ii) the match results presented by group (grouped on //match/@group); and (iii) group tables providing an overview of the standings by group (a dynamic table of the group element, with Auto-Calculations to calculate the required data).

 

GroupingEx2a

 

Strategy

For the two sections containing the match results, we group matches by date and tournament-group. For members of each group (date and tournament group), we create borderless tables (for alignment purposes). So matches played on a single date will be in a separate table, and all the match results of a single tournament group will be in a separate table (for example, Group A matches). For the group-tables section, the group element is created as a dynamic table, with Auto-Calculations providing the value of the required data.

 

Creating the SPS

The design was created as follows:

 

1.Drag the /results/match element from the schema tree and create it as contents.

2.Right-click the match element tag and, in the context menu, select Group by.

3.In the Define Output Grouping dialog, select group-by, set the XPath expression in the Match text box to @date, and click OK.

4.A dialog pops up asking whether the groups should be sorted. Since we wish the groups to be sorted according to the default ascending alphabetical sorting, click Yes. (Sorting can always be set, modified, or deleted subsequently.)

5.Since each group (which is a date) is to be created in a separate table, create the current group as a table. Do this by right-clicking the current-group() tag, selecting Change to | Table, and then selecting the descendant nodes team/@name and team/@for as the columns of the table (see screenshot below).

 

GroupingEx2b

 

6.Set a hyphen in each cell that will be output if the match is not the last in the current group. Do this by using a conditional template with a condition set to position() != last(). This provides output such as: Brazil - Germany or 2 - 1.

7.Put an Auto-Calculation in the header that outputs the current grouping key for the respective group (XPath expression: current-grouping-key()).

8.Format the table as required.

9.To group the matches by tournament group, repeat the entire process, but group matches this time on the group attribute of match.

10.For the group tables (in the third section of the design), which contain the standings of each team in the group, create the /results/group element as a dynamic table. Add columns as required (using the Table | Append Column or Table | Insert Column commands). Set up Auto-Calculations in each column to calculate the required output (3 point for a win; 1 point for a draw; 0 points for a loss). And, finally, sort the table in descending order of total points obtained. To see the XPath expressions used to obtain these results, right-click the Auto-Calculation or sorted template, and select, respectively, the Edit XPath and Sort by commands.

 

© 2018-2024 Altova GmbH