我有這個基於網站信息創建的xml文件。由於包含大量信息,我將發佈簡化版本。每個循環的XSLT/XML嵌套
這意味着使用xslt文件來顯示和模仿這樣的大學或大學課程的例子: 有多個課程要顯示,所以這就是爲什麼它開始於課程,然後我們有課程存儲每門課程。
這裏有像老師和其他描述的課程信息。然後我們進入年度,課程可以有多少年,這就是爲什麼我們把年度年份設置爲「1」,每年有兩個學期。在學期內有多個單位,所以我們把單位/單位存放。
這是我希望它看起來像給你一個想法的目標輸出。
我已經存儲在XML中的所有信息,這是我想通過XSLT來實現,但我不能確定如何開始它在這個層面上的輸出:http://puu.sh/80sBi/0107a6264e.png
這裏是我的代碼:
<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" href="Courses.xslt"?>
<courses>
<course>computing
<course_info></course_info>
<teacher etc>
<details></details>
</teacher etc>
<year ynum="1">
<semester snum="1">
<units>
<unit>
<code></code>
<title></title> <!-- this is the "description" table title -->
<credit_points></credit_points>
</unit>
<unit>
<code></code>
<title></title>
<credit_points></credit_points>
</unit>
</units>
</semester>
<semester snum="2">
<units>
<unit>
<code></code>
<title></title>
<credit_points></credit_points>
</unit>
</units>
</semester>
</year>
<year ynum="2">
<semester snum="1">
<units>
<unit>
<code></code>
<title></title>
<credit_points></credit_points>
</unit>
</units>
</semester>
<semester snum="2">
<units>
<unit>
</unit>
</units>
</semester>
</year>
</course>
</courses>
我在xslt文件中失敗的嘗試:/任何建議或幫助將不勝感激,因爲我似乎無法包裝我的頭如何讓這些循環工作的例子。
<?xml version="1.0" encoding="ISO-8859-1"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/">
<html>
<body>
<h2>Course information</h2>
<xsl:for-each select="courses/course">
<strong>Course:</strong><xsl:value-of select="course"/><br />
<strong>Code:</strong><xsl:value-of select="code"/><br />
<strong>Course Coordinaotr</strong><xsl:value-of select="fname"/><xsl:text> </xsl:text><xsl:value-of select="sname"/></li>
<table border="0">
<tr>
<th>unit</th>
<th>description</th>
<th>Credit Points</th>
</tr>
<xsl:for-each select="year/semester">
<tr>
<td><strong>Client ID:</strong><xsl:value-of select="unit_code"/></td>
<td><strong>OrderDate:</strong><xsl:value-of select="unit_title"/></td>
<td><strong>Quantity Ordered:</strong><xsl:value-of select="cp"/></td>
<td><strong>Order Status:</strong><xsl:value-of select="additional_link"/></td>
</xsl:for-each>
</tr>
</table>
</xsl:for-each>
</body>
</html>
</xsl:template></xsl:stylesheet>
我該如何解決這個問題?
我希望有人可以共享一些資源或處理類似上述的數據轉換成這樣的HTTP將XML XSLT的例子:// PUU .sh/80sBi/0107a6264e.png –