I. XSLT 1.0
Similar to the solution of michael.hor257k , but using AVTs -- Attribute-Value Templates.
Thus no need for an <xsl:attribute>
operator:
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output omit-xml-declaration="yes" indent="yes"/>
<xsl:strip-space elements="*"/>
<xsl:template match="node()|@*">
<xsl:copy>
<xsl:apply-templates select="node()|@*"/>
</xsl:copy>
</xsl:template>
<xsl:template match="AdditionalAttribute[@name='email']">
<AdditionalAttribute name="email"
value="{substring-before(@value, '(')
}({substring-before(
substring-after(@value,'('),
')'
)}@gmail.com)">
<xsl:apply-templates select="@*[not(name()='value')]"/>
</AdditionalAttribute>
</xsl:template>
</xsl:stylesheet>
When applied on the provided XML document:
<Person>
<AdditionalAttributes groupLabel="Profile">
<AdditionalAttribute name="First Name" value="John"/>
<AdditionalAttribute name="Last Name" value="Smith"/>
</AdditionalAttributes>
<AdditionalAttributes groupLabel="Additional">
<AdditionalAttribute name="email" value="John Smith(jsmith)"/>
<AdditionalAttribute name="Created Date" value="2016-04-20T19:50:01Z"/>
</AdditionalAttributes>
</Person>
the wanted, correct result is produced:
<Person>
<AdditionalAttributes groupLabel="Profile">
<AdditionalAttribute name="First Name" value="John"/>
<AdditionalAttribute name="Last Name" value="Smith"/>
</AdditionalAttributes>
<AdditionalAttributes groupLabel="Additional">
<AdditionalAttribute name="email" value="John Smith(jsmith@gmail.com)"/>
<AdditionalAttribute name="Created Date" value="2016-04-20T19:50:01Z"/>
</AdditionalAttributes>
</Person>
II. XSLT 2.0
This transformation uses AVT again and the XPath 2.0 replace()
function:
<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output omit-xml-declaration="yes" indent="yes"/>
<xsl:strip-space elements="*"/>
<xsl:template match="node()|@*">
<xsl:copy>
<xsl:apply-templates select="node()|@*"/>
</xsl:copy>
</xsl:template>
<xsl:template match="AdditionalAttribute[@name='email']">
<AdditionalAttribute name="email"
value="{replace(@value, '\)', '@gmail.com)')}">
<xsl:apply-templates select="@*[not(name()='value')]"/>
</AdditionalAttribute>
</xsl:template>
</xsl:stylesheet>