XML assignment to create a page that displays times that various zoo animals are
ID: 3833208 • Letter: X
Question
XML assignment to create a page that displays times that various zoo animals are fed. I need help fixing my xsl stylesheet code, information is at the bottom of what I need to be done. All of my current code is provided.
The Downtown Zoo has hired you to help work on their web site. They would like to create a page that displays the times that various animals are being fed. The Zoo has the information stored in an XML document, Zoo.xml. The web page should list the feeding times across the top as hyperlinks to the details of which animals are fed at that time. The page should look like this:
11:00 14:00 15:00 16:00 9:00
11:00 Feeding Time For:
Lion Tortise
14:00 Feeding Time For:
Penguin Hippo
15:00 Feeding Time For:
Flamingo
16:00 Feeding Time For:
Ape
9:00 Feeding Time For:
Elephant
Rattle Snake
Zoo.xml
<?xml version='1.0'?>
<?xml-stylesheet href="Zoo.xsl" type="text/xsl"?>
<!-- XML -->
<zoo>
<animal name="Lion">
<feeding-time>11:00</feeding-time>
</animal>
<animal name="Penguin">
<feeding-time>14:00</feeding-time>
</animal>
<animal name="Elephant">
<feeding-time>9:00</feeding-time>
</animal>
<animal name="Tortise">
<feeding-time>11:00</feeding-time>
</animal>
<animal name="Ape">
<feeding-time>16:00</feeding-time>
</animal>
<animal name="Hippo">
<feeding-time>14:00</feeding-time>
</animal>
<animal name="Rattle Snake">
<feeding-time>9:00</feeding-time>
</animal>
<animal name="Flamingo">
<feeding-time>15:00</feeding-time>
</animal>
</zoo>
To complete this task you should do the following steps:
1. Create a new XSLT style sheet document Zoo.xsl with the basic structure of a stylesheet.
2. Create a stylesheet that displays the feeding times as links across the top of the page, and a list of the animals that are fed at each time within the page.
So far I have this:
<?xml version="1.0" encoding="UTF-8"?>
< xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:fo="http://www.w3.org/1999/XSL/Format">
<xsl:template match="/">
< html>
< body>
<table>
<tbody>
<tr>
<xsl:for-each select="zoo/animal">
<th>
<a href="#"><xsl:value-of select="feeding-time" /></a>
</th>
</xsl:for-each>
< /tr>
</tbody>
</table>
<xsl:for-each select="zoo/animal">
<br />
<table>
<tbody>
<tr>
<td>
<h4><xsl:value-of select="feeding-time"></xsl:value-of> Feeding Time For:</h4>
<span>
<xsl:value-of select="@name"></xsl:value-of>
</span>
< /td>
</tr>
</tbody>
<br />
< /table>
</xsl:for-each>
< /body>
< /html>
< /xsl:template>
</xsl:stylesheet>
The only problem is that it is not grouping the animals based on the specific times. I am getting an output that reads throught the xml file and prints out each time based on each animal, which means that I have repreated times. The figure in the directions above is what the output should look like. I have tried using group-by and muenchian grouping but can not figure out how to apply it to my current code. Can you please edit my code so that the animals are grouped for those particular times, and so that there are no repeated times at the top either?
Explanation / Answer
Zoo.xml
?<?xml version='1.0'?>?
<?xml-stylesheet href="Zoo.xsl" type="text/xsl"?>
<!-- XML -->?
<zoo>?
<animal name="Lion">
<feeding-time>11:00</feeding-time>
</animal>
<animal name="Penguin">
<feeding-time>14:00</feeding-time>
</animal>?
<animal name="Elephant">
<feeding-time>9:00</feeding-time>
</animal>
<animal name="Tortise">
<feeding-time>11:00</feeding-time>
</animal>?
<animal name="Ape">
<feeding-time>16:00</feeding-time>
</animal>
<animal name="Hippo">
<feeding-time>14:00</feeding-time>
</animal>?
<animal name="Rattle Snake">
<feeding-time>9:00</feeding-time>
</animal>
<animal name="Flamingo">
<feeding-time>15:00</feeding-time>
</animal>
</zoo>
<?xml version="1.0" encoding="UTF-8"?>
< xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:fo="http://www.w3.org/1999/XSL/Format">
<xsl:template match="/">
< html>
< body>
<table>
<tbody>
<tr>
<xsl:for-each select="zoo/animal">
<th>
<a href="#"><xsl:value-of select="feeding-time" /></a>
</th>
</xsl:for-each>
< /tr>
</tbody>
</table>
<xsl:for-each select="zoo/animal">
<br />
<table>
<tbody>
<tr>
<td>
<h4><xsl:value-of select="feeding-time"></xsl:value-of> Feeding Time For:</h4>
<span>
<xsl:value-of select="@name"></xsl:value-of>
</span>
< /td>
</tr>
</tbody>
<br />
< /table>
</xsl:for-each>
< /body>
< /html>
< /xsl:template>
</xsl:stylesheet>
?
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.