2014-07-10 3 views
-1

이것은 내 첫 번째 질문에 대한 stackoverflow입니다. 나는이 같은 XML이 : 나는 태그/securityBasketDefinition/루트/securityBasketComponentNew [X]를 태그/레이블 아래의 레이블과 일치 할 필요가XSLT for-each on xml

<securityBasketDefinition> 
    <securityBasketComponents> 
     <securityBasketComponent> 
      <securityId> 
       <securityAlternateCodes/> 
       <securityLabel>5536</securityLabel> 
       <securityMarket>PT GOV</securityMarket> 
       <securityDisplayLabel>PGB 3.85 15APR21</securityDisplayLabel> 
      </securityId> 
      <weight>0.022041737</weight> 
      <nominalAmount>0.01</nominalAmount> 
      <componentPrice>0</componentPrice> 
      <componentType>bond</componentType> 
     </securityBasketComponent> 
     <securityBasketComponent> 
      <securityId> 
       <securityAlternateCodes/> 
       <securityLabel>2941</securityLabel> 
       <securityMarket>IT GOV</securityMarket> 
       <securityDisplayLabel>BTP 3.75 1MAR21</securityDisplayLabel> 
      </securityId> 
      <weight>0.204042787</weight> 
      <nominalAmount>0.01</nominalAmount> 
      <componentPrice>0</componentPrice> 
      <componentType>bond</componentType> 
     </securityBasketComponent> 
     <securityBasketComponent> 
      <securityId> 
       <securityAlternateCodes/> 
       <securityLabel>5542</securityLabel> 
       <securityMarket>FR GOV</securityMarket> 
       <securityDisplayLabel>FRTR 3.75 25APR21</securityDisplayLabel> 
      </securityId> 
      <weight>0.228670367</weight> 
      <nominalAmount>0.01</nominalAmount> 
      <componentPrice>0</componentPrice> 
      <componentType>bond</componentType> 
     </securityBasketComponent> 
     <securityBasketComponent> 
      <securityId> 
       <securityAlternateCodes/> 
       <securityLabel>12897</securityLabel> 
       <securityMarket>BE GOV</securityMarket> 
       <securityDisplayLabel>BGB 3.000 28SEP19 - OLO67</securityDisplayLabel> 
      </securityId> 
      <weight>0.029298111</weight> 
      <nominalAmount>0.01</nominalAmount> 
      <componentPrice>0</componentPrice> 
      <componentType>bond</componentType> 
     </securityBasketComponent> 
    </securityBasketComponents> 
    <root> 
     <securityBasketComponentNew> 
      <label>4905</label> 
      <securityId>AT0000386115</securityId> 
      <weight>0.039597771</weight> 
     </securityBasketComponentNew> 
     <securityBasketComponentNew> 
      <label>2862</label> 
      <securityId>AT0000A0VRF9</securityId> 
      <weight>0.020257355</weight> 
     </securityBasketComponentNew> 
     <securityBasketComponentNew> 
      <label>2867</label> 
      <securityId>BE0000318270</securityId> 
      <weight>0.053516328</weight> 
     </securityBasketComponentNew> 
     <securityBasketComponentNew> 
      <label>12897</label> 
      <securityId>BE0000327362</securityId> 
      <weight>0.028389328</weight> 
     </securityBasketComponentNew> 
     <securityBasketComponentNew> 
      <label>4848</label> 
      <securityId>FI4000010848</securityId> 
      <weight>0.019722759</weight> 
     </securityBasketComponentNew> 
    </root> 
</securityBasketDefinition> 

을/securityBasketDefinition/securityBasketComponents/securityBasketComponent [X]/securityId/securityLabel/securityBasketDefinition/securityBasketComponents/securityBasketComponent [X]/weight 아래의 태그를/securityBasketDefinition/root/securityBasketComponentNew [X]/weight의 값으로 업데이트하는 것보다 훨씬 쉽습니다.

이 경우 수식 결과는 다음과 같아야합니다 작성된 긴 코드에 대한 도움말과 유감에 대한 모든

<securityBasketDefinition> 
<securityBasketComponents> 
    <securityBasketComponent> 
     <securityId> 
      <securityAlternateCodes/> 
      <securityLabel>5536</securityLabel> 
      <securityMarket>PT GOV</securityMarket> 
      <securityDisplayLabel>PGB 3.85 15APR21</securityDisplayLabel> 
     </securityId> 
     <weight>0.022041737</weight> 
     <nominalAmount>0.01</nominalAmount> 
     <componentPrice>0</componentPrice> 
     <componentType>bond</componentType> 
    </securityBasketComponent> 
    <securityBasketComponent> 
     <securityId> 
      <securityAlternateCodes/> 
      <securityLabel>2941</securityLabel> 
      <securityMarket>IT GOV</securityMarket> 
      <securityDisplayLabel>BTP 3.75 1MAR21</securityDisplayLabel> 
     </securityId> 
     <weight>0.039597771</weight> <== NEW VALUE 
     <nominalAmount>0.01</nominalAmount> 
     <componentPrice>0</componentPrice> 
     <componentType>bond</componentType> 
    </securityBasketComponent> 
    <securityBasketComponent> 
     <securityId> 
      <securityAlternateCodes/> 
      <securityLabel>5542</securityLabel> 
      <securityMarket>FR GOV</securityMarket> 
      <securityDisplayLabel>FRTR 3.75 25APR21</securityDisplayLabel> 
     </securityId> 
     <weight>0.228670367</weight> 
     <nominalAmount>0.01</nominalAmount> 
     <componentPrice>0</componentPrice> 
     <componentType>bond</componentType> 
    </securityBasketComponent> 
    <securityBasketComponent> 
     <securityId> 
      <securityAlternateCodes/> 
      <securityLabel>12897</securityLabel> 
      <securityMarket>BE GOV</securityMarket> 
      <securityDisplayLabel>BGB 3.000 28SEP19 - OLO67</securityDisplayLabel> 
     </securityId> 
     <weight>0.028389328</weight> <== NEW VALUE 
     <nominalAmount>0.01</nominalAmount> 
     <componentPrice>0</componentPrice> 
     <componentType>bond</componentType> 
    </securityBasketComponent> 
</securityBasketComponents> 
<root> 
    <securityBasketComponentNew> 
     <label>2941</label> 
     <securityId>AT0000386115</securityId> 
     <weight>0.039597771</weight> 
    </securityBasketComponentNew> 
    <securityBasketComponentNew> 
     <label>2862</label> 
     <securityId>AT0000A0VRF9</securityId> 
     <weight>0.020257355</weight> 
    </securityBasketComponentNew> 
    <securityBasketComponentNew> 
     <label>2867</label> 
     <securityId>BE0000318270</securityId> 
     <weight>0.053516328</weight> 
    </securityBasketComponentNew> 
    <securityBasketComponentNew> 
     <label>12897</label> 
     <securityId>BE0000327362</securityId> 
     <weight>0.028389328</weight> 
    </securityBasketComponentNew> 
    <securityBasketComponentNew> 
     <label>4848</label> 
     <securityId>FI4000010848</securityId> 
     <weight>0.019722759</weight> 
    </securityBasketComponentNew> 
</root> 

감사합니다.

+0

에 오신 것을 환영합니다. 당신의 질문은 어디에 있습니까? –

+0

@ michael.hor257k 제 질문은 어떻게 xslt 공식으로 결과를 얻을 수 있습니까? 나는 중첩 된 각각을 위해 2 개를 시도하지만 결과는 없다. –

+1

시도한 내용과 실패한 이유를 보여주십시오. – WilQu

답변

0

귀하의 질문에 명확하지 않은가 두렵습니다. 또한 minimize 예제가 훨씬 더 좋습니다.

일치하는 securityBasketComponentNew 요소가있는 경우 여기에서 추측하여 securityLabellabel을 비교하여 가중치를 대체한다고 가정합니다. 경우이므로보십시오

XSLT 상기 다음 테스트 입력인가 1.0

<xsl:stylesheet version="1.0" 
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> 
<xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/> 
<xsl:strip-space elements="*"/> 

<xsl:key name="new" match="securityBasketComponentNew" use="label" /> 

<!-- identity transform --> 
<xsl:template match="@*|node()"> 
    <xsl:copy> 
     <xsl:apply-templates select="@*|node()"/> 
    </xsl:copy> 
</xsl:template> 

<xsl:template match="securityBasketComponent/weight[key('new', ../securityId/securityLabel)]"> 
    <xsl:copy> 
     <xsl:value-of select="key('new', ../securityId/securityLabel)/weight" /> 
    </xsl:copy> 
    <xsl:comment>NEW VALUE</xsl:comment> 
</xsl:template> 

</xsl:stylesheet> 

는 :

<securityBasketDefinition> 

    <securityBasketComponents> 
     <securityBasketComponent> 
      <securityId> 
       <securityLabel>111</securityLabel> 
      </securityId> 
      <weight>0.111</weight> 
     </securityBasketComponent> 
     <securityBasketComponent> 
      <securityId> 
       <securityLabel>222</securityLabel> 
      </securityId> 
      <weight>0.222</weight> 
     </securityBasketComponent> 
     <securityBasketComponent> 
      <securityId> 
       <securityLabel>333</securityLabel> 
      </securityId> 
      <weight>0.333</weight> 
     </securityBasketComponent> 
    </securityBasketComponents> 

    <root> 
     <securityBasketComponentNew> 
      <label>111</label> 
      <weight>1.11</weight> 
     </securityBasketComponentNew> 
     <securityBasketComponentNew> 
      <label>333</label> 
      <weight>3.33</weight> 
     </securityBasketComponentNew> 
     <securityBasketComponentNew> 
      <label>444</label> 
      <weight>4.44</weight> 
     </securityBasketComponentNew> 
    </root> 

</securityBasketDefinition> 

결과 될 것이다

<?xml version="1.0" encoding="UTF-8"?> 
<securityBasketDefinition> 
    <securityBasketComponents> 
     <securityBasketComponent> 
     <securityId> 
      <securityLabel>111</securityLabel> 
     </securityId> 
     <weight>1.11</weight><!--NEW VALUE--> 
     </securityBasketComponent> 
     <securityBasketComponent> 
     <securityId> 
      <securityLabel>222</securityLabel> 
     </securityId> 
     <weight>0.222</weight> 
     </securityBasketComponent> 
     <securityBasketComponent> 
     <securityId> 
      <securityLabel>333</securityLabel> 
     </securityId> 
     <weight>3.33</weight><!--NEW VALUE--> 
     </securityBasketComponent> 
    </securityBasketComponents> 
    <root> 
     <securityBasketComponentNew> 
     <label>111</label> 
     <weight>1.11</weight> 
     </securityBasketComponentNew> 
     <securityBasketComponentNew> 
     <label>333</label> 
     <weight>3.33</weight> 
     </securityBasketComponentNew> 
     <securityBasketComponentNew> 
     <label>444</label> 
     <weight>4.44</weight> 
     </securityBasketComponentNew> 
    </root> 
</securityBasketDefinition> 
+0

고맙습니다! 하지만 당신이 여기서 무엇을하는지 이해할 수 없습니다 :'' –

+0

@LuigiantonioCalo '도움이되는지보기 : http : //www.xml .com/pub/a/2002/02/06/key-lookups.html –