Matrix View allows generating tables that where both rows and columns are dynamic.
Matrix View consists of three tabs. The first two tabs - "Rows Hierarchy Query" and "Colums Hierarchy Query" are the same as the interface for table queries in Table View. They are used to define the row and column headers of the matrix. The third tab, called Matrix Query is used to specify the expression to calculate the values of the matrix cells and displays the results.
Matrix View Tabs
Here is a use case:
Suppose you want to make a spreadsheet that has a column for each tested host and a row for each discovered vulnerability. The table cell will contain an "X" if the corresponding host has the corresponding vulnerability and will be blank otherwise.
To have a row for each vulnerability the "rows hierarchy query" needs to list all unique findings. The query contains one expression:
mt:unique(//finding/@title)
Row Hierarchy Query
For more information about mt:unique() and other custom XPath functions in MagicTree see Custom XPath Functions
To have a column for each host, the "columns hierarchy query" will contain the expression
//host
The third tab "Matrix Query" will eventually contain the results. Before it happens, we need to define an expression that will calculate the values of the matrix cells. Initially it shows an empty table and the number of rows and columns:
Matrix Query tab
This is how it works. We define one expression is used to calculate the value of each matrix cell. If the expression returns a non-empty set, the matrix cell will contain "X". If the expression returns an empty set, the matrix cell will be empty. If an error occurs while calculating the expression, the matrix cell will contain "E". For each matrix cell two variables are defined - $row and $col. They are set to the values of the corresponding row and column header. For example, in our query, the $row value for the left topmost cell will be "MySQL yaSSL CertDecoderGetName Multiple Buffer Overflows" and the $col value will be "10.6.200.2". Those variables can (and should) be used in the cell expression.
So, if we want to have "X" in the cells where the given host has the given vulnerability, we need an expression like this:
//host[text()=$col and descendant::finding/@title=$col]
For each cell this expression will select the host with IP address in the current column, but only if it has the vulnerability in the current column. Clicking on "Update Matrix" button starts the calculation. It can take several minutes for table that have hundreds of rows or columns. The result looks like this:
Matrix Query Results
The contents of the Matrix can be copied and pasted into a spreadsheet, such as Microsoft Excell or OpenOffice/LibreOffice Calc.
Matrix Queries can be saved to the repository and re-used. Click on "Save Matrix Query to Repo" button to save the query. See also Using Repositories