In a database, the tool for representing many-to-many relationships is an association table. Each row in the table represents an association between two objects. Thus if a note with an ID of 1 appears in lists with IDs of 1, 2, and 3, there would be three rows in the association table:
ID NoteID ListID
-- ------ ------
1 1 1
2 1 2
3 1 3
You can get a note and all of its related lists with a query like this:
SELECT [columns] FROM Association
JOIN Notes ON Note.ID = Association.NoteID
JOIN Lists ON List.ID = Association.ListID
WHERE Association.NoteID = @NoteID
And all the notes for a list:
SELECT [columns] FROM Association
JOIN Notes ON Note.ID = Association.NoteID
JOIN Lists ON List.ID = Association.ListID
WHERE Association.ListID = @ListID
That's how you'd represent it in XML:
<Lists>
<List ID='1'>...</List>
<List ID='2'>...</List>
<List ID='3'>...</List>
...
<Lists>
<Notes>
<Note ID='1'>...</Note>
</Notes>
<Associations>
<Association ID='1' NoteID='1' ListID='1'/>
<Association ID='2' NoteID='1' ListID='2'/>
<Association ID='3' NoteID='1' ListID='3'/>
</Associations>
In, XSLT, you could access this association like this:
<xsl:template match="List" mode="AssociatedNotes">
<xsl:variable name="Associations" select="/*/Associations/Association[@ListID=current()/@ID]"/>
<xsl:apply-templates select="/*/Notes[@ID=$Associations/@NoteID]"/>
</xsl:template>
<xsl:template match="Note" mode="AssociatedLists">
<xsl:variable name="Associations" select="/*/Associations/Association[@NoteID=current()/@ID]"/>
<xsl:apply-templates select="/*/Lists[@ID=$Associations/@ListID]"/>
</xsl:template>
(Note the use of the mode
attribute to keep these templates from calling each other until you get a stack overflow.)