這是全部描述,我停留在第 5 點。我嘗試使用 for-each,生成 id 并應用模板似乎對我不起作用,不確定我錯過了什么。我只需要完成第 5 點需要填充專案號、描述和數量,我很困惑如何做到這一點,因為它是一種嵌套的 xml。任何人都可以幫忙解決這個問題,我是網路技術的新手,正在嘗試學習。下面附上我的代碼。
轉到文本編輯器中的 camping.xsl 檔案并開始設計 XSLT 樣式表。John 希望報告包括以下功能:
- 商店名稱作為主要標題。
- 提供每個客戶的姓名、地址和 ID 的客戶 ID 表,客戶按客戶名稱的字母順序列出。
- 每個客戶 ID 表后面的訂單表以及該客戶的訂單資訊;訂單表按訂單 ID 按降序列出。
- 每個訂單表都應包含訂單日期和訂單 ID。
- 每個訂單表應列出購買的物品,首先列出購買數量最多的物品。如果兩個產品的訂購數量相同,則產品應按專案 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>
uj5u.com熱心網友回復:
使最后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,您想要六列,您想要三列,名稱為 eg
<tr>
<th>Item No.</th>
<th>Description</th>
<th>Qty</th>
</tr>
轉載請註明出處,本文鏈接:https://www.uj5u.com/ruanti/369176.html
