• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

XSLT merging help

 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello, i'm fairly new to xsl stylesheets but have always wanted to know how to merge two xml documents and transform them to output a xml document referencing certain elements.
I've written up two simple xml documents to help you guys understand what i am after.

authors.xml:

books.xml:

And the output that i'd like:


So basically the books.xml 'author' element is a foreign key that references the authors.xml author entries. (i'm assuming using muenchian?)
- For each author, "name", "born", "nationality" and "about_me" along with all their "books".
- The books are grouped by "genre" and then sorted on "published_date".
- For each book, the "title", "description, "price" will be stored also.

Thanks


 
Marshal
Posts: 28235
95
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The document() function allows you to reference a second XML document from XSLT.
 
Ranch Hand
Posts: 734
7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
[0] I can show you how to do that, but before doing that, I do not target the output document in exactly the same as what you propose, in particular, I will not put the genre into the attribute to books (as the same author can write different genre of books). Instead I would show the demo with genre put in the book instead.

[0.1] There are quite a few typo and/or consistency in tagging in the sample. I only take the spirit of it and use a consistently named sample (like date vs published_date).

[0.2] Apart from that, the techniques being used to achieve the result are sufficiently varying so that any change of mind can easily be done by yourself with the techniques as demonstrated.

[1] Here is the xsl document. It is supposed to operate on authors.xml and that the books.xml is in the same directory as authors.xml.

[1.1] I suppose there always exist genre and published_date. In case one or both might be absent, it is easy to add a node test with xsl:if to filter the cases.
 
reply
    Bookmark Topic Watch Topic
  • New Topic