How to combine data?

Hello,

Sorry if this question has been asked before, this is the first time I 
encounter this problem. I have 2 XML files

1st file:

<record ID = "1">
     <title>some text</title>
</record>

<record ID = "2">
     <title>more text</title>
</record>

<record ID = "3">
     <title>another text</title>
</record>

2nd file:

<info ID = "1">
    <desc>some information here</desc>
    <url>http://some_links_ here</url>
</info>

<info ID = "2">
    <desc>more information here</desc>
    <url>http://more_links_ here</url>
</info>

<info ID = "3">
    <desc>another information here</desc>
    <url>http://another_linsk_here</url>
</info>

I need to insert information from the second file into first by matching ID 
records. Leaving structure and information in original file intact, just 
adding matching records from the second file, so the output result will be:


<record ID = "1">
    <title>some text</title>
    <desc>some information here</desc>
    <url>http://some_links_ here</url>
</record>

<record ID = "2">
     <title>more text</title>
     <desc>more information here</desc>
     <url>http://more_links_ here</url>
</record>

<record ID = "3">
     <title>another text</title>
    <desc>another information here</desc>
    <url>http://another_linsk_here</url>
</record>

Not sure what approach to use - any help is appreciated.

Thanks in advance,

Yuriy. 


0
yuri1 (10)
10/2/2007 2:38:25 PM
dotnet.xml 7266 articles. 0 followers. Follow

8 Replies
577 Views

Similar Articles

[PageSpeed] 52

One way is to use XSLT for that.
For instance if your input file is
<records>
  <record ID="1">
    <title>some text</title>
  </record>
  <record ID="2">
    <title>more text</title>
  </record>
  <record ID="3">
    <title>another text</title>
  </record>
</records>


and you have an info.xml file containing
<information>
  <info ID="1">
    <desc>some information here</desc>
    <url>http://some_links_ here</url>
  </info>
  <info ID="2">
    <desc>more information here</desc>
    <url>http://more_links_ here</url>
  </info>
  <info ID="3">
    <desc>another information here</desc>
    <url>http://another_linsk_here</url>
  </info>
</information>


then the following stylesheet will give you the desired result:

<?xml version="1.0"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/
Transform">
 <xsl:variable name="info" select="document('info.xml')/*/*"/>
 <xsl:template match="node() | @*">
   <xsl:copy>
    <xsl:apply-templates select="node() | @*"/>
   </xsl:copy>
  </xsl:template>
 <xsl:template match="record">
  <xsl:copy>
   <xsl:apply-templates select="node() | @*"/>
   <xsl:apply-templates select="$info[@ID=current()/@ID]/*"/>
  </xsl:copy>
 </xsl:template>

</xsl:stylesheet>

Regards,
George
---------------------------------------------------------------------
George Cristian Bina - http://aboutxml.blogspot.com/
<oXygen/> XML Editor, Schema Editor and XSLT Editor/Debugger
http://www.oxygenxml.com

0
george5726 (13)
10/3/2007 2:46:40 PM
Wow this is really neat, big thanks. Another question I have - what if I 
want to pass both filename and path to joining element as parameters? It 
works for the filename, so I can do something like:

   <xsl:param name="i_sBaseFileName" />
   <xsl:variable name="oJoinData" select="document($i_sBaseFileName)" />

But it doesn't work if I want to specify a path as a parameter:

   <xsl:param name="i_sBaseFileName" />
   <xsl:param name="i_sDataPath" />

   <xsl:variable name="oJoinData" 
select="document($i_sBaseFileName)$i_sDataPath" />

The parsers throws an error. Any idea how to do this?

Thanks!


0
yuri1 (10)
10/3/2007 6:44:22 PM
Forgot to ask one more thing.

Is there a way to do a template match to a variable or parameter? I.e.:

<xsl:param name="i_sSrcPath" />
....
<xsl:template match="$i_sSrcPath">


Thanks.


"Yuriy Galanter" <yuri@galanter.net> wrote in message 
news:uOr021eBIHA.1208@TK2MSFTNGP03.phx.gbl...
> Wow this is really neat, big thanks. Another question I have - what if I 
> want to pass both filename and path to joining element as parameters? It 
> works for the filename, so I can do something like:
>
>   <xsl:param name="i_sBaseFileName" />
>   <xsl:variable name="oJoinData" select="document($i_sBaseFileName)" />
>
> But it doesn't work if I want to specify a path as a parameter:
>
>   <xsl:param name="i_sBaseFileName" />
>   <xsl:param name="i_sDataPath" />
>
>   <xsl:variable name="oJoinData" 
> select="document($i_sBaseFileName)$i_sDataPath" />
>
> The parsers throws an error. Any idea how to do this?
>
> Thanks!
>
> 


0
yuri1 (10)
10/3/2007 6:56:47 PM
No, neither of the two work.
Some processors provide an evaluate extension that allows you to
evaluate a string as an XPath expression. In many cases however that
is not actually needed as you rewrite the test in a slightly different
way. Here you have an example: imagine you want to iterate the
elements with a specific name that are children of the current
element. Normally if you know that name you can write

<xsl:for-each select="myElement"> ...

But if the element name is an a variable or parameter named element
then you cannot have

<xsl:for-each select="$element"> ...

but instead you can write

<xsl:for-each select="*[name()=$element]"> ...

Best Regards,
George
---------------------------------------------------------------------
George Cristian Bina - http://aboutxml.blogspot.com/
<oXygen/> XML Editor, Schema Editor and XSLT Editor/Debugger
http://www.oxygenxml.com

0
george5726 (13)
10/4/2007 6:06:44 AM
Thanks again!

I will give it a try. 


0
yuri1 (10)
10/4/2007 12:27:39 PM
Another question for the guru ;)

The XSL works great to copy all elements  from the matching node of external 
file into current node. But how do I modify the line:

 <xsl:apply-templates select="$info[@ID=current()/@ID]/*"/>

To copy only those elements that _don't already exist_ in current node?

I tried something like

 <xsl:apply-templates select="$info[@ID=current()/@ID]/*[name() != 
name(current()/*)"/>

But it matches only first name in current elements nodeset.

Thanks!


"George Bina" <george@oxygenxml.com> wrote in message 
news:1191422800.027028.27700@50g2000hsm.googlegroups.com...
> One way is to use XSLT for that.
> For instance if your input file is
> <records>
>  <record ID="1">
>    <title>some text</title>
>  </record>
>  <record ID="2">
>    <title>more text</title>
>  </record>
>  <record ID="3">
>    <title>another text</title>
>  </record>
> </records>
>
>
> and you have an info.xml file containing
> <information>
>  <info ID="1">
>    <desc>some information here</desc>
>    <url>http://some_links_ here</url>
>  </info>
>  <info ID="2">
>    <desc>more information here</desc>
>    <url>http://more_links_ here</url>
>  </info>
>  <info ID="3">
>    <desc>another information here</desc>
>    <url>http://another_linsk_here</url>
>  </info>
> </information>
>
>
> then the following stylesheet will give you the desired result:
>
> <?xml version="1.0"?>
> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/
> Transform">
> <xsl:variable name="info" select="document('info.xml')/*/*"/>
> <xsl:template match="node() | @*">
>   <xsl:copy>
>    <xsl:apply-templates select="node() | @*"/>
>   </xsl:copy>
>  </xsl:template>
> <xsl:template match="record">
>  <xsl:copy>
>   <xsl:apply-templates select="node() | @*"/>
>   <xsl:apply-templates select="$info[@ID=current()/@ID]/*"/>
>  </xsl:copy>
> </xsl:template>
>
> </xsl:stylesheet>
>
> Regards,
> George
> ---------------------------------------------------------------------
> George Cristian Bina - http://aboutxml.blogspot.com/
> <oXygen/> XML Editor, Schema Editor and XSLT Editor/Debugger
> http://www.oxygenxml.com
> 


0
yuri1 (10)
10/5/2007 4:49:13 PM
<?xml version="1.0"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/
Transform">
 <xsl:variable name="info" select="document('info.xml')/*/*"/>
 <xsl:template match="node() | @*">
  <xsl:copy>
   <xsl:apply-templates select="node() | @*"/>
  </xsl:copy>
 </xsl:template>
 <xsl:template match="record">
  <xsl:variable name="thisRecord" select="."/>
  <xsl:copy>
   <xsl:apply-templates select="node() | @*"/>
   <xsl:for-each select="$info[@ID=current()/@ID]/*">
    <xsl:variable name="name" select="name()"/>
    <xsl:if test="not($thisRecord/*[name()=$name])">
     <xsl:apply-templates select="."/>
    </xsl:if>
   </xsl:for-each>
     </xsl:copy>
 </xsl:template>

</xsl:stylesheet>

Regards,
George
---------------------------------------------------------------------
George Cristian Bina -http://aboutxml.blogspot.com/
<oXygen/> XML Editor, Schema Editor and XSLT Editor/Debugger
http://www.oxygenxml.com

0
george5726 (13)
10/5/2007 5:22:29 PM
Thanks!

I will give it a try. 


0
yuri1 (10)
10/5/2007 5:58:14 PM
Reply:

Similar Artilces:

How can I create a chart to compare multiple data series?
Using Excel, is there a way to merge multiple charts with different data series into one to demonstrate a direct comparison of the data series within one single chart. I've got 4 charts of the stacked column type. magnoliak77 Tufte calls them small multiples, Cleveland calls them trellis displays. I call them panel charts. Take a look at the examples on this page. http://processtrends.com/toc_panel_charts.htm Another option is to stick with your 4 charts, however, you can size and align them. Here's a link to a simple macro that sizes and aligns all charts on a single sheet....

Mails Combined
HI, I mistakenly delete all mails from Inbox and then found them on the deleted Items and selected all and ask to move folders back to Inbox. the problem is all mails were combined into one email and moved back in to Inbox as a single email. How do i go back to the original version. How do i uncombined all the mails in to individual mails from the right recipient? Please help ASAP.. Submitted using http://www.outlookforums.com ...

merge/combine workshhets
I need to merge about 75 worksheets into one spreadsheet on a regular basis - all have exactly the same format/layout etc back can vary in the number of rows Try this Jeff http://www.rondebruin.nl/copy3.htm -- Regards Ron de Bruin http://www.rondebruin.nl "Jeff224" <Jeff224@discussions.microsoft.com> wrote in message news:C6790506-2888-4F4D-80EA-BB0D9F9B27A2@microsoft.com... >I need to merge about 75 worksheets into one spreadsheet on a regular basis - > all have exactly the same format/layout etc back can vary in the number of > rows Or http://www.rondebru...

Documenting the backup of data
This may not be the place to ask however i am looking for resources on how i may document data I am backing up from an oracle database to MS Access. Basically I have my oracle database and i have an Acess database. I have to back up 3 tables from oracle into access. I have no idea how i would document this. I want to say Columns 1, column 2 from table A in oracle will be backed up to Column 1a and Column 1b in Access. Has anyone had similar exeperiences? Does anyone know of any resources on the net or example? ...

numbers in data sheet of stacked bar chart
I'm trying to label segments in a stacked bar chart, example: 1-10, 11-20, etc. I'm not able to enter the number with the dash. In most cases it automatically changes to Jan-10. Any tips on how I can fix this? Thanks! Format the cell as text and see if that helps. -- Echo [MS PPT MVP] http://www.echosvoice.com What's new in PPT 2010? http://www.echosvoice.com/2010.htm Fixing PowerPoint Annoyances http://tinyurl.com/36grcd PowerPoint 2007 Complete Makeover Kit http://tinyurl.com/32a7nx "Genevieve" <Genevieve@discussions.microsoft.com> wrote in me...

Data from one sheet to another sheets
Dear Sir, I have a ZoneWise Worksheet i;e nz01,nz02,nz03.wz01,wz02,wz03,sz01,sz02,sz03 and so on. Now i want to copy this data according to ZoneWise For example: nz01 in sheet1, nz02 in sheet2, wz01 in sheet 3 and so no Thanks In Advance Hardeep kanwar ...

Finding the combination that appears more times
Hi everybody i have a list on excel 2007 that displays the purchase of items on columns A:E, each column showing one (1) item I want to find what combination of items appears more times, especifically, which combination of four (4) is the favorite mix eg: A B C D F A C D E F B C D E F B C D F Z in this example, the winner would be (B, C, D, E) as it appears 3 times the main problem is that I have over 1,000 rows and trying with =SUMPRODUCT(COUNTIF(A1:E1,$N$1:$R$1)) por each combination would take forever... is there a simpler, quicker ...

Combining Publications
Can I combine two different publications into one? Suzi wrote: > Can I combine two different publications into one? ========================================= Personally, I would simply open two instances of Publisher (one document in each) / tile the two screens...and copy/paste. Maybe the following link will be useful: Combining Publisher Documents http://tinyurl.com/2lpj5w -- John Inzer MS Picture It! - Digital Image MVP Digital Image Highlights and FAQs http://tinyurl.com/aczzp Notice This is not tech support I am a volunteer Solutions that wo...

transfer of data
Is there a way to transfer data that is in outlook to an exce spreadsheet. I have name, address, city, state, zip, all phone numbers that I woul like to send to certain cells in a spreadsheet. If this is possible, what code could I write help me do this? :confused: Thank You Michae -- Message posted from http://www.ExcelForum.com Hi in Outlook you can save your data as *.csv file. Open this exported file in Excel -- Regards Frank Kabel Frankfurt, Germany "daniels012 >" <<daniels012.1byt7v@excelforum-nospam.com> schrieb im Newsbeitrag news:daniels012.1byt7v@excel...

Combining 2 Excel (xls) files
I have 2 xls workbooks with different sheet names and both with different range names. I would like to combine them both into one workbook so that I don't have to re-create all of the range names. Is there a way to do that? -- LAF ------------------------------------------------------------------------ LAF's Profile: http://www.excelforum.com/member.php?action=getinfo&userid=9656 View this thread: http://www.excelforum.com/showthread.php?threadid=346017 Hi LAF- Open both files (let's call them A & B, and assume A will be your "combined" file). Working i...

How to Combine Data in Different Columns
Hi Everyone I need help in this issue. I have tried many ways though some wer successful but they were not efficient. I have say 5 columns of data and the data could be on the same rows o all 5 columns or on different rows hence if I need to combine all th data of these 5 columns, I would have to sort or filter each of the manually and copy and paste to a different worksheet or column. This i very tedious and time consuming. I also tried to write a macro to loo for data in one column then put them into another column but i was no successful. However, experts like you guys shouldn't have ...

CDATA, XmlTextWriter, Read data
Hi All, I am using XmlTextWriter to write CDATA section using following code: XmlTextWriter xtw = new XmlTextWriter(Console.Out); xtw.WriteStartElement("data"); xtw.WriteCData("UNSAFE SCRIPT DATA CONTAINING & and < WHICH GETS CONVERTED TO &amp; and &lt;. SO HAVE TO USE WriteCData() METHOD HERE"); xtw.WriteEndElement(); xtw.Flush(); xtw.Close(); I suppose the data gets written to xtw instance. Now I want to retrieve the data back. How should I do that? Please let me know ASAP. Thanks, Gem Pramod wrote: > Hi All, > > I am using XmlTextWriter to ...

combinations
I have a finite number of values that represent length (right now I have less than 20 values). Can Excel take these values and list all possible combinations of the values? Any pointers appreciated. Stephen R. Stephen, No. There are 2,432,902,008,176,640,000 possible ways to combine 20 different values. That is, unless you have another limitation, like only using 4 at a time.... HTH, Bernie MS Excel MVP "Stephen R" <nospam@nospam.com> wrote in message news:u9ZiYhOeFHA.1456@TK2MSFTNGP15.phx.gbl... > I have a finite number of values that represent length (right...

Sorting rows of repetitive data
I have 12 months annual line item spend data and within that the same part number repeats several times. How do I produce a consolidated report with repetitive line items rolled up to one line item entry? So the total number of part number 1234 showing as one line item instead of six, the total of part number 5678 as a second line item, etc. I can create sub totals but I cannot find a way to consolidate to just one row for the total of each part number. Have you tried using pivot table? Sounds like a good fit. Check http://peltiertech.com/Excel/Pivots/pivotstart.htm for how to info....

How can i see a data change?
i need help with a problem i want to be able to see when values have been updated in a spreadsheet. My thoughts are pointing towards the font changing colour when a value has been increased and a seperate colour when the value has decreased. I am using Excel 2003 Thanks in advance Mickky --------------= Posted using GrabIt =---------------- ------= Binary Usenet downloading made easy =--------- -= Get GrabIt for free from http://www.shemes.com/ =- On Apr 20, 4:11=A0am, "Mickky" <mbro...@ntlworld.com> wrote: > i need help with a problem > > i want to be abl...

Combine 2 Charts 2007 Excel
I have a line chart (looks like an S curve graph) with two rows of data below & this chart looks exactly like I want it to. Period % Complete Dec-04 7% Jan-05 9% Feb-05 10% Mar-05 12% Apr-05 14% May-05 19% Jun-05 22% Jul-05 23% Aug-05 24% Sep-05 26% Oct-05 28% Nov-05 32% Dec-05 36% Jan-06 40% Feb-06 45% Mar-06 50% Apr-06 55% May-06 59% Jun-06 63% Jul-06 66% Aug-06 71% Sep-06 75% Oct-06 78% Nov-06 81% Dec-06 85% Jan-07 87% Feb-07 89% Mar-07 91% Apr-07 93% May-07 94% Jun-07 94% Jul-07 95% Aug-07 95% Sep-07 95% Oct-07 95% Nov-07 95% Dec-07 95% Jan-08...

filtering data #2
I have a column with copied formular till row # 3,000. I've entered data into 10 rows. But, when I filter the data the next row for the data entries is 3,001. How could I make the next empty row (11) available for the data entries after applying filtering. Thanks I usually copy and paste my filtered data over to another worksheet for further processing......... Vaya con Dios, Chuck, CABGx3 "Alex" <Alex@discussions.microsoft.com> wrote in message news:13D48C9E-FA34-48FB-A10C-386CC0E8DBE1@microsoft.com... > I have a column with copied formular till row # 3,000. I&#...

Removing Fixed Assets data from company
Hi there, Does anyone know what the best way is to remove all fixed assets data from a company? Thank you, Ian Tools >> Utilities >> Fixed Assets >> Clear Data. Make a backup before you do this. -- Charles Allen, MVP "Ian2009" wrote: > Hi there, > > Does anyone know what the best way is to remove all fixed assets data from a > company? > > Thank you, > Ian Thanks Charles for the help Ian "Charles Allen" wrote: > Tools >> Utilities >> Fixed Assets >> Clear Data. > > Make a backup before yo...

combining worksheets
I have a number of identically structured worksheets. I wish to treat them as alternative realities, assigning a probability of occurrence to each. I want to combine all this into a probabilistically "average" worksheet. Anybody have a good way to do this? Thanks mike Mike - You can set up one spreadsheet with the spreadsheets listed and the weighting you want to assign to each. Then set up another spreadsheet that will contain the results. Copy any header / row information from one of the spreadsheets, then for each cell you want 'averaged', enter a f...

Automatic number combination
I have Table 1 with Field IDTable1 [autonumber] [and other fields] and Table 2 with Field IDTable2 [autonumber] and Field GRV set to text [and other Fields] Is the following posibble: Can I automatically generate a number that can be used in GRV field of Table 2 consisting out of a combination of IDTable1 and IDTable2 written as IDTable1/IDTable2 in the GV field of Table 2 I want this GRV number as a unique number identifying Table 1 and Table 2 Thanks for the help You can, but shouldn't. All data in a table must identify the key. Foreign Keys, which are the keys f...

How do I group multiple sets of data for stacked bar chart?
I want to create a stcked column chart with 4 groups of dataset each containing 3 values. 3 values should be stacked in a column and each column should represent a group. Can anyone please help me? Arrange your data like this. Keep the top left cell blank, then create the stacked column chart with series in columns. Bottom Middle Top Group 1 X X X Group 2 X X X Group 3 X X X Group 4 X X X - Jon ------- Jon Peltier, Microsoft Excel MVP Peltier Technical Services Tutorials and Custom Solutions http://Peltier...

Data Recovrey and passwords
I placed my faulty hard drive in an enclosure. When I click on Documents and settings, followed by computer owner, I get a message saying access denied. How do I get it to ask for password so I can copy data to new hard drive? Are there any options to recover the data? Thanks RGH =?Utf-8?B?UkdI?= <RGH@discussions.microsoft.com> wrote in news:6A2D460E-5327-4640-9AB2-BD39E7F3ECE2@microsoft.com: > I placed my faulty hard drive in an enclosure. When I click on > Documents and settings, followed by computer owner, I get a message > saying access denied. How do I get ...

Data Transfer Among Dialogs, Views, and Documents
OS: Windows 2000 IDE: MS VS .NET 2002 Language: VC++ Hello I'm a novice MFC developer and I have run across a problem I was hoping someone could assist me with. I'm developing an SDI application with multiple views. In one of the views, I have a button that opens a dialog. I would like to have this dialog dynamically modify several of the controls based on information from the document class. The controls that need to be modified all have associated member control variables added to the dialog class. In my application, the view class processes information and stores numerical values...

Combined multiple IFs and AND functions
Hi, I have a problem coming up with an IF statement for the below scenario. Scenario A = Y B = N where Y is Yes and N is No. The Y and N is entered by the user. If A= Y and B= Y, execute A1 If A= Y and B= N, execute B1 If A= N and B= Y, execute C1 If A= N and B= N, execute D1 I used an "IF(AND(...,...)", however, I got #Value! for the answer. Can someone please help? Thanks in advance Hi one way (if you enter value A in cell E1 and value B in cell F1) =IF(E1="Y",IF(F1="Y",A1,IF(F1="N",B1,"not defined")),IF (E1="N",IF(F1="...

Identify end of data in worksheet, prevent overshoot
When scrolling down through many rows I often find that I way overshoot the end of my data. Is there a way to identify a row as the last row of data so that when using the mouse in the down scroll bar the cursor in the bar would botttom out at the last row of data? OR some other way to prevent overshooting? Ctrl + End key should normally take you to the last cell Regards, Peo Sjoblom "VPH" wrote: > When scrolling down through many rows I often find that I way overshoot the > end of my data. Is there a way to identify a row as the last row of data so > that whe...