By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,321 Members | 1,875 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,321 IT Pros & Developers. It's quick & easy.

Replacing tags within xml using xslt

P: 1
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
Share this Question
Share on Google+
1 Reply


Dököll
Expert 100+
P: 2,364
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

Post your reply

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