Dear Jay,
And what I'm wondering is that, in a situation where there's one of something (a musician), and a bunch of something else they're associated with (song writting or performance credits), which node should get the reference?
I would go with the first approach (listing the track names along with the album). If you plan to build a potentially larger database, I would advise to use ids instead of plain names. This will ensure that people with the same name won’t get mixed up, and updates will be much faster.
Your data could look as follows:
albums.xml: <albums> <album id='album0' by="artist0"> <name>We Might Rock You</name> <track name="Hot Cross Buns" written-by="artist1" /> <track name="Bicycle" written-by="artist1" /> </album> </albums>
artists.xml: <artists> <artist id='artist0'> <name>The Quesadillas</name> </artist> <artist id='artist1'> <name>Joe Schmoe</name> </artist> </album>
If all documents are stored in a database 'music', the following query will give you the names of all albums by a specific band:
let $artist := 'The Quesadillas' let $artist-id := db:open('music')/artists/artist[name = $artist]/@id let $albums := db:open('music')/albums/album[@by = $artist-id] return $albums/name/string()
• I have removed the track number from your original examples because it can be derived from the order of the track elements. • I have moved names to elements. This was just by preference: Your documents may be better readable if attributes are only used for ids and short values. • If you use ids, and if you have updates, you will need to take care that each id is only assigned once. If you use util:uuid() instead, you’ll be (as good as) safe.
All the best to Alaska, Christian