Description
For this assignment we are going to use xpath to extract and summarize data. The file that we are going to summarize is doctorwho.xml
I am going to lead you through the process. The code for the xpath is listed below, but we will go through it setp by step. I have used the full location paths and axis rather than the abbreviated to give a better sense of what the xpath is doing.
To Do
- Download the doctor who file.
- Start a new XSLT file
<?xml version="1.0"?> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
- Start a template with the basic html document
<xsl:template match="/"> <html> <head> <title>Xpath Assignment</title> </head> <body> <h1>Doctor Who</h1>
- Now we will use the xpath function "count" to get the total number of doctors
<p> There have been<xsl:value-of select="count(descendant-or-self::doctor)" /> doctors</p>
- Now we will get the total number of episodes
<p>The total number of Doctor who episodes (including the new series) is <xsl:value-of select="sum(descendant-or-self::doctor/child::episodes) "/> </p>
- Next we get the name of a specific doctor and some years based on attribute values
<p>The most popular doctor was <xsl:value-of select="descendant-or-self::doctor[attribute::ID= 'four']/child::name" /> <p>Doctor Who began in <xsl:value-of select="descendant-or-self::doctor[attribute::ID='one']/begin" /> and ended in <xsl:value-of select="descendant-or-self::doctor[attribute::ID='seven']/child::end" />.
- Now we will actually do some math
<p>The original show ran for a total of <xsl:value-of select="(descendant-or-self::doctor[attribute::ID='seven']/child::end)-(descendant-or-self::doctor[attribute::ID='one']/child::begin)" /> years.</p> <p>There was an eigth doctor,
- An then the final summary
<xsl:value-of select="descendant-or-self::doctor[attribute::ID='eight']/child::name" />, who starred in a television movie. </p> <p>In 2005 the series was resurrected. The ninth doctor was <xsl:value-of select="descendant-or-self::doctor[attribute::ID='nine']/child::name" /> He worked for one year and then <xsl:value-of select="descendant-or-self::doctor[attribute::ID='ten']/child::name" /> became the new doctor. He is currently continuing in the role. </p>
To turn in
Print or email me the code for the xslt/xpath file