Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>I would prefer a two step transformation, collecting the data into a variable first. When vast data size is involved, this may have to be reconsidered. Below is an xslt which does the trick.</p> <pre><code>&lt;xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"&gt; &lt;xsl:output indent="yes" omit-xml-declaration="yes" method="xml" version="1.0"/&gt; &lt;xsl:key name="CellGroup" use="@CellOrdinal - (@CellOrdinal mod 6)" match="CellData/Cell"/&gt; &lt;xsl:template match="CellData"&gt; &lt;xsl:variable name="Cells"&gt; &lt;xsl:apply-templates select="Cell[generate-id() = generate-id(key('CellGroup', @CellOrdinal - (@CellOrdinal mod 6))[1])]" mode="group"/&gt; &lt;/xsl:variable&gt; &lt;body&gt; &lt;actual_accounts&gt; &lt;xsl:for-each select="$Cells/Cell[contract-type='actual']"&gt; &lt;actual_account&gt; &lt;xsl:copy-of select="contract-type"/&gt; &lt;xsl:copy-of select="sum"/&gt; &lt;xsl:copy-of select="percentage"/&gt; &lt;/actual_account&gt; &lt;/xsl:for-each&gt; &lt;actual_percentage&gt;&lt;xsl:value-of select="$Cells/Cell[contract-type='actual'][1]/contract-type-percentage"/&gt;&lt;/actual_percentage&gt; &lt;/actual_accounts&gt; &lt;accumulation_accounts&gt; &lt;xsl:for-each select="$Cells/Cell[contract-type='accumulation']"&gt; &lt;accumulation_account&gt; &lt;xsl:copy-of select="contract-type"/&gt; &lt;xsl:copy-of select="sum"/&gt; &lt;xsl:copy-of select="percentage"/&gt; &lt;/accumulation_account&gt; &lt;/xsl:for-each&gt; &lt;accumulation_percentage&gt;&lt;xsl:value-of select="$Cells/Cell[contract-type='accumulation'][1]/contract-type-percentage[1]"/&gt;&lt;/accumulation_percentage&gt; &lt;/accumulation_accounts&gt; &lt;deposits&gt; &lt;xsl:for-each select="$Cells/Cell[contract-type='deposit']"&gt; &lt;deposit&gt; &lt;xsl:copy-of select="contract-type"/&gt; &lt;xsl:copy-of select="sum"/&gt; &lt;xsl:copy-of select="percentage"/&gt; &lt;/deposit&gt; &lt;/xsl:for-each&gt; &lt;deposit_percentage&gt;&lt;xsl:value-of select="$Cells/Cell[contract-type='deposit'][1]/contract-type-percentage[1]"/&gt;&lt;/deposit_percentage&gt; &lt;/deposits&gt; &lt;balance_total&gt;&lt;xsl:value-of select="$Cells/Cell[1]/balance-total"/&gt;&lt;/balance_total&gt; &lt;/body&gt; &lt;/xsl:template&gt; &lt;xsl:template match="Cell" mode="group"&gt; &lt;Cell&gt; &lt;xsl:variable name="Cells" select="key('CellGroup', @CellOrdinal - (@CellOrdinal mod 6))"/&gt; &lt;contract-type&gt;&lt;xsl:value-of select="$Cells[1]/FmtValue"/&gt;&lt;/contract-type&gt; &lt;contract-id&gt;&lt;xsl:value-of select="$Cells[2]/FmtValue"/&gt;&lt;/contract-id&gt; &lt;sum&gt;&lt;xsl:value-of select="$Cells[3]/FmtValue"/&gt;&lt;/sum&gt; &lt;percentage&gt;&lt;xsl:value-of select="$Cells[4]/FmtValue"/&gt;&lt;/percentage&gt; &lt;contract-type-percentage&gt;&lt;xsl:value-of select="$Cells[5]/FmtValue"/&gt;&lt;/contract-type-percentage&gt; &lt;balance-total&gt;&lt;xsl:value-of select="$Cells[6]/FmtValue"/&gt;&lt;/balance-total&gt; &lt;/Cell&gt; &lt;/xsl:template&gt; &lt;/xsl:stylesheet&gt; </code></pre> <p>The output I get is as follows:</p> <pre><code>&lt;body&gt; &lt;actual_accounts&gt; &lt;actual_account&gt; &lt;contract-type&gt;actual&lt;/contract-type&gt; &lt;sum&gt;20457114.2200&lt;/sum&gt; &lt;percentage&gt;99.9711&lt;/percentage&gt; &lt;/actual_account&gt; &lt;actual_percentage&gt;33.0000&lt;/actual_percentage&gt; &lt;/actual_accounts&gt; &lt;accumulation_accounts&gt; &lt;accumulation_percentage&gt;&lt;/accumulation_percentage&gt; &lt;/accumulation_accounts&gt; &lt;deposits&gt; &lt;deposit&gt; &lt;contract-type&gt;deposit&lt;/contract-type&gt; &lt;sum&gt;213.8800&lt;/sum&gt; &lt;percentage&gt;0.0010&lt;/percentage&gt; &lt;/deposit&gt; &lt;deposit&gt; &lt;contract-type&gt;deposit&lt;/contract-type&gt; &lt;sum&gt;5709.7200&lt;/sum&gt; &lt;percentage&gt;0.0279&lt;/percentage&gt; &lt;/deposit&gt; &lt;deposit_percentage&gt;67.0000&lt;/deposit_percentage&gt; &lt;/deposits&gt; &lt;balance_total&gt;20463037.8200&lt;/balance_total&gt; &lt;/body&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