'What's the syntax for otherwise in XSLT if we have to update the value for an existing key/element

I am trying to add a new key in a CustomAPI Node using Choose when. If new key doesn't present in existing node, it is adding a key. So, a new key is adding to node. So, to update the value of existing key, while using otherwise I am unable to change value of a existing key in a node. We implemented those using following code. Also find the error attached after this code.

XML Input:-

<Configuration>
  <CustomAPI>
    <add key="City" value="Mumbai"/>
    <add key="Street" value="Dalal"/>   
  </CustomAPI>
</Configuration>

XSLT:-

 <xsl:template match="/configuration/CustomAPI">
<xsl:copy>
    <xsl:apply-templates select="@* | node()"/>
    <xsl:choose>
        <xsl:when test="not(add[@key = 'City'])">
            <add key="City" value="Mumbai"/>
        </xsl:when>
     <xsl:otherwise>
            <xsl:template match="/configuration/CustomAPI/add[@key='City']/@value">
            <xsl:attribute name="{name()}">Delhi</xsl:attribute>
            </xsl:template>
        </xsl:otherwise>                
    </xsl:choose>
</xsl:copy>
</xsl:template> 

XML Output:-

 <Configuration>
   <CustomAPI>
    <add key="City" value="Delhi"/>
    <add key="Street" value="Dalal"/>   
   </CustomAPI>
 </Configuration>

Error:- "'xsl:template' cannot be a child of the 'xsl:otherwise' element."



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source