XML/XSLT为课程项目帮助



我正在为我的介绍编程课做一个项目,我必须编写一个XML文档,该文档使用XSL文档在我的学校书店中显示书籍列表。

我已经完成了大部分内容,但是每当我尝试发布页面时,我都会在文档中遇到有关额外内容的错误。我不确定错误来自哪里。

这是我的XML文档:

<?xml version="1.0" encoding="UTF-8"?>
<bookstore>
  <book>
    <ISBN>32132132132</ISBN>
    <BookTitle>Peace Corps</BookTitle>
    <Author>Jack and Angene Wilson</Author>
    <InStock>50</InStock>
    <SellingPrice>15.00</SellingPrice>
    <CostPrice>12.00</CostPrice>
    <PublicationYear>2011</PublicationYear>
    <Publisher>City Publications</Publisher>
  </book>
<bookstore>
  <book>
    <ISBN>97942335221</ISBN>
    <BookTitle>Fundamentals of Database Systems</BookTitle>
    <Author>Ramez Elmasri</Author>
    <InStock>100</InStock>
    <SellingPrice>125.00</SellingPrice>
    <CostPrice>100.00</CostPrice>
    <PublicationYear>2011</PublicationYear>
    <Publisher>Addison-Wesley</Publisher>
  </book><bookstore>
  <book>
    <ISBN>64814414414</ISBN>
    <BookTitle>Legal Issues of Computer Security</BookTitle>
    <Author>Joanna Gramma</Author>
    <InStock>20</InStock>
    <SellingPrice>60.00</SellingPrice>
    <CostPrice>55.00</CostPrice>
    <PublicationYear>2012</PublicationYear>
    <Publisher>Jones and Bartlett</Publisher>
  </book><bookstore>
  <book>
    <ISBN>9780133862256</ISBN>
    <BookTitle>Starting Out with Python 3rd Ed</BookTitle>
    <Author>Tony Gaddis</Author>
    <InStock>80</InStock>
    <SellingPrice>194.75</SellingPrice>
    <CostPrice>160.00</CostPrice>
    <PublicationYear>2015</PublicationYear>
    <Publisher>Pearson</Publisher>
  </book><bookstore>
  <book>
    <ISBN>12345678901</ISBN>
    <BookTitle>Discrete Mathematics</BookTitle>
    <Author>Kenneth Rosen</Author>
    <InStock>200</InStock>
    <SellingPrice>212.69</SellingPrice>
    <CostPrice>175.00</CostPrice>
    <PublicationYear>2012</PublicationYear>
    <Publisher>McGraw-Hill</Publisher>
  </book><bookstore>
  <book>
    <ISBN>44444444444</ISBN>
    <BookTitle>Visual Basic: Step by Step</BookTitle>
    <Author>Malik</Author>
    <InStock>100</InStock>
    <SellingPrice>38.75</SellingPrice>
    <CostPrice>35.00</CostPrice>
    <PublicationYear>2007</PublicationYear>
    <Publisher>Course Technology</Publisher>
  </book><bookstore>
  <book>
    <ISBN>2900133775982</ISBN>
    <BookTitle>Programming the WWW 8th Ed</BookTitle>
    <Author>Robert W. Sebesta</Author>
    <InStock>60</InStock>
    <SellingPrice>34.80</SellingPrice>
    <CostPrice>150.00</CostPrice>
    <PublicationYear>2014</PublicationYear>
    <Publisher>Pearson</Publisher>
  </book><bookstore>
  <book>
    <ISBN>98013200025</ISBN>
    <BookTitle>Cryptography</BookTitle>
    <Author>Stinson</Author>
    <InStock>10</InStock>
    <SellingPrice>105.00</SellingPrice>
    <CostPrice>75.00</CostPrice>
    <PublicationYear>2008</PublicationYear>
    <Publisher>CRC</Publisher>
  </book><bookstore>
  <book>
    <ISBN>27224421166</ISBN>
    <BookTitle>C++ Programming Language</BookTitle>
    <Author>Stroustrup</Author>
    <InStock>300</InStock>
    <SellingPrice>62.50</SellingPrice>
    <CostPrice>50.00</CostPrice>
    <PublicationYear>2013</PublicationYear>
    <Publisher>Addison-Wesley</Publisher>
  </book><bookstore>
  <book>
    <ISBN>33421111222</ISBN>
    <BookTitle>Steve Jobs</BookTitle>
    <Author>Walter Isaacson</Author>
    <InStock>1000</InStock>
    <SellingPrice>47.45</SellingPrice>
    <CostPrice>40.25</CostPrice>
    <PublicationYear>2011</PublicationYear>
    <Publisher>Simpson and Schuster</Publisher>
  </book><bookstore>
  <book>
    <ISBN>43433333444</ISBN>
    <BookTitle>Software Engineering</BookTitle>
    <Author>Frank Tsui</Author>
    <InStock>70</InStock>
    <SellingPrice>53.53</SellingPrice>
    <CostPrice>43.43</CostPrice>
    <PublicationYear>2009</PublicationYear>
    <Publisher>Wiley</Publisher>
  </book><bookstore>
  <book>
    <ISBN>58729955411</ISBN>
    <BookTitle>Computer Security</BookTitle>
    <Author>Frank Conklin</Author>
    <InStock>30</InStock>
    <SellingPrice>82.75</SellingPrice>
    <CostPrice>80.00</CostPrice>
    <PublicationYear>2010</PublicationYear>
    <Publisher>Wiley</Publisher>
  </book><bookstore>
  <book>
    <ISBN>62588811432</ISBN>
    <BookTitle>Things Fall Apart</BookTitle>
    <Author>Chinua Achebe</Author>
    <InStock>5</InStock>
    <SellingPrice>12.00</SellingPrice>
    <CostPrice>10.00</CostPrice>
    <PublicationYear>1968</PublicationYear>
    <Publisher>Longman</Publisher>
  </book><bookstore>
  <book>
    <ISBN>9780134527338</ISBN>
    <BookTitle>Network Security Essentials</BookTitle>
    <Author>William Stallings</Author>
    <InStock>15</InStock>
    <SellingPrice>95.24</SellingPrice>
    <CostPrice>75.89</CostPrice>
    <PublicationYear>2016</PublicationYear>
    <Publisher>Pearson</Publisher>
  </book><bookstore>
  <book>
    <ISBN>77744555663</ISBN>
    <BookTitle>No Easy Task</BookTitle>
    <Author>Aubrey Kayira</Author>
    <InStock>2</InStock>
    <SellingPrice>7.00</SellingPrice>
    <CostPrice>5.00</CostPrice>
    <PublicationYear>1970</PublicationYear>
    <Publisher>Penguin</Publisher>
  </book><bookstore>
  <book>
    <ISBN>97812345678</ISBN>
    <BookTitle>Computer Networks</BookTitle>
    <Author>Peterson</Author>
    <InStock>8</InStock>
    <SellingPrice>112.00</SellingPrice>
    <CostPrice>100.00</CostPrice>
    <PublicationYear>2004</PublicationYear>
    <Publisher>Morgan Kaufman</Publisher>
  </book><bookstore>
  <book>
    <ISBN>87062662662</ISBN>
    <BookTitle>Differential Equations</BookTitle>
    <Author>Perko</Author>
    <InStock>12</InStock>
    <SellingPrice>95.00</SellingPrice>
    <CostPrice>90.00</CostPrice>
    <PublicationYear>2000</PublicationYear>
    <Publisher>Elsevier</Publisher>
  </book>
  <book>
    <ISBN>70626626621</ISBN>
    <BookTitle>Computers in Action 9th Ed</BookTitle>
    <Author>Parsley</Author>
    <InStock>500</InStock>
    <SellingPrice>130.00</SellingPrice>
    <CostPrice>90.00</CostPrice>
    <PublicationYear>2013</PublicationYear>
    <Publisher>Pearson</Publisher>
  </book>
</bookstore>

这是我的XSL文档:

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/">
<html> 
<body>
  <h2>Bookstore Inventory</h2>
  <table border="1">
    <tr bgcolor="#9acd32">
      <th style="text-align:left">BookTitle</th>
      <th style="text-align:left">Author</th>
      <th style="text-align:left">SellingPrice</th>
      <th style="text-align:left">PublicationYear</th>
      <th style="text-align:left">Publisher</th>
    </tr>
    <xsl:for-each select="bookstore/book">
    <tr>
      <td><xsl:value-of select="booktitle"/></td>
      <td><xsl:value-of select="author"/></td>
      <td><xsl:value-of select="sellingprice"/></td>
      <td><xsl:value-of select="publicationyear"/></td>
      <td><xsl:value-of select="publisher"/></td>
    </tr>
    </xsl:for-each>
  </table>
</body>
</html>
</xsl:template>
</xsl:stylesheet>

我知道这是很多,我感谢任何帮助。

谢谢!

xml是案例敏感的:

<xsl:value-of select="booktitle"/>

将无法获得名为BookTitle的元素的值。除此之外,您的XSLT似乎还不错。但是您的输入不是。

最新更新