Solved

XML Change attribute Names By XSL

Posted on 2009-07-05
2
236 Views
Last Modified: 2013-11-18
Hi,
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.

0
Comment
Question by:Bagur
2 Comments
 
LVL 18

Accepted Solution

by:
zc2 earned 500 total points
ID: 24781754
Hi,
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>
	
	<xsl:template match="*">
		<xsl:copy>
			<xsl:apply-templates select="@* | * | text()"/>
		</xsl:copy>
    </xsl:template>
	
	<xsl:template match="text() | @*">
		<xsl:copy/>
    </xsl:template>
	
	<xsl:template match="@Name[parent::Field]">
		<xsl:attribute name="Name"><xsl:value-of select="."/>_abc</xsl:attribute>
    </xsl:template>
	
</xsl:stylesheet>

Open in new window

0
 

Author Closing Comment

by:Bagur
ID: 31599980
I can't thank you much! I was going nuts figuring it out..guys like u make our lives easy..
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

In this article you will learn how to create a free basic website on Bitbucket, a git service provider. Polymer creates dynamic HTML components, which allow more flexibility than static HTML. This tutorial uses Ubuntu Linux but can also be done on W…
JavaScript has plenty of pieces of code people often just copy/paste from somewhere but never quite fully understand. Self-Executing functions are just one good example that I'll try to demystify here.
The viewer will receive an overview of the basics of CSS showing inline styles. In the head tags set up your style tags: (CODE) Reference the nav tag and set your properties.: (CODE) Set the reference for the UL element and styles for it to ensu…
The viewer will the learn the benefit of plain text editors and code an HTML5 based template for use in further tutorials.

679 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question