• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

XSLT merging help

 
vez yao
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • 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


 
Paul Clapham
Sheriff
Posts: 21416
33
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The document() function allows you to reference a second XML document from XSLT.
 
g tsuji
Ranch Hand
Posts: 672
3
  • Mark post as helpful
  • send pies
  • 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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic