xml - XSLT Union联合数据集?

xml - XSLT Union联合数据集?,第1张

我试图像数据集一样解析我的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 个答案:

答案 0 :(得分:2)

此转化:

<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>
本文经用户投稿或网站收集转载,如有侵权请联系本站。

发表评论

0条回复