many-to-many XML structure

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • oNLINE bUDDY

    #1

    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!




  • Dimitre Novatchev

    #2
    Re: many-to-many XML structure

    The answer is to use a grouping method -- e.g. the Muenchian method.

    For a good description see:



    or

    http://www.topxml.com/code/default.a...20010129150851


    Cheers,


    Dimitre Novatchev.


    "oNLINE bUDDY" <oNLINEbUDDY121 21212@HOTMAIL.C OM> wrote in message
    news:2scRc.2358 1$Gl6.1872989@w eber.videotron. net...[color=blue]
    > 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!
    >
    >
    >
    >[/color]


    Comment

    • Dieu tout puissant

      #3
      Re: many-to-many XML structure

      nope that wont work for what i want to do

      "Dimitre Novatchev" <x@yyy.com> wrote in message
      news:#0#VEGOfEH A.3200@TK2MSFTN GP09.phx.gbl...[color=blue]
      > The answer is to use a grouping method -- e.g. the Muenchian method.
      >
      > For a good description see:
      >
      > http://www.jenitennison.com/xslt/grouping/
      >
      > or
      >
      > http://www.topxml.com/code/default.a...20010129150851
      >
      >
      > Cheers,
      >
      >
      > Dimitre Novatchev.
      >
      >
      > "oNLINE bUDDY" <oNLINEbUDDY121 21212@HOTMAIL.C OM> wrote in message
      > news:2scRc.2358 1$Gl6.1872989@w eber.videotron. net...[color=green]
      > > 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!
      > >
      > >
      > >
      > >[/color]
      >
      >[/color]


      Comment

      • oNline bUDDY

        #4
        Re: many-to-many XML structure

        nope that wont work for what i want to do

        "Dimitre Novatchev" <x@yyy.com> wrote in message
        news:#0#VEGOfEH A.3200@TK2MSFTN GP09.phx.gbl...[color=blue]
        > The answer is to use a grouping method -- e.g. the Muenchian method.
        >
        > For a good description see:
        >
        > http://www.jenitennison.com/xslt/grouping/
        >
        > or
        >
        > http://www.topxml.com/code/default.a...20010129150851
        >
        >
        > Cheers,
        >
        >
        > Dimitre Novatchev.
        >
        >
        > "oNLINE bUDDY" <oNLINEbUDDY121 21212@HOTMAIL.C OM> wrote in message
        > news:2scRc.2358 1$Gl6.1872989@w eber.videotron. net...[color=green]
        > > 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!
        > >
        > >
        > >
        > >[/color]
        >
        >[/color]


        Comment

        • Dimitre Novatchev

          #5
          Re: many-to-many XML structure

          That solves exactly the problem you described -- in case you had something
          else in mind you have yet to tell us about it.

          Cheers,

          Dimitre Novatchev.

          "oNline bUDDY" <sddsdds@hotmai l.com> wrote in message
          news:QvgRc.2399 7$Gl6.1978213@w eber.videotron. net...[color=blue]
          > nope that wont work for what i want to do
          >
          > "Dimitre Novatchev" <x@yyy.com> wrote in message
          > news:#0#VEGOfEH A.3200@TK2MSFTN GP09.phx.gbl...[color=green]
          >> The answer is to use a grouping method -- e.g. the Muenchian method.
          >>
          >> For a good description see:
          >>
          >> http://www.jenitennison.com/xslt/grouping/
          >>
          >> or
          >>
          >> http://www.topxml.com/code/default.a...20010129150851
          >>
          >>
          >> Cheers,
          >>
          >>
          >> Dimitre Novatchev.
          >>
          >>
          >> "oNLINE bUDDY" <oNLINEbUDDY121 21212@HOTMAIL.C OM> wrote in message
          >> news:2scRc.2358 1$Gl6.1872989@w eber.videotron. net...[color=darkred]
          >> > 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!
          >> >
          >> >
          >> >
          >> >[/color]
          >>
          >>[/color]
          >
          >[/color]


          Comment

          • oNLINE bUDDY

            #6
            Re: many-to-many XML structure

            ok got a (what looks like) good answer from someone


            oNLINE bUDDY wrote:
            [color=blue]
            > 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>[/color]

            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<boo klist>
            <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:styleshe et
            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::Auth or)]">
            <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>


            "Dimitre Novatchev" <x@yyy.com> wrote in message
            news:O#3NB7RfEH A.2028@tk2msftn gp13.phx.gbl...[color=blue]
            > That solves exactly the problem you described -- in case you had something
            > else in mind you have yet to tell us about it.
            >
            > Cheers,
            >
            > Dimitre Novatchev.
            >
            > "oNline bUDDY" <sddsdds@hotmai l.com> wrote in message
            > news:QvgRc.2399 7$Gl6.1978213@w eber.videotron. net...[color=green]
            > > nope that wont work for what i want to do
            > >
            > > "Dimitre Novatchev" <x@yyy.com> wrote in message
            > > news:#0#VEGOfEH A.3200@TK2MSFTN GP09.phx.gbl...[color=darkred]
            > >> The answer is to use a grouping method -- e.g. the Muenchian method.
            > >>
            > >> For a good description see:
            > >>
            > >> http://www.jenitennison.com/xslt/grouping/
            > >>
            > >> or
            > >>
            > >> http://www.topxml.com/code/default.a...20010129150851
            > >>
            > >>
            > >> Cheers,
            > >>
            > >>
            > >> Dimitre Novatchev.
            > >>
            > >>
            > >> "oNLINE bUDDY" <oNLINEbUDDY121 21212@HOTMAIL.C OM> wrote in message
            > >> news:2scRc.2358 1$Gl6.1872989@w eber.videotron. net...
            > >> > 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!
            > >> >
            > >> >
            > >> >
            > >> >
            > >>
            > >>[/color]
            > >
            > >[/color]
            >
            >[/color]


            Comment

            Working...