473,385 Members | 1,942 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Replacing tags within xml using xslt

Hi,

I want to convert xml in one format into another xml format shown below

Input xml :
Expand|Select|Wrap|Line Numbers
  1. <Name>
  2.    <Name1>
  3.        <Name11>Name11</Name11>
  4.        <Name12>Name12</Name12>
  5.    </Name1>
  6.    <Name1>
  7.        <Name11>Name21</Name11>
  8.        <Name12>Name22</Name12> 
  9.    </Name1> 
  10.    <Name2>
  11.        <Name1>
  12.            <Name11>Name11</Name11>
  13.            <Name12>Name12overRide</Name12>
  14.       </Name1>  
  15.       <Name3> 
  16.            <Name31>Name3Override</Name31>
  17.        </Name3>
  18.    </Name2>
  19.  <Name3>
  20.        <Name31>Name3Origional</Name31>
  21.  </Name3>
  22.  <Name3>
  23.        <Name32>Name3Origional</Name32> 
  24.  </Name3>
  25. </Name>
  26.  
Output xml

Expand|Select|Wrap|Line Numbers
  1. <Name>
  2.    <Name1>
  3.        <Name11>Name11</Name11>
  4.        <Name12>Name12overRide</Name12>
  5.    </Name1>
  6.    <Name1>
  7.        <Name11>Name21</Name11> 
  8.        <Name12>Name22</Name12>
  9.    </Name1> 
  10.    <Name2>
  11.    </Name2>
  12.  <Name3>
  13.            <Name31>Name3Override</Name31>
  14.  </Name3>
  15.  <Name3> 
  16.        <Name32>Name3Origional</Name32>
  17.  </Name3>
  18. </Name>
  19.  
Basically, Name2 tags stores Overriden information for the tag which are already present inside Name root tag.
i want generic template which does this replacing node based on pre - comparision.
i just know like Name2 is the only tag which stores overRiding information for Node's child tag.
Scenario :
1. While replacing \\Name\Name1 tag, i just know like i have to compare \\Name\Name2\Name1\Name11 with \\Name\Name1\Name11,
If this value matches, i need to replace \\Name\Name1 tag with \\Name\Name2\Name1 tag.
Also only \\Name\Name1 tag which satisfies this condition will replace, all other \\Name\Name1 tags remain same.
2. While replacing \\Name\Name3, i just know like i have to compare \\Name\Name2\Name3\Name31 with \\Name\Name3\Name31,
If this value matches, i just have to replace that \\Name\Name3 node with \\Name\Name2\Name3.
3. This replacing this should be cut paste kind of thing, not copy paste.

Please help me to find its solution,

Please Reply.

Thanks,
Jun 20 '07 #1
1 4481
Dököll
2,364 Expert 2GB
Hi,

I want to convert xml in one format into another xml format shown below

Input xml :

Expand|Select|Wrap|Line Numbers
  1. <Name>
  2.    <Name1>
  3.        <Name11>Name11</Name11>
  4.        <Name12>Name12</Name12>
  5.    </Name1>
  6.    <Name1>
  7.        <Name11>Name21</Name11>
  8.        <Name12>Name22</Name12> 
  9.    </Name1> 
  10.    <Name2>
  11.        <Name1>
  12.            <Name11>Name11</Name11>
  13.            <Name12>Name12overRide</Name12>
  14.       </Name1>  
  15.       <Name3> 
  16.            <Name31>Name3Override</Name31>
  17.        </Name3>
  18.    </Name2>
  19.  <Name3>
  20.        <Name31>Name3Origional</Name31>
  21.  </Name3>
  22.  <Name3>
  23.        <Name32>Name3Origional</Name32> 
  24.  </Name3>
  25. </Name>
  26.  
Output xml

Expand|Select|Wrap|Line Numbers
  1. <Name>
  2.    <Name1>
  3.        <Name11>Name11</Name11>
  4.        <Name12>Name12overRide</Name12>
  5.    </Name1>
  6.    <Name1>
  7.        <Name11>Name21</Name11> 
  8.        <Name12>Name22</Name12>
  9.    </Name1> 
  10.    <Name2>
  11.    </Name2>
  12.  <Name3>
  13.            <Name31>Name3Override</Name31>
  14.  </Name3>
  15.  <Name3> 
  16.        <Name32>Name3Origional</Name32>
  17.  </Name3>
  18. </Name>
  19.  
3. This replacing this should be cut paste kind of thing, not copy paste.

Please help me to find its solution,

Please Reply.

Thanks,
We hear you loud and clear, patelgaurav85!

Please stay tuned while we figure this all out, surely doable.

Question for you:

I am assuming you want to use XSLT to compare the Input XML against the Output one, and if something's missing in the Output one to modify and add. Is this correct.

Please write if you would. Thanks, patelgaurav85!

Dököll
Jun 24 '07 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: Spence Hackney | last post by:
I am using ASP.NET to get XML data from a database, style it with an XSLT, and then display it as HTML to a browser. The content in the database, which becomes my XML, has HTML tags embedded in...
3
by: Francis Hwang | last post by:
Hi, Maybe this is a newbie question, but: Is there a way to output an element's contents -- including contained nodes and free-form text -- without the containing tags? I can imagine that...
2
by: Xtr | last post by:
Hello, Is it possible, using xsl, to indent most tags, but preserve the position of tags that are inline (surrounded by text)? For example, given the following,: ...
5
by: Donald Firesmith | last post by:
Are html tags allowed within meta tags? Specifically, if I have html tags within a <definition> tag within XML, can I use the definition as the content within the <meta content="description> tag? ...
8
by: Kathleen Dollard | last post by:
Hi, Oleg's answer about attribute value templates led me to look back at a different problem, and wonder if someone else had solved it. I want to output an ASP.NET page. Thus I need to output...
7
by: Ryan Taylor | last post by:
Hi. I have some code that dynamically generates a PDF and spits this content directly to the web browser. I use HTMLDoc to create the Pdf's from html. So the user can click on a button "Print...
5
by: Thierry | last post by:
Let's say I have the following tags in an xml: <World> <Country>Canada</Country> <Hemisphere>North</Hemisphere> <Weather climate="cold" forecast="snow"> <CommandAction>$(HOME)\calculate.py...
6
by: tentstitcher | last post by:
Hi all: I have a source xml document with an element of type string. This element contains something like the following: <stringData> &lt;Header&gt; &lt;Body&gt; </stringData> I would like to apply an...
2
by: Andy | last post by:
Hi, I have an ASP.NET webpage that contains an ASP.NET XML control. This control accepts an XSLT stylesheet and XML document which it then uses to render HTML code where the XML control is...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.