这是我的全部描述,我被困在第5点。我尝试了for -每一个,生成id和应用模板似乎对我没有工作,不知道我错过了哪里。我只需要完成第五点,需要填充项目编号、描述和数量--我对如何做到这一点感到困惑,因为它是嵌套的xml.Can,请任何人帮助我尝试学习web技术。在下面附加我的代码。
转到文本编辑器中的camping.xsl文件,开始设计XSLT样式表。John希望报告包含以下功能:
ID.
这是campingtxt.xml文件
<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="html" href="campingtxt.html"?>
<customers xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<?xml-stylesheet type="html" version="2.0" href="campingtxt.xsl"?>
<customer cid="c5781">
<name>Hardy, Joan</name>
<street>105 Terrace Rd.</street>
<city>Duncan</city>
<state>NE</state>
<zip>68634</zip>
<orders>
<order oid="51170">
<date>8/2/2017</date>
<item iid="p5148">
<description>Self-Inflating Pad</description>
<qty>2</qty>
</item>
<item iid="sb2818">
<description>Down Sleeping Bag</description>
<qty>2</qty>
</item>
<item iid="t7815">
<description>2 Person Tent</description>
<qty>1</qty>
</item>
</order>
<order oid="52811">
<date>8/11/2017</date>
<item iid="led7331">
<description>LED Rechargeable Lantern</description>
<qty>1</qty>
</item>
<item iid="wp0312">
<description>Water Purifier</description>
<qty>1</qty>
</item>
</order>
</orders>
</customer>
<customer cid="c5391">
<name>Evans, Terry</name>
<street>641 Greenway Blvd.</street>
<city>Mount Hope</city>
<state>OH</state>
<zip>44660</zip>
<orders>
<order oid="52517">
<date>8/1/2017</date>
<item iid="wb7133">
<description>Insulated Water Bottle</description>
<qty>2</qty>
</item>
<item iid="gps1015">
<description>Zendo GPS meter</description>
<qty>1</qty>
</item>
<item iid="bl2815">
<description>Boot Laces (Medium)</description>
<qty>1</qty>
</item>
<item iid="tr8140">
<description>Trail Mix (Pouch)</description>
<qty>5</qty>
</item>
<item iid="fa8442">
<description>First Aid Kit (Pack Size)</description>
<qty>1</qty>
</item>
<item iid="bb7117">
<description>Blister Patches</description>
<qty>3</qty>
</item>
</order>
<order oid="53003">
<date>8/5/2017</date>
<item iid="hp7814">
<description>Fiberglass Light Hiking Poles (Spring Adj.)</description>
<qty>1</qty>
</item>
</order>
<order oid="54814">
<date>8/6/2017</date>
<item iid="sb6601">
<description>Solar Battery Recharging Unit</description>
<qty>1</qty>
</item>
<item iid="br9002">
<description>Bug Repellent (Deep Woodes)</description>
<qty>2</qty>
</item>
<item iid="sb8502">
<description>Sunblock SPF 30 (Hiking Size)</description>
<qty>6</qty>
</item>
</order>
</orders>
</customer>
<customer cid="c5614">
<name>Sandoval, Tammy</name>
<street>641 Greenway Blvd.</street>
<city>Galesburg</city>
<state>ND</state>
<zip>58035</zip>
<orders>
<order oid="52144">
<date>8/3/2017</date>
<item iid="sg8128">
<description>Polarized Snow Goggles</description>
<qty>1</qty>
</item>
<item iid="sh5591">
<description>Snow Helmet Women's</description>
<qty>1</qty>
</item>
<item iid="sb5317">
<description>Attack Snowboard Women's</description>
<qty>1</qty>
</item>
<item iid="pw6558">
<description>Insulated Pants Women's</description>
<qty>2</qty>
</item>
<item iid="pj5199">
<description>Insulated Jacket Women's</description>
<qty>1</qty>
</item>
<item iid="bl6638">
<description>Snowboard Leash</description>
<qty>1</qty>
</item>
</order>
<order oid="53410">
<date>8/6/2017</date>
<item iid="ws6832">
<description>Snowshoes Women's</description>
<qty>1</qty>
</item>
<item iid="sp5588">
<description>Snowshoes Pair</description>
<qty>1</qty>
</item>
</order>
</orders>
</customer>
</customers>Css文件/*默认样式*/
* {
margin: 0px;
list-style: none;
}
header, section, article {
display: block;
}
/* Body styles */
body {
font-family: Verdana, Geneva, sans-serif;
background-color: white;
}
div#wrap {
background-color: white;
margin: 0px auto;
width: 780px;
border-left: 1px solid rgb(151, 151, 151);
border-right: 1px solid rgb(151, 151, 151);
box-shadow: rgb(191, 191, 191) 10px 0px 30px,
rgb(191, 191, 191) -10px 0px 30px;
}
header {
background-color: rgb(120, 157, 40);
padding: 5px;
}
header h1 {
font-size: 2.4em;
color: rgb(150, 187, 60);
text-shadow: black 1px 1px 1px,
white 0px -2px 0px;
margin-left: 20px;
}
section {
margin-top: 10px;
margin-left: 20px;
}
section h1 {
font-size: 1.8em;
color: rgb(51, 51, 51);
text-shadow: rgb(150, 187, 60) 1px 1px 4px;
margin: 0px 0px 30px 0px;
}
table.cdata {
border-collapse: collapse;
border: 1px solid rgb(151, 151, 151);
background-color: rgb(231, 231, 231);
font-size: 0.8em;
margin-top: 10px;
margin-bottom: 30px;
}
table.cdata th {
text-align: left;
background-color: rgb(191, 191, 191);
border: 1px solid rgb(101, 101, 101);
padding: 3px;
width: 100px;
font-weight: normal;
vertical-align: top;
}
table.cdata td {
text-align: left;
width: 250px;
border: 1px solid rgb(101, 101, 101);
padding: 3px;
vertical-align: top;
}
article {
border-bottom: 1px solid rgb(111, 151, 71);
padding-bottom: 15px;
}
span {
color: rgb(131, 131, 131);
}
table.items span.oid {
float: right;
}
table.items span.date {
float: left;
}
table.items tr {
clear: both;
}
table.items {
border-collapse: collapse;
border: 1px solid rgb(191,211, 171);
font-size: 0.8em;
margin-top: 8px;
}
table.items td, table.items th {
border: 1px solid rgb(151, 151, 151);
padding: 3px 7px;
}
table.items thead tr:last-of-type th {
font-weight: normal;
background-color: rgb(191, 191, 191);
}
table.items tbody tr:nth-child(even) {
background-color: rgb(231, 255, 211);
}
table.items tr td:nth-child(1) {
width: 100px;
}
table.items tr td:nth-child(2) {
width: 350px;
}
table.items tr td:nth-child(3) {
width: 50px;
text-align: right;
}这是我的campingtxt.xsl样式表,它必须转换成html页面。
<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>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>Customer Orders at Cairn Camping</title>
<link href="cstyles.css" rel="stylesheet" type="text/css" />
</head>
<body>
<div id="wrap">
<header>
<h1>Cairn Camping Store</h1>
</header>
<section>
<h1>Customer Orders</h1>
<article>
<xsl:for-each select="customers/customer">
<xsl:sort select="name" />
<table class="cdata">
<tr>
<th>Name</th>
<td>
<xsl:value-of select="name" />
</td>
</tr>
<tr>
<th>Address</th>
<td>
<xsl:value-of select="street"/>
<br>
<xsl:value-of select="city" />
,
<xsl:value-of select="state" />
</br>
<br>
<xsl:value-of select="zip" />
</br>
</td>
</tr>
<tr>
<th>Customer ID</th>
<td>
<xsl:value-of select="@cid" />
</td>
</tr>
</table>
<xsl:for-each select ="orders/order">
<xsl:sort select="@oid" order="descending" />
<table class="items">
<thead>
<tr>
<th colspan="3">
<span class="date">
<xsl:value-of select="date" />
</span>
<span class="oid">
<xsl:value-of select="@oid" />
</span></th>
</tr>
<tr>
<th>Item No.</th>
<td><xsl:value-of select="iid" /> </td>
<th>Description</th>
<td><xsl:value-of select="description" /> </td>
<th>Qty</th>
<td><xsl:value-of select="qty" /> </td>
</tr>
</thead>
<tbody>
<tr>
</tr>
</tbody>
</table>
</xsl:for-each>
</xsl:for-each>
</article>
</section>
</div>
</body>
</html>
</xsl:template>
</xsl:stylesheet>发布于 2021-11-28 09:44:59
使最后一个tbody (当前输出一个带有<tbody<tr></tr></tbody>的空行)输出items:
<tbody>
<xsl:for-each select="item">
<xsl:sort select="qty" data-type="number" order="descending"/>
<xsl:sort select="description"/>
<tr>
<td>
<xsl:value-of select="@iid"/>
</td>
<td>
<xsl:value-of select="description"/>
</td>
<td>
<xsl:value-of select="qty"/>
</td>
</tr>
</xsl:for-each>
</tbody>此外,我不认为在以前的thead中,您需要六列,您想要三列,名字是。
<tr>
<th>Item No.</th>
<th>Description</th>
<th>Qty</th>
</tr>https://stackoverflow.com/questions/70140926
复制相似问题