Note that there are some explanatory texts on larger screens.

plurals
  1. POUse XSL to process a hierarchy from flat data structure
    primarykey
    data
    text
    <p>Newbie question. I have to create a cross tab report like this: <PRE> SC TIN Total 3 2 South East 2 0 Gold Coast 2 0 North 1 2 Cairns 0 1 Townsville 1 1 </PRE></p> <p>using the (simplified) XML below:</p> <pre><code>&lt;DATASETLIST&gt; &lt;DATASET entity="SC"&gt; &lt;ROW&gt; &lt;District&gt;GOLD COAST&lt;/District&gt; &lt;Region&gt;SOUTH EAST&lt;/Region&gt; &lt;/ROW&gt; &lt;ROW&gt; &lt;District&gt;GOLD COAST&lt;/District&gt; &lt;Region&gt;SOUTH EASTERN&lt;/Region&gt; &lt;/ROW&gt; &lt;ROW&gt; &lt;District&gt;TOWNSVILLE&lt;/District&gt; &lt;Region&gt;NORTH&lt;/Region&gt; &lt;/ROW&gt; &lt;/DATASET&gt; &lt;DATASET entity="TIN"&gt; &lt;ROW&gt; &lt;District&gt;TOWNSVILLE&lt;/District&gt; &lt;Region&gt;NORTH&lt;/Region&gt; &lt;/ROW&gt; &lt;ROW&gt; &lt;District&gt;CAIRNS&lt;/District&gt; &lt;Region&gt;NORTH&lt;/Region&gt; &lt;/ROW&gt; &lt;/DATASET&gt; &lt;/DATASETLIST&gt; </code></pre> <p>I've actually got the main report working however the hierarchy is hardcoded (e.g. count SC's linked to "Gold Coast") but because of possible poor data, I could miss some nodes so I want to build a unique hierarchy based on the data, and then I can call my "count" template for each node.</p> <p>I've got to a point (see below) where I can produce a region-sorted list but it's not unique and the districts are not sorted within each region. I was thinking that I could somehow create a unique hierarchy variable and then process that with xsl:for-each logic.</p> <p>But I have no idea whether this is possible or the recommended method. It's possibly an extremely simple solution, but I have no idea how to go about it. Please any answers in simple (and clearly explained) terms thanks.</p> <pre><code>&lt;xsl:for-each select="//Region[not(Region=preceding-sibling::Region)]"&gt; &lt;xsl:sort select="."/&gt; &lt;xsl:for-each select="."&gt; &lt;xsl:value-of select="."/&gt; - &lt;xsl:for-each select="../District"&gt; &lt;xsl:value-of select="."/&gt;&lt;br/&gt; &lt;/xsl:for-each&gt; &lt;/xsl:for-each&gt; &lt;/xsl:for-each&gt; </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload