对于我的XML类,我被指派完成本教程。
珍娜一直致力于创建一个DVD库,在那里她可以列出她拥有的所有DVD。有些是她自己买的,另一些是她妈妈、爸爸、姐姐、爷爷和奶奶送的礼物。她的库的根元素是带有一个或多个dvd元素的dvdlibrary。每个dvd都有一个标题、描述、年份、公司、最喜欢的角色、最喜欢的奖励功能和购买信息。她的字符元素每个都有一个或多个字符元素。她的奖励元素每个都有一个或多个特征。她购买的元素各有价格、地点和日期。dvd元素有两个属性,红利元素有一个属性,而购买的元素没有属性。珍娜希望创建一个XSLT样式表,用于以吸引人的方式显示DVD集合信息。她已经为该页面创建了CSS样式表。
完成以下内容:
</body>标记上插入以下内容:<article></article>标记中,插入以下内容以显示每个DVD的标题和字符列表:</p>标记下面插入下表:我的代码似乎仍然有问题,我尝试添加一个XSD表,其中声明了所有的元素,但它没有工作。
到目前为止,这就是我所拥有的:
这是我的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>这是我的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>这是我的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);
}但是我一直收到一个错误: cvc-elt.1:找不到元素'dvdlibrary‘的声明。
发布于 2018-06-30 21:23:18
在http://xsltfiddle.liberty-development.net/上测试XSLT时(这是测试XSLT的好地方),给出的错误消息实际上与您提供的错误消息不匹配。
Error 1 at line 25:51 : Invalid element <article> within xsl:apply-templates错误与这些行有关..。
<xsl:apply-templates select="dvd">
<article> 因为实际上,您不能在xsl:apply-templates中嵌入内容。您可能需要在这里执行<xsl:template match="dvd">,尽管需要将其移动为xsl:stylesheet的直接子级。
此外,使用xsl:for-each也存在一些问题,尽管当前的代码不会导致任何错误。但是在xsl:for-each中,您所做的任何xpath表达式都将与您选择的当前元素相关。所以,与其这样做.
<xsl:for-each select="chracters/character">
<h2>
<xsl:value-of select="character"/>
</h2>
</xsl:for-each>你需要这样做(也要纠正拼写.)
<xsl:for-each select="characters/character">
<h2>
<xsl:value-of select="."/>
</h2>
</xsl:for-each>无论如何,您可以在http://xsltfiddle.liberty-development.net/eiZQaFj上看到启动器的XSLT。
<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>https://stackoverflow.com/questions/51118218
复制相似问题