473,326 Members | 2,680 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,326 software developers and data experts.

Splitting XML document based on a child node value

Hi All,

I have a requirement to split an incoming XML document based on a child node value. Here is snippet of my source XML.

Expand|Select|Wrap|Line Numbers
  1. <Select_Groupid_Collection>
  2. <Select_Groupid_Output> 
  3.   <USER_NAME>User1</USER_NAME> 
  4.   <DOC_DATE>2010-10-31T00:00:00.000-05:00</DOC_DATE> 
  5.   <DOC_TYPE>SE</DOC_TYPE> 
  6.   <ARR_ID>ARR1</ARR_ID> 
  7. </Select_Groupid_Output>
  8. <Select_Groupid_Output> 
  9.   <USER_NAME>User2</USER_NAME> 
  10.   <DOC_DATE>2010-10-31T00:00:00.000-05:00</DOC_DATE> 
  11.   <DOC_TYPE>SF</DOC_TYPE> 
  12.   <ARR_ID>ARR2</ARR_ID> 
  13. </Select_Groupid_Output>
  14. <Select_Groupid_Output> 
  15.   <USER_NAME>User3</USER_NAME> 
  16.   <DOC_DATE>2010-10-31T00:00:00.000-05:00</DOC_DATE> 
  17.   <DOC_TYPE>SF</DOC_TYPE> 
  18.   <ARR_ID>ARR1</ARR_ID> 
  19. </Select_Groupid_Output>
  20. <Select_Groupid_Output> 
  21.   <USER_NAME>User4</USER_NAME> 
  22.   <DOC_DATE>2010-10-31T00:00:00.000-05:00</DOC_DATE> 
  23.   <DOC_TYPE>SF</DOC_TYPE> 
  24.   <ARR_ID>ARR3</ARR_ID> 
  25. </Select_Groupid_Output>
  26. <Select_Groupid_Output> 
  27.   <USER_NAME>User5</USER_NAME> 
  28.   <DOC_DATE>2010-10-31T00:00:00.000-05:00</DOC_DATE> 
  29.   <DOC_TYPE>SE</DOC_TYPE> 
  30.   <ARR_ID>ARR2</ARR_ID> 
  31. </Select_Groupid_Output>
  32. </Select_Groupid_Collection>
  33.  
I want the output to be split into 3 XMLs, based on ARR_ID. For each unique ARR_ID a separate XML has to be generated.

xml1
Expand|Select|Wrap|Line Numbers
  1. <Select_Groupid_Collection>
  2. <Select_Groupid_Output> 
  3.   <USER_NAME>User1</USER_NAME> 
  4.   <DOC_DATE>2010-10-31T00:00:00.000-05:00</DOC_DATE> 
  5.   <DOC_TYPE>SE</DOC_TYPE> 
  6.   <ARR_ID>ARR1</ARR_ID> 
  7. </Select_Groupid_Output>
  8. <Select_Groupid_Output> 
  9.   <USER_NAME>User3</USER_NAME> 
  10.   <DOC_DATE>2010-10-31T00:00:00.000-05:00</DOC_DATE> 
  11.   <DOC_TYPE>SF</DOC_TYPE> 
  12.   <ARR_ID>ARR1</ARR_ID> 
  13. </Select_Groupid_Output>
  14. </Select_Groupid_Collection>
xml2
Expand|Select|Wrap|Line Numbers
  1. <Select_Groupid_Collection>
  2. <Select_Groupid_Output> 
  3.   <USER_NAME>User2</USER_NAME> 
  4.   <DOC_DATE>2010-10-31T00:00:00.000-05:00</DOC_DATE> 
  5.   <DOC_TYPE>SF</DOC_TYPE> 
  6.   <ARR_ID>ARR2</ARR_ID> 
  7. </Select_Groupid_Output>
  8. <Select_Groupid_Output> 
  9.   <USER_NAME>User5</USER_NAME> 
  10.   <DOC_DATE>2010-10-31T00:00:00.000-05:00</DOC_DATE> 
  11.   <DOC_TYPE>SE</DOC_TYPE> 
  12.   <ARR_ID>ARR2</ARR_ID> 
  13. </Select_Groupid_Output>
  14. </Select_Groupid_Collection>
xml3
Expand|Select|Wrap|Line Numbers
  1. <Select_Groupid_Collection>
  2. <Select_Groupid_Output> 
  3.   <USER_NAME>User4</USER_NAME> 
  4.   <DOC_DATE>2010-10-31T00:00:00.000-05:00</DOC_DATE> 
  5.   <DOC_TYPE>SF</DOC_TYPE> 
  6.   <ARR_ID>ARR3</ARR_ID> 
  7. </Select_Groupid_Output>
  8. </Select_Groupid_Collection>
  9.  
Any suggestions how this can be done using XSLT. I read about the grouping concept in XSLT from below link
http://www.jenitennison.com/xslt/gro...muenchian.html

But not sure how the XML can be split..
Oct 22 '10 #1
1 2214
jkmyoung
2,057 Expert 2GB
Are you using XSLT 2.0? If so, XSLT 2.0 has a result-document function http://www.w3.org/TR/xslt20/#element-result-document

Expand|Select|Wrap|Line Numbers
  1. <xsl:result-document href="arr1.xml">
  2.  
I can't recall if the href can be set dynamically, eg in braces {}.

If you're not using XSLT 2.0 the solution may depend on your transformation engine (many of which have similar functionality) or you might have to run the same transformation several times. If so, I suggest creating 1 XSLT with a parameter you can pass in as opposed to creating multiple XSLT stylesheets.
Oct 25 '10 #2

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

Similar topics

0
by: CoolPint | last post by:
I am trying to write a generic heapsort (of course as a self-exercise) with Iterator interface: something like blow.... But I got into trouble finding out the Iterator to the Child node. If...
3
by: keepyourstupidspam | last post by:
Hi, I am using xerces dom C++, I want to change an element value, here is the code I am using but the element in the file is not getting updated. ... ... ... xercesc_2_4::DOMDocument*...
5
by: B-Dog | last post by:
I want to be able to detect if a user has selected a parent or child node in a treeview and depending on which is clicked act accordingly based on the tag. I can get the values but don't know if...
1
by: gplott | last post by:
I have an XML document that has multiple childe nodes like the one at the end of this message What syntax would I use with selectNodes to select all viewentry nodes that have an entrydata...
1
by: Rajarshi | last post by:
Hi, I'm using ElementTree for some RSS processing. The point where I face a problem is that within an <item></itemI need to add another child node (in addition to <linketc) which is a well-formed...
0
by: Thomas | last post by:
How do you create an XML document based on an XML Schema? I have an XML Schema that defines several primary XML document types (i.e. the top-level element contains 4 complex type child elements...
1
by: Tedros.G | last post by:
Hi I have an attribute the appears in both the root node and child node for example, below the attribute VERSION appears in the rood node (PRODMSG ) and a child node (OPERATION ) ================...
2
by: ofuuzo1 | last post by:
Hei, I have the following xml file and I have tried to write xslt to extract only the values of the first "record" node. It does not work. I need some help. I used ---- to represent indent. ...
20
omerbutt
by: omerbutt | last post by:
hi there i am making an application in which i have to populate columns that consist of some textfields and some input boxes the problem is at the mozilla's end, it creates a new node and appends the...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....

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.