Updating two different nodes using XSLT
Input –
<root>
<Bank>
<BankDetail>
<Name1>
</Name1>
<Name2>TestBank</Name2>
</BankDetail>
</Bank>
<Item>
<Item1>1235</Item1>
</Item>
</root>
Existing XSLT
The XSLT is doing one task of copying the value from Name2 Tag to Name1.
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:msxsl="urn:schemas-microsoft-com:xslt" exclude-result-prefixes="msxsl" version="1.0">
<xsl:output omit-xml-declaration="yes" method="xml" indent="yes" version="1.0"/>
<xsl:template match="@*|node()">
<xsl:copy>
<xsl:apply-templates select="@*|node()"/>
</xsl:copy>
</xsl:template>
<xsl:variable name="varName">
<xsl:if test="/root/Bank/BankDetail/Name1 = ''">
<xsl:value-of select="/root/Bank/BankDetail/Name2"/2
</xsl:if>
</xsl:variable>
<xsl:template match="/root/Bank/BankDetail/Name1">
<xsl:copy>
<xsl:value-of select="$varName"/>
<xsl:apply-templates/>
</xsl:copy>
</xsl:template>
</xsl:stylesheet>
Now, another update needs to be made using the same XSLT. Replacing the <Item1> value 1235 with “Item No 1” string.
Need this in XSLT 1.0
Desired Output –
<root>
<Bank>
<BankDetail>
<Name1>TestBank</Name1>
<Name2>TestBank</Name2>
</BankDetail>
</Bank>
<Item>
<Item1>Item No 1</Item1>
</Item>
</root>
I am new to the XSLT. Please let me know if we have any way to do the updates in same XSLT.