Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

XML Change attribute Names By XSL

Posted on 2009-07-05
2
Medium Priority
?
250 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 19

Accepted Solution

by:
zc2 earned 2000 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: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say 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

I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
Many times as a report developer I've been asked to display normalized data such as three rows with values Jack, Joe, and Bob as a single comma-separated string such as 'Jack, Joe, Bob', and vice versa.  Here's how to do it. 
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
The viewer will the learn the benefit of plain text editors and code an HTML5 based template for use in further tutorials.

610 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