2011-11-14 4 views
2

나는 다음과 같은 데이터 집합처럼 너무 많은 내 XML을 ABIT를 분석하고 가지고 노력하고 있어요 :데이터 집합을 결합하는 XSLT 연합?

... 
     <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가 동일 곳 모두 elemets를 '선택'에 대한 수 InvestmentAccount/@ InvestmentStrategyId

및 결합 된 데이터 노드 주변 루프. 나는이 또한 뭔가

같은 단서를 'unioning'많은 성공없이 시도? 도움?

답변

2

이 변형 : 제공된 XML 적용

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

(상부 소자 래핑이 잘 형성된 문서를 만들기 위해)

<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

감사합니다. 내가 원했던 것과 매우 흡사합니다. (완벽하게 분리되어 있습니다.) 이제이 코드를 템플릿 일치와 다양한 루프 등을 사용하여 XML DataSet을 구축하는 기존 템플릿에 추가해야합니다. 어떤 동기 부여? 중첩 될 수 없다고 생각되면 템플릿 없이도 작동 할 수 있습니까? ... ... .. . –

+0

나는 그것을 금이 생각 '에 대한-각'

+0

@JonH : 예, 가능하며 편도를 찾았습니다. 나는 확실히 를''로 선호 할 것이다. 이 대답을 수락하는 것을 고려해주십시오. 또한 현재 받아 들여지는 것보다 나은 내 대답을 수락하는 것을 생각해 볼 수 있습니다. –