• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 261
  • Last Modified:

XML Change attribute Names By XSL

In the below xml document, if I need to change the "Name" attribute of all the Field Nodes to current name + "_abc", how do I do that with xsl? I need full xsl.

<FormHtmData><Field Name="Cls1" Value="2"></Field><Field Name="Cls2" Value="0"></Field><Field Name="Cmnt_1" Value="comment"></Field></FormHtmData>

The desired output is this
<FormHtmData><Field Name="Cls1_abc" Value="2"></Field><Field Name="Cls2_abc" Value="0"></Field><Field Name="Cmnt_1_abc" Value="comment"></Field></FormHtmData>

Thanks much in advance.

1 Solution
Below is a copy XSLT, which also adds the "_abc" to the "Name" attribute values:
<?xml version="1.0"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
	<xsl:output method="xml" indent = "yes"/>
	<xsl:template match="/">
		<xsl:apply-templates select="*"/>
	<xsl:template match="*">
			<xsl:apply-templates select="@* | * | text()"/>
	<xsl:template match="text() | @*">
	<xsl:template match="@Name[parent::Field]">
		<xsl:attribute name="Name"><xsl:value-of select="."/>_abc</xsl:attribute>

Open in new window

BagurAuthor Commented:
I can't thank you much! I was going nuts figuring it out..guys like u make our lives easy..
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

The 14th Annual Expert Award Winners

The results are in! Meet the top members of our 2017 Expert Awards. Congratulations to all who qualified!

Tackle projects and never again get stuck behind a technical roadblock.
Join Now