Reputation: 1071
I am trying to parse my xml abit too much like a dataset and Have the following:
...
<InvestmentStrategy Id="Employee">
<FundSplit FundName="Fund032" PctInvested="20.0000" />
<FundSplit FundName="Fund034" PctInvested="20.0000" />
<FundSplit FundName="Fund035" PctInvested="10.0000" />
<FundSplit FundName="Fund042" PctInvested="20.0000" />
<FundSplit FundName="Lifeasdstyle030" PctInvested="30.0000" />
</InvestmentStrategy>
<InvestmentStrategy Id="Employer">
<FundSplit FundName="Fund092" PctInvested="20.0000" />
<FundSplit FundName="Fund094" PctInvested="20.0000" />
<FundSplit FundName="Fund095" PctInvested="10.0000" />
<FundSplit FundName="Fund092" PctInvested="20.0000" />
<FundSplit FundName="Lifasdestyle030" PctInvested="30.0000" />
</InvestmentStrategy>
...
<InvestmentAccount Id="Sequence001" Type="Standard" InvestmentStrategyId="Employee" ParameterOverrideIds="AllocationRateOverride">
<Investment FundName="Fund092" FundValue="7395.91" />
<Investment FundName="Fund094" FundValue="7222.72" />
<Investment FundName="Fund095" FundValue="3903.52" />
<Investment FundName="Fund098" FundValue="11051.32" />
<Investment FundName="Fund092" FundValue="6602.54" />
</InvestmentAccount>
<InvestmentAccount Id="Sequence002" Type="Standard" InvestmentStrategyId="Employer" ParameterOverrideIds="AllocationRateOverride">
<Investment FundName="Fund032" FundValue="4754.82" />
<Investment FundName="Fund034" FundValue="4643.48" />
<Investment FundName="Fund035" FundValue="2509.46" />
<Investment FundName="Fund038" FundValue="7104.71" />
<Investment FundName="Fund042" FundValue="4244.08" />
</InvestmentAccount>
What I'd like to do is able about to 'select' all elemets where InvestmentStrategy/@Id is equal to InvestmentAccount/@InvestmentStrategyId
and loop around the combined data node. I have tried without much success 'unioning' the 2 and also something like
any clues? help?
Upvotes: 2
Views: 254
Reputation: 243479
This transformation:
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output omit-xml-declaration="yes" indent="yes"/>
<xsl:key name="kacctByStratId" match="InvestmentAccount"
use="@InvestmentStrategyId"/>
<xsl:template match="InvestmentStrategy">
<strategyData>
<xsl:copy-of select="."/>
<xsl:copy-of select="key('kacctByStratId', @Id)"/>
</strategyData>
</xsl:template>
<xsl:template match="text()"/>
</xsl:stylesheet>
when applied on the provided XML (wrapped in a top element to make it well-formed document):
<t>
<InvestmentStrategy Id="Employee">
<FundSplit FundName="Fund032" PctInvested="20.0000" />
<FundSplit FundName="Fund034" PctInvested="20.0000" />
<FundSplit FundName="Fund035" PctInvested="10.0000" />
<FundSplit FundName="Fund042" PctInvested="20.0000" />
<FundSplit FundName="Lifeasdstyle030" PctInvested="30.0000" />
</InvestmentStrategy>
<InvestmentStrategy Id="Employer">
<FundSplit FundName="Fund092" PctInvested="20.0000" />
<FundSplit FundName="Fund094" PctInvested="20.0000" />
<FundSplit FundName="Fund095" PctInvested="10.0000" />
<FundSplit FundName="Fund092" PctInvested="20.0000" />
<FundSplit FundName="Lifasdestyle030" PctInvested="30.0000" />
</InvestmentStrategy>
...
<InvestmentAccount Id="Sequence001" Type="Standard" InvestmentStrategyId="Employee" ParameterOverrideIds="AllocationRateOverride">
<Investment FundName="Fund092" FundValue="7395.91" />
<Investment FundName="Fund094" FundValue="7222.72" />
<Investment FundName="Fund095" FundValue="3903.52" />
<Investment FundName="Fund098" FundValue="11051.32" />
<Investment FundName="Fund092" FundValue="6602.54" />
</InvestmentAccount>
<InvestmentAccount Id="Sequence002" Type="Standard" InvestmentStrategyId="Employer" ParameterOverrideIds="AllocationRateOverride">
<Investment FundName="Fund032" FundValue="4754.82" />
<Investment FundName="Fund034" FundValue="4643.48" />
<Investment FundName="Fund035" FundValue="2509.46" />
<Investment FundName="Fund038" FundValue="7104.71" />
<Investment FundName="Fund042" FundValue="4244.08" />
</InvestmentAccount>
</t>
produces the wanted "combined data" result:
<strategyData>
<InvestmentStrategy Id="Employee">
<FundSplit FundName="Fund032" PctInvested="20.0000" />
<FundSplit FundName="Fund034" PctInvested="20.0000" />
<FundSplit FundName="Fund035" PctInvested="10.0000" />
<FundSplit FundName="Fund042" PctInvested="20.0000" />
<FundSplit FundName="Lifeasdstyle030" PctInvested="30.0000" />
</InvestmentStrategy>
<InvestmentAccount Id="Sequence001" Type="Standard" InvestmentStrategyId="Employee" ParameterOverrideIds="AllocationRateOverride">
<Investment FundName="Fund092" FundValue="7395.91" />
<Investment FundName="Fund094" FundValue="7222.72" />
<Investment FundName="Fund095" FundValue="3903.52" />
<Investment FundName="Fund098" FundValue="11051.32" />
<Investment FundName="Fund092" FundValue="6602.54" />
</InvestmentAccount>
</strategyData>
<strategyData>
<InvestmentStrategy Id="Employer">
<FundSplit FundName="Fund092" PctInvested="20.0000" />
<FundSplit FundName="Fund094" PctInvested="20.0000" />
<FundSplit FundName="Fund095" PctInvested="10.0000" />
<FundSplit FundName="Fund092" PctInvested="20.0000" />
<FundSplit FundName="Lifasdestyle030" PctInvested="30.0000" />
</InvestmentStrategy>
<InvestmentAccount Id="Sequence002" Type="Standard" InvestmentStrategyId="Employer" ParameterOverrideIds="AllocationRateOverride">
<Investment FundName="Fund032" FundValue="4754.82" />
<Investment FundName="Fund034" FundValue="4643.48" />
<Investment FundName="Fund035" FundValue="2509.46" />
<Investment FundName="Fund038" FundValue="7104.71" />
<Investment FundName="Fund042" FundValue="4244.08" />
</InvestmentAccount>
</strategyData>
Upvotes: 2