cvc-elt.1 in Tutorial 5, New Perspectives

Multi tool use
Multi tool use


cvc-elt.1 in Tutorial 5, New Perspectives



For my XML online class, I was assigned this Tutorial to completes.



Jenna has been working on creating a DVD library where she can list all of the DVDs that she has. Some she bought herself, others were gifts from her mom, dad, sister, grandpa, and grandma. The root element for her library is dvdlibrary with one or more dvd elements. Each dvd has a title, description, year, company, favorite characters, favorite bonus features, and purchase information. Her characters elements each have one or more character elements. Her bonus elements each have one or more features. Her purchased elements each have price, location, and date. The dvd element has two attributes, bonus element has one attribute, and the purchased element has no attributes.
Jenna wishes to create an XSLT style sheet to use to display the DVD collection information attractively. She has already created a CSS style sheet for the page.



Complete the following:



Go to the dvdlibrary.xsl file in your text editor and go down to the root template. Add the following commands to the template:


<html>
<head>
<title>Jenna's DVD Collection</title>
<link href="dvdlibrarystyles.css"
rel="stylesheet" type="text/css" />
</head>
<body>
<header>
<h1>Jenna's DVD Collection</h1>
</header>
</body>
</html>



Within the root template directly above the </body> tag, insert the following:


</body>


<section>
<h1>DVD List</h1>
dvd template
</section>



where dvd template applies the template for the dvdlibrary/dvd path, sorted by the title element.



Create a template for the dvd element to display information on each movie. Add the following HTML code to the template:


<article>
</article>



Within the <article></article> tags, insert the following to display the title and list of characters for each DVD:


<article></article>


<h1>title</h1>
<h2>Featuring: [character] [character] …</h2>



where title is the value of the title element and [character] [character] … is the list of characters in the movie. (Hint: Use the for-each instruction to go through each character element in the characters/character path.)



Below the h2 heading, insert the following:


<p>
Bonus Features:
<span>
feature/feature/ …
</span>
</p>



where feature/feature/ … is a list of the feature values within the bonus/feature path separated with the “/” symbol. (Hint: Use the for-each instruction with the bonus/feature path and display the value of the context node within the for-each element.)



Below the closing </p> tag, insert the following table:


</p>


<table>
<tr>
<th>Price</th>
<th>Location</th>
<th>Date</th>
</tr>
<tr>
<td>price</td>
<td>location</td>
<td>date</td>
</tr>
</table>



where price, location, and date are the values of the price, location, and date elements.



Save your changes to the file.



Generate a result document using either an XML editor or your Web browser. Verify that the layout and content of each item matches that shown in the figure below:



Submit the completed files to your instructor.



And I still seem to be having a issue with the code, and I tried adding an XSD sheet where I declared all the elements, but it didn't work.



This is what I have so far:



This is my XML:


<?xml version="1.0" encoding="UTF-8"?>

<!--
This document contains data about Jenna's DVD library.

Author: Julia Turek
Date: 6/25/2018

Filename: dvdlibrary.xml
Supporting File: dvdlibrary.xsl
-->

<?xml-stylesheet type="text/xsl" href="dvdlibrary.xsl" ?>

<dvdlibrary>
<dvd isbn="1-4157-4399-0" from="mom" >
<title>Kung Fu Lizard</title>
<description>Jo defends his training academy against the evil Mighty Moose, Benny.</description>
<year>2011</year>
<company>Cloud Nine Productions</company>
<characters>
<character>Jo, the Kung Fu Lizard</character>
<character>Lisa, the Fighting Kricket</character>
<character>Benny, the Evil Mangler Moose</character>
</characters>
<bonus num="2">
<feature>Kung Fu Academy</feature>
<feature>Cast Commentary</feature>
</bonus>
<purchased>
<price>19.94</price>
<location>Best DVDs in Town</location>
<date>2012-10-03</date>
</purchased>
</dvd>

<dvd isbn="1-5158-4399-0" from="mom">
<title>Planet of the Ogres</title>
<description>Bilbo had always dreamt he was from another planet. Now he finds out that he is. Join him as he meets his destiny to save his homeworld.</description>
<year>2012</year>
<company>MGM</company>
<characters>
<character>Bilbo, future leader of the Ogres</character>
<character>Kilnary, leader of the invading Tigres</character>
<character>Wicket, leader of the Morkian army</character>
</characters>
<bonus num="3">
<feature>Making Of Featurette</feature>
<feature>Theatre Trailers</feature>
<feature>PC downloadable version</feature>
</bonus>
<purchased>
<price>17.99</price>
<location>Mallmart</location>
<date>2013-10-06</date>
</purchased>
</dvd>

<dvd isbn="1-9955-8745-0" from="mom">
<title>Mountain King</title>
<description>Freda is the daughter of the Mountain King. As the only heir, will she break with tradition and be the first Mountain Queen?</description>
<year>2014</year>
<company>Sunny Entertainment</company>
<characters>
<character>Freda, daughter of the Mountain King</character>
<character>Toru, the Mountain King</character>
<character>Ella, the Enchanted Advisor</character>
<character>Bopo, the Monkey Bone Wizard</character>
</characters>
<bonus num="2">
<feature>Cast Commentary</feature>
<feature>Mountain King Music Video</feature>
</bonus>
<purchased>
<price>14.99</price>
<location>Movies For Everyone</location>
<date>2015-11-07</date>
</purchased>
</dvd>
</dvdlibrary>



This is my XSL


<?xml version="1.0" encoding="UTF-8" ?>

<!--
Project 5
Tutorial Project

DVD Library XSLT Style Sheet
Author: Julia Turek
Date: 6/28/18

Filename: dvdlibrary.xsl
-->

<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

<xsl:output method="html"
doctype-system="about:legacy-compat"
encoding="UTF-8"
indent="yes" />

<xsl:template match="/">
<html>
<head>
<title>Jenna's DVD Collection</title>
<link href="dvdlibrarystyles.css" rel="stylesheet" type="text/css" />
</head>
<body>
<header>
<h1>Jenna's DVD Collection</h1>
</header>
<section>
<h1>DVD List</h1>
<xsl:apply-templates select="dvdlibrary/dvd">
<xsl:sort select="title" />
</xsl:apply-templates>

<xsl:apply-templates select="dvd">
<article>
<xsl:for-each select="dvd/title">
<h1>
<xsl:value-of select="title"/>
</h1>
</xsl:for-each>
<xsl:for-each select="chracters/character">
<h2>
<xsl:value-of select="character"/>
</h2>
</xsl:for-each>
<p>
Bonus Features:
<span>
<xsl:for-each select="bonus/featuress"/>
</span>
</p>


<table>
<tr>
<th>Price</th>
<th>Location</th>
<th>Date</th>
</tr>
<tr>
<td>price</td>
<td>location</td>
<td>date</td>
</tr>
</table>


</article>
</xsl:apply-templates>

</section>
</body>
</html>

</xsl:template>

</xsl:stylesheet>



This is my CSS:


* {
margin: 0px;
list-style: none;
}

header, section, article {
display: block;
}



/* Body styles */
body {
background-color: white;
font-family: Verdana, Geneva, sans-serif;
margin: 10px auto;
width: 920px;
}

header h1 {
color: white;
font-size: 2.8em;
font-weight: normal;
text-shadow: rgb(90, 127, 0) 0px 0px 25px;
}

header h2 {
font-size: 1.5em;
font-weight: normal;
color: rgb(90, 127, 0);
}

section {
margin-top: 25px;
}

section > h1 {
font-weight: normal;
font-size: 1.9em;
}

article {
border: 1px solid black;
margin: 10px 10px;
padding: 10px;
width: 400px;
float: left;
box-shadow: rgb(151, 151, 151) 8px 8px 15px;
}

article > h1, article > h2 {
background-color: rgb(190, 235, 110);
}

article > h1 {
font-size: 1em;
font-weight: normal;
padding: 10px 0px 0px 10px;
}

article > h2 {
font-size: 0.7em;
font-weight: normal;
padding: 0px 0px 10px 10px;
border-bottom: 1px solid black;
}

article > p {
font-size: 0.7em;
margin: 4px 0px 0px 0px;
}

article span {
color: rgb(151,151, 151);
}

table {
border-collapse: collapse;
margin: 10px 0px 5px 0px;
}

td, th {
border: 1px solid rgb(191, 191, 191);
font-weight: normal;
font-size: 0.7em;
padding: 3px;
text-align: center;
}

th {
background-color: rgb(231, 231, 231);
}



But I keep getting an error that says:
cvc-elt.1: Cannot find the declaration of element 'dvdlibrary'.





You should really simplify your question a bit. It's OK to ask for help if you are trying complete a tutorial, but we don't really need to see the whole tutorial. Ideally, we just need a Minimal, Complete, Verifiable Example. i.e Show the XML, the XSLT you have tried, the output you expect, and the output (or error) you get. The CSS isn't really relevant in this case. Thanks
– Tim C
Jun 30 at 21:12




1 Answer
1



When testing your XSLT at http://xsltfiddle.liberty-development.net/ (which is a good place to test XSLT), the error message given doesn't really match the one you have given.


Error 1 at line 25:51 : Invalid element <article> within xsl:apply-templates



The error concerns these lines..


<xsl:apply-templates select="dvd">
<article>



For indeed you can't embed content inside xsl:apply-templates. You probably need to do <xsl:template match="dvd"> here, although this need to be moved to be a direct child of xsl:stylesheet


xsl:apply-templates


<xsl:template match="dvd">


xsl:stylesheet



Also, there are a couple of issues with your use of xsl:for-each, although your current code wouldn't cause any error. But within an xsl:for-each any xpath expression you do will be relevant to the current element you have selected. So, instead of doing this...


xsl:for-each


xsl:for-each


<xsl:for-each select="chracters/character">
<h2>
<xsl:value-of select="character"/>
</h2>
</xsl:for-each>



You need to do this (also correcting the spelling as well...)


<xsl:for-each select="characters/character">
<h2>
<xsl:value-of select="."/>
</h2>
</xsl:for-each>



Anyway, try this XSLT for starters, which you can see in action at http://xsltfiddle.liberty-development.net/eiZQaFj


<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

<xsl:output method="html"
doctype-system="about:legacy-compat"
encoding="UTF-8"
indent="yes" />

<xsl:template match="/">
<html>
<head>
<title>Jenna's DVD Collection</title>
<link href="dvdlibrarystyles.css" rel="stylesheet" type="text/css" />
</head>
<body>
<header>
<h1>Jenna's DVD Collection</h1>
</header>
<section>
<h1>DVD List</h1>
<xsl:apply-templates select="dvdlibrary/dvd">
<xsl:sort select="title" />
</xsl:apply-templates>
</section>
</body>
</html>
</xsl:template>

<xsl:template match="dvd">
<article>
<h1>
<xsl:value-of select="title"/>
</h1>
<xsl:for-each select="characters/character">
<h2>
<xsl:value-of select="."/>
</h2>
</xsl:for-each>
<p>
Bonus Features:
<xsl:for-each select="bonus/feature">
<span>
<xsl:value-of select="." />
</span>
</xsl:for-each>
</p>
</article>
</xsl:template>
</xsl:stylesheet>






By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

1EKuVPp5rzxxDScNzHVsG2ztnoO,mfVC0QwqrHF
rJAlokafFyE5HaKd5qG4L6JOYzvkHr8XwAcATKHk7pvTN,H6trRvO,MI0JxYQe,Njq9Wfqi8Ch

Popular posts from this blog

PySpark - SparkContext: Error initializing SparkContext File does not exist

django NoReverseMatch Exception

List of Kim Possible characters