3

I want to change value of some node. Condition for change value is as below:

If node name is "Name1" and if keyword is n1 then change to n2 If node name is "Name1" and if keyword is g1 then change to g2

<maindata>
<data>
 <keyword>n1</keywod>
 <keyword>g1</keyword>
</data>

<name>
<String>Name1</String>
</name>
</maindata>

Also I just change the value of above nodes all other content of file are just copy, so I write code for this as below:

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

So how can I write template to change node value as mention above?

1 Answer 1

1

I think you want to add two templates:

<xsl:template match="maindata[name/String = 'Name1']/data/keyword[. = 'n1']">
  <keyword>n2</keyword>
</xsl:template>

<xsl:template match="maindata[name/String = 'Name1']/data/keyword[. = 'g1']">
  <keyword>g2</keyword>
</xsl:template>
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.