fabz1988
06-26-2006, 12:16 AM
I am very new to XML and XSL, but I am currently trying to create a database of my movie collection using it. First I created an XML document with all my movies in a format similar to the following:
<catalog>
<movie>
<title>12 Monkeys</title>
<actor> firstname>Bruce </firstname><lastname>Willis</lastname></actor>
<actor> firstname>Madeleine </firstname><lastname>Stowe</lastname></actor>
<actor><firstname>Brad </firstname><lastname>Pitt</lastname></actor>
<year>1995</year>
</movie>
<movie>
<title>Bandits</title>
<actor><firstname>Bruce </firstname><lastname>Willis</lastname></actor>
<actor><firstname>Billy Bob </firstname><lastname>Thorton</lastname></actor>
<actor><firstname>Cate </firstname><lastname>Blanchett</lastname></actor>
<year>2001</year>
</movie>
<movie>
<title>Sixth Sense, The</title>
<actor><firstname>Bruce
</firstname><lastname>Willis</lastname></actor>
<actor><firstname>Haley Joel </firstname><lastname>Osment</lastname></actor>
<actor><firstname>Toni </firstname><lastname>Collette</lastname></actor>
<year>1999</year>
</movie>
</catalog>
The next step I would like to do is to create an XSL document that will allow me to list every actor with all the movies they have played in that are in my collection. For example, if the previous except was my collection, then under Bruce Willis, the three movies 12 Monkeys, Bandits, and The Sixth Sense would be listed.
The only way I have come up with so far is this:
Bruce Willis<br/><table>
<xsl:for-each select="catalog//actor[lastname='Willis']">
<tr><td> <xsl:value-of select="parent::node()/title"/></td>
<td> <xsl:value-of select="parent::node()/year "/></td>
</tr>
</xsl:for-each></table>
I would like to find a way to do this that would produce the same result, in which I would not have to copy the above section and change the actor's name and the for-each test to a new lastname every time. Rather, a template that would automatically do the above to every author in my database.
If you have any ideas or advice, please let me know.
<catalog>
<movie>
<title>12 Monkeys</title>
<actor> firstname>Bruce </firstname><lastname>Willis</lastname></actor>
<actor> firstname>Madeleine </firstname><lastname>Stowe</lastname></actor>
<actor><firstname>Brad </firstname><lastname>Pitt</lastname></actor>
<year>1995</year>
</movie>
<movie>
<title>Bandits</title>
<actor><firstname>Bruce </firstname><lastname>Willis</lastname></actor>
<actor><firstname>Billy Bob </firstname><lastname>Thorton</lastname></actor>
<actor><firstname>Cate </firstname><lastname>Blanchett</lastname></actor>
<year>2001</year>
</movie>
<movie>
<title>Sixth Sense, The</title>
<actor><firstname>Bruce
</firstname><lastname>Willis</lastname></actor>
<actor><firstname>Haley Joel </firstname><lastname>Osment</lastname></actor>
<actor><firstname>Toni </firstname><lastname>Collette</lastname></actor>
<year>1999</year>
</movie>
</catalog>
The next step I would like to do is to create an XSL document that will allow me to list every actor with all the movies they have played in that are in my collection. For example, if the previous except was my collection, then under Bruce Willis, the three movies 12 Monkeys, Bandits, and The Sixth Sense would be listed.
The only way I have come up with so far is this:
Bruce Willis<br/><table>
<xsl:for-each select="catalog//actor[lastname='Willis']">
<tr><td> <xsl:value-of select="parent::node()/title"/></td>
<td> <xsl:value-of select="parent::node()/year "/></td>
</tr>
</xsl:for-each></table>
I would like to find a way to do this that would produce the same result, in which I would not have to copy the above section and change the actor's name and the for-each test to a new lastname every time. Rather, a template that would automatically do the above to every author in my database.
If you have any ideas or advice, please let me know.