XSLT Union объединит наборы данных? - PullRequest
2 голосов
/ 14 ноября 2011

Я пытаюсь проанализировать мой xml abit слишком сильно, как набор данных, и имею следующее:

... 
        <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>

То, что я хотел бы сделать, может «выбрать» все элементы, где InvestmentStrategy / @ Id равен InvestmentAccount / @ InvestmentStrategyId

и обведите объединенный узел данных. Я без особого успеха пытался «объединить» 2, а также что-то вроде

какие-нибудь подсказки? помочь?

1 Ответ

2 голосов
/ 14 ноября 2011

Это преобразование:

<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>

при применении к предоставленному XML (завернутый в верхний элемент, чтобы сделать его правильно сформированным документом):

<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>

дает требуемый результат "комбинированных данных" :

<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>
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...