Solved

XML Change attribute Names By XSL

Posted on 2009-07-05
2
243 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Shoutout to Emily Plummer (http://www.experts-exchange.com/members/eplummer26.html) for giving me this article! She did most of it, I just finished it up and posted it for her :)    Introduction In a previous article (http://www.experts-exchang…
Introduction Knockoutjs (Knockout) is a JavaScript framework (Model View ViewModel or MVVM framework).   The main ideology behind Knockout is to control from JavaScript how a page looks whilst creating an engaging user experience in the least …
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The viewer will learn how to count occurrences of each item in an array.

689 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