473,385 Members | 2,274 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.

Merge XML within a file

Hello, I have an xml-file like this:
Expand|Select|Wrap|Line Numbers
  1.  
  2. <ROOT>
  3.   <ORDER_LINES>
  4.     <DATA>
  5.       <LINE_NO>1</LINE_NO>
  6.       <MISC_INFO/>
  7.     </DATA>
  8.     <DATA>
  9.       <LINE_NO>2</LINE_NO>
  10.       <MISC_INFO/>
  11.     </DATA>
  12.   </ORDER_LINES>
  13.  
  14.   <SORT>
  15.     <LINE_NO sort_no="2">1</LINE_NO>
  16.     <LINE_NO sort_no="1">2</LINE_NO>
  17.   </SORT>
  18. </ROOT>
  19.  
  20.  
In XSLT 1.0, how would I go about producing this output:

Expand|Select|Wrap|Line Numbers
  1.   <ORDER_LINES>
  2.     <DATA>
  3.       <LINE_NO sort_no="1">2</LINE_NO>
  4.       <MISC_INFO/>
  5.     </DATA>
  6.     <DATA>
  7.       <LINE_NO sort_no="2">1</LINE_NO>
  8.       <MISC_INFO/>
  9.     </DATA>
  10.   </ORDER_LINES>
  11.  
I hva tried differrent solutions for this over the past couple of days. But have failed in producing the desired output every time. The problem lies in merging the two nodes. (The tag xsl:sort helps me sort accordingly though).

Any help would be greatly appreciated.....
Dec 10 '08 #1
4 3263
Dormilich
8,658 Expert Mod 8TB
I wouldn't try to merge the nodes, replace one with its counterpart.
Expand|Select|Wrap|Line Numbers
  1. <xsl:template match="LINE_NO[not(ancestor-or-self::SORT)]">
  2.   <xsl:copy-of select="//LINE_NO[@sort_no = current()]"/>
  3. </xsl:template>
regards
Dec 10 '08 #2
jkmyoung
2,057 Expert 2GB
Suggest sort on apply-templates at the data element. It's hard to tell without seeing the rest of your code.
Expand|Select|Wrap|Line Numbers
  1. <xsl:template match="ORDER_LINES">
  2.   <xsl:copy>
  3.     <xsl:apply-templates select="DATA">
  4.       <xsl:sort select="//SORT/LINE_NO[.=current()/LINE_NO]/@sort_no"/>
  5.    </xsl:apply-templates>
  6.   </xsl:copy>
  7. </xsl:template>
  8. <xsl:template match="LINE_NO">
  9.    <xsl:copy-of select"//SORT/LINE_NO[.=current()]"/>
  10. </xsl:template>
  11. <xsl:template match="*"> <!-- default copy template -->
  12.   <xsl:copy>
  13.     <xsl:copy-of select="@*"/>
  14.     <xsl:apply-templates/>
  15.   </xsl:copy>
  16. </xsl:template>
  17.  
Dec 10 '08 #3
Wow, thank you all for quick replies. Problem is solved! Adopted both suggestions into my solution and it finally works.
Dec 11 '08 #4
Dormilich
8,658 Expert Mod 8TB
I'm pleased to hear that we could help.
Dec 11 '08 #5

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

Similar topics

2
by: Steve M | last post by:
I'm trying to do invoke the mail merge functionality of MS Word from a Python script. The situation is that I have a template Word document, and a record that I've generated in Python, and I want...
3
by: Richard Fritzler | last post by:
I was given the task of designing a complete web based document prep system. In simplest terms (using a msword explanation) create a database of merge fields, and a library of templates. Allow the...
8
by: Squirrel | last post by:
Hi everyone, I've created a mail merge Word doc. (using Office XP) , the data source is an Access query. Functionality I'm attempting to set up is: User sets a boolean field to true for...
4
by: John J. Hughes II | last post by:
Could someone explain how to merge the form menu with the mdi container window. The menu strip items on the form window merge but I either end up with a blank blue menu on the form or top list of...
4
by: Andreas Kasparek | last post by:
Hola! I'm preparing my master thesis about a XML Merge Tool implementation and was wondering if there is any open standard for XML diff regarding topics like: - is a diff result computed on...
0
by: Sheila | last post by:
I have set up a Word mail merge document of the type Directory which allows me to display all of the records on a single page rather than putting each record on a separate page. It uses a...
5
by: johnvon | last post by:
I have a mail merge that runs flawlessly in Access 2000. In 2003 I keep getting dialog boxes that I can't figure out how to supress. Several of them are telling me that Admin (me!) has the database...
3
by: Bishman | last post by:
Hi, I have some issues with the code below. These are: ONE: In code I open an existing document and 'attach' the Mail Merge data source, but the data is not poulating the merge fields...
7
by: giladp1 | last post by:
I found Albert Kallal's great "Super easy Word Merge" code in his site at: http://www.members.shaw.ca/AlbertKallal/msaccess/msaccess.html Thanks Albert so much for sharing this. I am looking...
9
by: Peter | last post by:
Does anyone has .NET library to merger RTF files? Thank You Peter
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...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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
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,...

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.