Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>The OP appears to be saying that there is precisely one Case child per Statistic, and precisely one Percentage child per per Statistic. This being the case, grouping is not necessary, and the solution becomes trivial.</p> <p>**This XSLT 1.0 style-sheet (also works for XSLT 2.0)...</p> <pre><code>&lt;xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"&gt; &lt;xsl:output method="xml" indent="yes" omit-xml-declaration="yes" /&gt; &lt;xsl:strip-space elements="*" /&gt; &lt;xsl:template match="@*|node()"&gt; &lt;xsl:copy&gt; &lt;xsl:apply-templates select="@*|node()"/&gt; &lt;/xsl:copy&gt; &lt;/xsl:template&gt; &lt;xsl:template match="Statistic[Key='Percentage']" /&gt; &lt;xsl:template match="Statistic"&gt; &lt;xsl:copy&gt; &lt;xsl:apply-templates select="@*|node()[not(self::Key|self::Value)]"/&gt; &lt;count&gt; &lt;Case&gt;&lt;xsl:value-of select="Value" /&gt;&lt;/Case&gt; &lt;Percentage&gt;&lt;xsl:value-of select= "../Statistic[Type=current()/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><strong>...when applied to this document...</strong></p> <pre><code>&lt;Data&gt; &lt;Statistic&gt; &lt;Title&gt;Total Values&lt;/Title&gt; &lt;Type&gt;Type A&lt;/Type&gt; &lt;Key&gt;Cases&lt;/Key&gt; &lt;Value&gt;3&lt;/Value&gt; &lt;/Statistic&gt; &lt;Statistic&gt; &lt;Title&gt;PHYSICIAN DETAIL TOTAL&lt;/Title&gt; &lt;Type&gt;Type A&lt;/Type&gt; &lt;Key&gt;Percentage&lt;/Key&gt; &lt;Value&gt;75.0%&lt;/Value&gt; &lt;/Statistic&gt; &lt;Statistic&gt; &lt;Title&gt;Total Values&lt;/Title&gt; &lt;Type&gt;Type B&lt;/Type&gt; &lt;Key&gt;Cases&lt;/Key&gt; &lt;Value&gt;1&lt;/Value&gt; &lt;/Statistic&gt; &lt;Statistic&gt; &lt;Title&gt;Total Values&lt;/Title&gt; &lt;Type&gt;Type B&lt;/Type&gt; &lt;Key&gt;Percentage&lt;/Key&gt; &lt;Value&gt;25.0%&lt;/Value&gt; &lt;/Statistic&gt; &lt;/Data&gt; </code></pre> <p><strong>...yields...</strong></p> <pre><code>&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