Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<pre class="lang-xml prettyprint-override"><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt; &lt;xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0"&gt; &lt;xsl:output indent="yes"/&gt; &lt;xsl:key name="stat-key" match="/Data/Statistic" use="Type"/&gt; &lt;xsl:template match="/"&gt; &lt;Data&gt; &lt;xsl:apply-templates select="/Data/Statistic[generate-id()=generate-id(key('stat-key',Type)[1])]"&gt; &lt;xsl:sort select="Type"/&gt; &lt;/xsl:apply-templates&gt; &lt;/Data&gt; &lt;/xsl:template&gt; &lt;xsl:template match="Statistic"&gt; &lt;xsl:copy&gt; &lt;xsl:copy-of select="Title|Type"/&gt; &lt;count&gt; &lt;Case&gt; &lt;xsl:value-of select="key('stat-key', Type)[Key='Cases']/Value"/&gt; &lt;/Case&gt; &lt;Percentage&gt; &lt;xsl:value-of select="key('stat-key', Type)[Key='Percentage']/Value"/&gt; &lt;/Percentage&gt; &lt;/count&gt; &lt;/xsl:copy&gt; &lt;/xsl:template&gt; &lt;/xsl:stylesheet&gt; </code></pre> <p>It picks the <code>Title</code> of the first <code>Statistic</code> for each <code>Type</code>-group.</p> <p><strong>Output</strong></p> <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt; &lt;Data&gt; &lt;Statistic&gt; &lt;Title&gt;Total Values&lt;/Title&gt; &lt;Type&gt;Type A&lt;/Type&gt; &lt;count&gt; &lt;Case&gt;3&lt;/Case&gt; &lt;Percentage&gt;75.0%&lt;/Percentage&gt; &lt;/count&gt; &lt;/Statistic&gt; &lt;Statistic&gt; &lt;Title&gt;Total Values&lt;/Title&gt; &lt;Type&gt;Type B&lt;/Type&gt; &lt;count&gt; &lt;Case&gt;1&lt;/Case&gt; &lt;Percentage&gt;25.0%&lt;/Percentage&gt; &lt;/count&gt; &lt;/Statistic&gt; &lt;/Data&gt; </code></pre>
 

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