473,509 Members | 2,508 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

many-to-many XML structure

How can you reverse a many-to-many XML structure between 2 tags?

Lets say we have a books/author XML file.

A book can have many authors.

<book1>
<Author1>
</Author1>
</book1>
<book2>
<Author1>
</Author1>
<Author2>
</Author2>
</book1>

Many people are the authors of a book.
So if we reverse the first xml we get:

<Author1>
<book1>
</book1>
<book2>
</book2>
</Author1>
<Author2>
<book2>
</book2>
</Author2>

How can I do that?

txs for your answer!


Jul 20 '05 #1
3 1933


oNLINE bUDDY wrote:
How can you reverse a many-to-many XML structure between 2 tags?

Lets say we have a books/author XML file.

A book can have many authors.

<book1>
<Author1>
</Author1>
</book1>
<book2>
<Author1>
</Author1>
<Author2>
</Author2>
</book1>


Are you really using a unique tag name for every book and every author?
That is very bad XML design in my view, you should have one <book> and
<Author> elements and then use attributes and/or child elements to
indentify the books or the authors.
Thus an example could look like this:

<?xml version="1.0" encoding="UTF-8"?>
<booklist>
<book id="1">
<Author>Kay</Author>
</book>
<book id="2">
<Author>Kay</Author>
<Author>Gosling</Author>
</book>
</booklist>

Then you can transform that to

<?xml version="1.0" encoding="UTF-8"?>
<authorlist>
<Author>Kay<booklist>
<book id="1"/>
<book id="2"/>
</booklist>
</Author>
<Author>Gosling<booklist>
<book id="2"/>
</booklist>
</Author>
</authorlist>

with a stylesheet alike
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
version="1.0">

<xsl:output method="xml" encoding="UTF-8" indent="yes" />

<xsl:template match="/">
<authorlist>
<xsl:for-each select="//Author[not(. = following::Author)]">
<xsl:copy>
<xsl:value-of select="." />
<booklist>
<xsl:apply-templates select="//book[Author = current()]" />
</booklist>
</xsl:copy>
</xsl:for-each>
</authorlist>
</xsl:template>

<xsl:template match="book">
<xsl:copy>
<xsl:copy-of select="@*" />
</xsl:copy>
</xsl:template>

</xsl:stylesheet>
--

Martin Honnen
http://JavaScript.FAQTs.com/

Jul 20 '05 #2

oh txs very much! I can understand more the XSLT how it works.
but lets say you have more attributes to transfert. how do you also
transfert those?

Here I added titles for books and email adresses for the authors:

<?xml version="1.0" encoding="UTF-8"?>
<booklist>
<book id="1">
<Title="Star Wars"/> <-New
<Author>Kay</Author>
<email="ka*@hotmail.com"/> <-New
</book>
<book id="2">
<Title="Anaconda"/> <-New
<Author>Kay</Author>
<email="ka*@hotmail.com"/> <-New
<Author>Gosling</Author>
<email="go*****@hotmail.com"/> <-New
</book>
</booklist>

<?xml version="1.0" encoding="UTF-8"?>
<authorlist>
<Author>Kay<booklist>
<email="ka*@hotmail.com"/> <-New
<book id="1"/>
<Title="Star Wars"/> <-New
<book id="2"/>
<Title="Anaconda"/> <-New
</booklist>
</Author>
<Author>Gosling<booklist>
<email="go*****@hotmail.com"/> <-New
<book id="2"/>
<Title="Anaconda"/> <-New
</booklist>
</Author>
</authorlist>

<xsl:template match="/">
<authorlist>
<xsl:for-each select="//Author[not(. = following::Author)]">
<xsl:copy>
<xsl:value-of select="." />
<booklist>
<xsl:apply-templates select="//book[Author = current()]" />
<xsl:apply-templates select="//email[Author = current()]" />
<------- ????
</booklist>
</xsl:copy>
</xsl:for-each>
</authorlist>
</xsl:template>
"Martin Honnen" <ma*******@yahoo.de> wrote in message
news:41********@olaf.komtel.net...


oNLINE bUDDY wrote:
How can you reverse a many-to-many XML structure between 2 tags?

Lets say we have a books/author XML file.

A book can have many authors.

<book1>
<Author1>
</Author1>
</book1>
<book2>
<Author1>
</Author1>
<Author2>
</Author2>
</book1>


Are you really using a unique tag name for every book and every author?
That is very bad XML design in my view, you should have one <book> and
<Author> elements and then use attributes and/or child elements to
indentify the books or the authors.
Thus an example could look like this:

<?xml version="1.0" encoding="UTF-8"?>
<booklist>
<book id="1">
<Author>Kay</Author>
</book>
<book id="2">
<Author>Kay</Author>
<Author>Gosling</Author>
</book>
</booklist>

Then you can transform that to

<?xml version="1.0" encoding="UTF-8"?>
<authorlist>
<Author>Kay<booklist>
<book id="1"/>
<book id="2"/>
</booklist>
</Author>
<Author>Gosling<booklist>
<book id="2"/>
</booklist>
</Author>
</authorlist>

with a stylesheet alike
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
version="1.0">

<xsl:output method="xml" encoding="UTF-8" indent="yes" />

<xsl:template match="/">
<authorlist>
<xsl:for-each select="//Author[not(. = following::Author)]">
<xsl:copy>
<xsl:value-of select="." />
<booklist>
<xsl:apply-templates select="//book[Author = current()]" />
</booklist>
</xsl:copy>
</xsl:for-each>
</authorlist>
</xsl:template>

<xsl:template match="book">
<xsl:copy>
<xsl:copy-of select="@*" />
</xsl:copy>
</xsl:template>

</xsl:stylesheet>
--

Martin Honnen
http://JavaScript.FAQTs.com/

Jul 20 '05 #3
<xsl:copy-of select="@*" /> will do some!
"oNLINE bUDDY" <sd*****@hotmail.com> wrote in message
news:2o********************@weber.videotron.net...

oh txs very much! I can understand more the XSLT how it works.
but lets say you have more attributes to transfert. how do you also
transfert those?

Here I added titles for books and email adresses for the authors:

<?xml version="1.0" encoding="UTF-8"?>
<booklist>
<book id="1">
<Title="Star Wars"/> <-New
<Author>Kay</Author>
<email="ka*@hotmail.com"/> <-New
</book>
<book id="2">
<Title="Anaconda"/> <-New
<Author>Kay</Author>
<email="ka*@hotmail.com"/> <-New
<Author>Gosling</Author>
<email="go*****@hotmail.com"/> <-New
</book>
</booklist>

<?xml version="1.0" encoding="UTF-8"?>
<authorlist>
<Author>Kay<booklist>
<email="ka*@hotmail.com"/> <-New
<book id="1"/>
<Title="Star Wars"/> <-New
<book id="2"/>
<Title="Anaconda"/> <-New
</booklist>
</Author>
<Author>Gosling<booklist>
<email="go*****@hotmail.com"/> <-New
<book id="2"/>
<Title="Anaconda"/> <-New
</booklist>
</Author>
</authorlist>

<xsl:template match="/">
<authorlist>
<xsl:for-each select="//Author[not(. = following::Author)]">
<xsl:copy>
<xsl:value-of select="." />
<booklist>
<xsl:apply-templates select="//book[Author = current()]" />
<xsl:apply-templates select="//email[Author = current()]" />
<------- ????
</booklist>
</xsl:copy>
</xsl:for-each>
</authorlist>
</xsl:template>
"Martin Honnen" <ma*******@yahoo.de> wrote in message
news:41********@olaf.komtel.net...


oNLINE bUDDY wrote:
How can you reverse a many-to-many XML structure between 2 tags?

Lets say we have a books/author XML file.

A book can have many authors.

<book1>
<Author1>
</Author1>
</book1>
<book2>
<Author1>
</Author1>
<Author2>
</Author2>
</book1>


Are you really using a unique tag name for every book and every author?
That is very bad XML design in my view, you should have one <book> and
<Author> elements and then use attributes and/or child elements to
indentify the books or the authors.
Thus an example could look like this:

<?xml version="1.0" encoding="UTF-8"?>
<booklist>
<book id="1">
<Author>Kay</Author>
</book>
<book id="2">
<Author>Kay</Author>
<Author>Gosling</Author>
</book>
</booklist>

Then you can transform that to

<?xml version="1.0" encoding="UTF-8"?>
<authorlist>
<Author>Kay<booklist>
<book id="1"/>
<book id="2"/>
</booklist>
</Author>
<Author>Gosling<booklist>
<book id="2"/>
</booklist>
</Author>
</authorlist>

with a stylesheet alike
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
version="1.0">

<xsl:output method="xml" encoding="UTF-8" indent="yes" />

<xsl:template match="/">
<authorlist>
<xsl:for-each select="//Author[not(. = following::Author)]">
<xsl:copy>
<xsl:value-of select="." />
<booklist>
<xsl:apply-templates select="//book[Author = current()]" />
</booklist>
</xsl:copy>
</xsl:for-each>
</authorlist>
</xsl:template>

<xsl:template match="book">
<xsl:copy>
<xsl:copy-of select="@*" />
</xsl:copy>
</xsl:template>

</xsl:stylesheet>
--

Martin Honnen
http://JavaScript.FAQTs.com/


Jul 20 '05 #4

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

Similar topics

2
11930
by: vikas | last post by:
I have following structure in c++. typedef struct MMF_result_struct { int action; char text; int cols,rows; int month,day,year; } MMF_result; Now this structure is shared between C++ and C#...
26
7031
by: Brett | last post by:
I have created a structure with five fields. I then create an array of this type of structure and place the structure into an array element. Say index one. I want to assign a value to field3 of...
4
3877
by: marco_segurini | last post by:
Hi, From my VB program I call a C++ function that gets a structure pointer like parameter. The structure has a field that contains the structure length and other fields. My problem is that...
2
4825
by: Steve Turner | last post by:
I have read several interesting posts on passing structures to C dlls, but none seem to cover the following case. The structure (as seen in C) is as follows: typedef struct tag_scanparm { short...
8
3312
by: Charles Law | last post by:
Can anyone suggest how I would marshal a variable length structure back from an API call. Specifically, I am looking at the WaitForDebugEvent function, which returns a DEBUG_EVENT structure. ...
15
8184
by: Charles Law | last post by:
I have adapted the following code from the MSDN help for PropertyInfo SetValue. In the original code, the structure MyStructure is defined as a class MyProperty, and it works as expected. There is...
3
8880
by: Kiran B. | last post by:
Hi, I am new to .net. I have two Data Structure Type ... Sturcture A and Structure B. Structure A Public Fname as String Public LastName as String Public City as String Public Zip as String...
14
1765
by: Dennis | last post by:
If I have a structure like; Public Structure myStructureDef Public b() as Byte Public t as String End Structure If I pass this structure, will the values in the array b be stored on the...
10
4968
by: David Fort | last post by:
Hi, I'm upgrading a VB6 app to VB.net and I'm having a problem with a call to a function provided in a DLL. The function takes the address of a structure which it will fill in with values. I...
5
3773
by: =?Utf-8?B?QXlrdXQgRXJnaW4=?= | last post by:
Hi Willy, Thank you very much for your work. C++ code doesnot make any serialization. So at runtime C# code gives an serialization error at "msg_file_s sa = (msg_file_s) bf.Deserialize(ms);"...
0
7233
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7135
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...
1
7067
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
7505
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
4729
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3215
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
1570
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
774
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
440
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

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.