Solved

XML Change attribute Names By XSL

Posted on 2009-07-05
2
222 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

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

The Confluence of Individual Knowledge and the Collective Intelligence At this writing (summer 2013) the term API (http://dictionary.reference.com/browse/API?s=t) has made its way into the popular lexicon of the English language.  A few years ago, …
Browsers only know CSS so your awesome SASS code needs to be translated into normal CSS. Here I'll try to explain what you should aim for in order to take full advantage of SASS.
Viewers will learn one way to get user input in Java. Introduce the Scanner object: Declare the variable that stores the user input: An example prompting the user for input: Methods you need to invoke in order to properly get  user input:
Viewers will learn about the regular for loop in Java and how to use it. Definition: Break the for loop down into 3 parts: Syntax when using for loops: Example using a for loop:

707 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

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now