Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>XSLT 2.0 solution :</p> <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt; &lt;xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:xs="http://www.w3.org/2001/XMLSchema" exclude-result-prefixes="xs" version="2.0"&gt; &lt;xsl:template match="/"&gt; &lt;xsl:apply-templates/&gt; &lt;/xsl:template&gt; &lt;xsl:template match="*"&gt; &lt;xsl:copy&gt; &lt;xsl:copy-of select="@*"/&gt; &lt;xsl:apply-templates/&gt; &lt;/xsl:copy&gt; &lt;/xsl:template&gt; &lt;xsl:template match="InvestmentAccount[1]"&gt; &lt;xsl:for-each-group select="self::*|following-sibling::InvestmentAccount" group-by="concat(@InvestmentStrategyId,@Type)" &gt; &lt;InvestmentAccount Id="{@Id}" Type="{@Type}" InvestmentStrategyId="{@InvestmentStrategyId}" ParameterOverrideIds="{@ParameterOverrideIds}"&gt; &lt;xsl:for-each-group select="current-group()/Investment" group-by="@FundName"&gt; &lt;Investment FundName="{current-grouping-key()}" FundValue="{sum(for $x in current-group()/@FundValue return xs:double(data($x)))}" /&gt; &lt;/xsl:for-each-group&gt; &lt;/InvestmentAccount&gt; &lt;/xsl:for-each-group&gt; &lt;/xsl:template&gt; &lt;xsl:template match="InvestmentAccount"/&gt; &lt;/xsl:stylesheet&gt; </code></pre> <p>I insert your XML in a root called <code>&lt;test&gt;&lt;/test&gt;</code> and the result of the XSLT is :</p> <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt; &lt;test&gt; &lt;InvestmentAccount Id="Element01_Source3_Sequence002" Type="Standard" InvestmentStrategyId="Employer" ParameterOverrideIds="AllocationRateOverride"&gt; &lt;Investment FundName="Fund032" FundValue="4754.82"/&gt; &lt;Investment FundName="Fund034" FundValue="4643.48"/&gt; &lt;Investment FundName="Fund035" FundValue="2509.46"/&gt; &lt;Investment FundName="Fund038" FundValue="7104.71"/&gt; &lt;Investment FundName="Fund042" FundValue="4244.08"/&gt; &lt;/InvestmentAccount&gt; &lt;InvestmentAccount Id="Element01_Source4_Sequence003" Type="DWPRebate" InvestmentStrategyId="DSS" ParameterOverrideIds="DWPAllocationRateOverride"&gt; &lt;Investment FundName="Fund032" FundValue="1881.76"/&gt; &lt;Investment FundName="Fund034" FundValue="1584.18"/&gt; &lt;Investment FundName="Fund035" FundValue="872.99"/&gt; &lt;Investment FundName="Fund038" FundValue="2899.53"/&gt; &lt;Investment FundName="Fund042" FundValue="1762.62"/&gt; &lt;/InvestmentAccount&gt; &lt;InvestmentAccount Id="Element01_Source2_Sequence001" Type="Standard" InvestmentStrategyId="Employee" ParameterOverrideIds="AllocationRateOverride"&gt; &lt;Investment FundName="Fund032" FundValue="7395.91"/&gt; &lt;Investment FundName="Fund034" FundValue="7222.72"/&gt; &lt;Investment FundName="Fund035" FundValue="3903.52"/&gt; &lt;Investment FundName="Fund038" FundValue="11051.32"/&gt; &lt;Investment FundName="Fund042" FundValue="6602.54"/&gt; &lt;/InvestmentAccount&gt; &lt;InvestmentAccount Id="Element02_Source2_Sequence004" Type="TransferNonPR" InvestmentStrategyId="Employee" ParameterOverrideIds="AllocationRateOverride"&gt; &lt;Investment FundName="Fund032" FundValue="11056.71"/&gt; &lt;Investment FundName="Fund034" FundValue="12401.34"/&gt; &lt;Investment FundName="Fund035" FundValue="6634.860000000001"/&gt; &lt;Investment FundName="Fund038" FundValue="16545"/&gt; &lt;Investment FundName="Fund042" FundValue="10036.26"/&gt; &lt;Investment FundName="fictiousextra" FundValue="1414"/&gt; &lt;/InvestmentAccount&gt; &lt;/test&gt; </code></pre> <p>Note : the InvestmentAccount attributes value are the one of the first element InvestmentAccount in the group of InvestmentAccount that has same values for Type and InvestmentStrategyId. This can be changed easily.</p>
    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.
    1. VO
      singulars
      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