简体   繁体   中英

How to replace XML elements value with xslt stylesheet?

i have to replace each

CalculationItemPointCalculationItem/<CalculationSource>**xxxxxx**</CalculationSource>

with Value of <Name> Element under Sources/CalculationSource/<ID>**xxxxxx**</> -->where ID==CalculationSource

I tried so much but never got this: CalculationItemPointCalculationItem/<CalculationSource>Bauplan01</CalculationSource>

here a link what i did: http://xsltransform.net/aUSW7n/8

 <Project>
    <ProjectChildPosition>
      <Number>1</Number>
      <Name>Pos 1.1</Name>
      <CalculationItems>
        <CalculationItemPointCalculationItem>
          <Name>(R)Bodenbeschichtung</Name>
          <CalculationSource>f3ba3b76</CalculationSource>
        </CalculationItem>
      </CalculationItems>
      <Value>10.018</Value>
      <Unit>m²</Unit>
    </ProjectChild>
  <Sources>
    <CalculationSource>
      <Id>f3ba3b76</Id>
      <Name>Bauplan01</Name>
    </CalculationSource>
  </Sources>
  <Sources>
    <CalculationSource>
      <Id>sdfese</Id>
      <Name>Bauplan02</Name>
    </CalculationSource>
  </Sources>
  <Name>POS test Projekt </Name>
</Project>

I guess you want to use a key

   <xsl:key name="source" match="Sources/CalculationSource" use="Id"/>


<xsl:template match="CalculationItemPointCalculationItem/CalculationSource">
    <xsl:copy>
        <xsl:value-of select="key('source', .)/Name"/>
    </xsl:copy>
</xsl:template>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM