Victor Mukherjee
Victor Mukherjee

Reputation: 11025

Changing value of some elements with xslt

The input xml structure is like this:



  <Envelopes>
    <env:Envelope>
     <urn:MyFunction>
      <parameter1 attr1='df'>fdad</parameter1>
      <parameter2 attr2='ww'>dfsa</parameter2>
      <productData>
        <Id></Id>
        <Description></Description>
        <Price><Price>
      </productData>
    </urn:MyFunction>
    </env:Envelope>

    <env:Envelope>
     <urn:MyFunction1>
       <parameter1 attr1='df'>fdad</parameter1>
       <parameter2 attr2='ww'>dfsa</parameter2>
       <productData>
        <Id></Id>
        <Description></Description>
        <Price><Price>
       </productData>
    </urn:MyFunction>
   </env:Envelope>

   <env:Envelope>
     <urn:MyFunction1>
       <parameter1 attr1='df'>fdad</parameter1>
       <parameter2 attr2='ww'>dfsa</parameter2>
       <productData>
        <Id></Id>
        <Description></Description>
        <Price><Price>
       </productData>
    </urn:MyFunction>
   </env:Envelope>
 <Envelopes>

In my xsl I am doing the below:

<xsl:template match="/">
 <NewEnvelopes>
   <xsl:for-each select="//productData">
   <xsl:copy>
   <xsl:apply-templates select="@* | node()" />
</xsl:copy>
</NewEnvelopes>
</xsl:template>

<xsl:template match="productData/Description">
<Description>new Description</Description>
</xsl:template>

I intend to keep the rest of the productData elements and attributes same, but modify some of them. But the resulting xml gives the description element with the new value, but only the text nodes for the rest of the elements. How can I get all the rest of the nodes of productData?

Upvotes: 0

Views: 79

Answers (1)

JLRishe
JLRishe

Reputation: 101652

You need an identity template that will copy the input content. Try adding this to your XSLT:

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

Upvotes: 1

Related Questions