473,399 Members | 4,192 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,399 software developers and data experts.

merging two XML files

Hi,
I would like to merge two XML files. The first XML contains a list of books,
the second XML file contains a bestseller list of books. So some of the
books in the first file will appear in the second file.

I want to merge the two files, so that the ones, that also exist in the
second XML file are printed in bold. I am trying to compare the titles of
the books, but this doesn't seem to work.

Could anybody give me a hint how to solve this? I guess this XPath statement
ind the <xsl:when...> is not quite right...

Thanks,
Stefan

<?xml version="1.0" encoding="ISO-8859-1"?><xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

<xsl:variable name="doc1" select="/" />
<xsl:variable name="doc2" select="document('Buchbestand.xml')" />

<xsl:template match="/">
<xsl:for-each select="$doc2/BUCHBESTAND/BUCH">
<xsl:choose>
<xsl:when test="($doc1/BESTSELLER/EINTRAG/TITEL) =
($doc2/BUCHBESTAND/BUCH/TITEL)">
<b><xsl:value-of select="TITEL"/></b><br />
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="TITEL"/><br />
</xsl:otherwise>
</xsl:choose>
</xsl:for-each>
</xsl:template>

</xsl:stylesheet>

.................................................. ..................

second XML file:

<?xml-stylesheet type="text/xsl" href="Bestseller.xsl"?>
<BESTSELLER>
<EINTRAG>
<TITEL>...</TITEL>
<VERLAG>...</VERLAG>
<JAHR>...</JAHR>
</EINTRAG>
<EINTRAG>
....
</BESTSELLER>

.................................................. ..................

first XML file:

<BUCHBESTAND>
<BUCH Einband="..." Lagernd="...">
<TITEL>...</TITEL>
<AUTOR>...</AUTOR>
<SEITEN>...</SEITEN>
<PREIS>...</PREIS>
</BUCH>
....
</BUCHBESTAND>
Jul 20 '05 #1
5 4532
Hi,
I want to merge the two files, so that the ones, that also exist in the
second XML file are printed in bold. I am trying to compare the titles of
the books, but this doesn't seem to work.

Could anybody give me a hint how to solve this? I guess this XPath statement
ind the <xsl:when...> is not quite right...


It is indeed not correct. Change it to:
<xsl:when test="($doc1/BESTSELLER/EINTRAG/TITEL) = TITEL">
and it will probably work.

regards,
--
Joris Gillis (http://www.ticalc.org/cgi-bin/acct-v...i?userid=38041)
Spread the wiki (http://www.wikipedia.org)
Jul 20 '05 #2
> <xsl:when test="($doc1/BESTSELLER/EINTRAG/TITEL) = TITEL">
and it will probably work.


Thanks very much, that was it. However I ran into another problem when
merging those two files. When I'm iterating through the elements with a
for-each statement I always get the current element from the XML file in the
for-each statement. When I'm trying to access information that's from the
other XML file, it fails.

<xsl:for-each select="$doc1/BESTSELLER/EINTRAG">
<xsl:if test="($doc2/BUCHBESTAND/BUCH/TITEL) = TITEL">
<b><xsl:value-of select="TITEL"/></b><br />
<xsl:value-of
select="$doc2/BUCHBESTAND/BUCH/AUTOR[($doc2/BUCHBESTAND/BUCH/TITEL) =
TITEL]"/><br />
</xsl:if>
</xsl:for-each>

I'm trying to work around this problem with an XPath statement
("$doc2/BUCHBESTAND/BUCH/AUTOR[($doc2/BUCHBESTAND/BUCH/TITEL) = TITEL]"),
but so far there has been no success.

Does anyone have any ideas on that problem?

Thanks,
Stefan
Jul 20 '05 #3
> I'm trying to work around this problem with an XPath statement
"$doc2/BUCHBESTAND/BUCH/AUTOR[($doc2/BUCHBESTAND/BUCH/TITEL) = TITEL]"
but so far there has been no success.


This cannot work since the 'AUTOR' element has no 'TITLE' child to perform an equality test.

Try this one:
"$doc2/BUCHBESTAND/BUCH[($doc2/BUCHBESTAND/BUCH/TITEL) = TITEL]/AUTOR"
--
Joris Gillis (http://www.ticalc.org/cgi-bin/acct-v...i?userid=38041)
Spread the wiki (http://www.wikipedia.org)
Jul 20 '05 #4
> Try this one:
"$doc2/BUCHBESTAND/BUCH[($doc2/BUCHBESTAND/BUCH/TITEL) = TITEL]/AUTOR"

No, doesn't work either, but it certainly brought me nearer to the solution,
that I found just a few minutes ago - one has to define a variable that
holds the current TITEL):

<xsl:for-each select="$doc1/BESTSELLER/EINTRAG">

<xsl:variable name="titel" select="TITEL" />

<xsl:if test="($doc2/BUCHBESTAND/BUCH/TITEL) = TITEL">
<b><xsl:value-of select="TITEL"/></b><br />
<xsl:value-of select="$doc2/BUCHBESTAND/BUCH[TITEL =
$titel]/AUTOR"/><br />
</xsl:if>
</xsl:for-each>

Thanks very much for your help,
Stefan
Jul 20 '05 #5
>> Try this one:
"$doc2/BUCHBESTAND/BUCH[($doc2/BUCHBESTAND/BUCH/TITEL) = TITEL]/AUTOR"
No, doesn't work either


Ok, I misread your previous question, try this:
"$doc2/BUCHBESTAND/BUCH[TITEL = current()/TITEL]/AUTOR"
it certainly brought me nearer to the solution,that I found just a few minutes ago - one has to define a variable thatholds the current TITEL):


That is indeed a working solution, but I (personally speaking) prefer to use 'current()' in my Xpath expressions rather than declaring dummy variables for reaching the same goal.

regards,
--
Joris Gillis (http://www.ticalc.org/cgi-bin/acct-v...i?userid=38041)
Spread the wiki (http://www.wikipedia.org)
Jul 20 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Cy Huckaba | last post by:
I have an XML document that is linked to other document and I can't figure out what the best way to try and merge them before query qith an XpathNavigator. Simple example...a root xml document...
3
by: Mike | last post by:
Hi! I also asked this question in C# group with no results: I have 2 datasets loaded with data from two xml files having the same schema. The files contain data from yesterday and today. I'd...
2
by: Nikhil Prashar | last post by:
I'm trying to merge two XML files that have the same structure but not necessarily the same nodes in the same order. I've tried opening the files as datasets and using the DataSet.Merge() function,...
0
by: steve | last post by:
Hi there, I am trying to import data from 2 dbf files into excel using the 'get external data' option which launches ms query. Ultimately I am merging data with a right join statement. I can...
0
by: Mike | last post by:
Hi! I have 2 datasets loaded with data from two xml files having the same schema. The files contain data from yesterday and today. I'd like to merge both datasets in such a way that the resulting...
10
by: n o s p a m p l e a s e | last post by:
Is it possible to merge two DLL files into one? If so, how? Thanx/NSP
1
by: adamrace | last post by:
Hi, I've got two excel files, one has a list of products and their current prices and they all have a product ID, I have another file with a list of price's that need updating. I was wondering...
0
by: veer | last post by:
Hello sir. I am making a program on merging in Visual Basic. The program is that I have a folder which is not on my hard drive contain 80 Mdb files and each Mdb file contains two tables. I want to...
0
by: Albert-jan Roskam | last post by:
Hi John, Thanks! Using a higher xlrd version did the trick! Regarding your other remarks: -yep, input files with multiple sheets don't work yet. I kinda repressed that ;-) Spss outputs only...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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
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:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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
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...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.