0
我有兩個主要的XML元素:courses
和CRNs
XSLT鍵()基本
<courses>
<course credits="3" courseNum="COMP1950" name="Intermediate Web Development and Design" url="http://www.bcit.ca/study/outlines/comp1950">
<prereqs>
<prereq courseNum="COMP1850"/>
</prereqs>
</course>
<course credits="1" courseNum="COMP1854" name="Content Management with Drupal" url="http://www.bcit.ca/study/outlines/comp1854">
<prereqs>
<prereq courseNum="COMP1854"/>
</prereqs>
</course>
<course credits="3" courseNum="COMP1920" name="Server-side Web Scripting with PHP Level 1" url="http://www.bcit.ca/study/outlines/comp1920">
<prereqs>
<prereq courseNum="COMP1850"/>
</prereqs>
</course>
</courses>
<CRNs>
<CRN crn="78645" courseNum="COMP4625" totalWeeks="12" startDate="Jan16" endDate="Apr02" cost="489.00" instructor="Arron Ferguson" term="201210"/>
<CRN crn="47515" courseNum="COMP1002" totalWeeks="12" startDate="Jan09" endDate="Mar26" cost="109.00" instructor="Michael Evans" term="201210"/>
<CRN crn="47515" courseNum="COMP1002" totalWeeks="12" startDate="Jan09" endDate="Mar26" cost="109.00" instructor="Michael Evans" term="201210"/>
<CRN crn="47514" courseNum="COMP1002" totalWeeks="12" startDate="Jan10" endDate="Mar2702" cost="109.00" instructor="Fraser Robertson" term="201210"/>
<CRN crn="47513" courseNum="COMP1002" totalWeeks="6" startDate="Jan11" endDate="Apr04" cost="109.00" instructor="Michael Evans" term="201210"/>
<CRN crn="49033" courseNum="COMP2899" totalWeeks="12" startDate="Jan10" endDate="Apr03" cost="489.00" instructor="Arron Ferguson" term="201210"/>
<CRN crn="49029" courseNum="COMP1920" totalWeeks="12" startDate="Jan12" endDate="Apr05" cost="510.00" instructor="Jason Harrison" term="201210"/>
<CRN crn="54151" courseNum="COMP1920" totalWeeks="12" startDate="Feb22" endDate="Apr02" cost="520.00" instructor="Jason Harrison" term="201210"/>
<CRN crn="60270" courseNum="COMP1854" totalWeeks="2" startDate="Jun10" endDate="Jun17" cost="197.00" instructor="Jason Harrison" term="201220"/>
<CRN crn="60271" courseNum="COMP1854" totalWeeks="2" startDate="Jun09" endDate="Jun16" cost="197.00" instructor="Jason Harrison" term="201220"/>
</CRNs>
我想,以獲得從課程@name屬性使用courseNum作爲重點。
到目前爲止我的代碼是:
<xsl:for-each select="CRNs/CRN[@term='201220']">
<xsl:sort select="./@courseNum" order="ascending" data-type="text"/>
<tr>
<td> <xsl:value-of select="./@courseNum"/></td>
<td>
<a target="_blank" href="{./@url}">
<!--How do I use the key() function here in order to obtain the @name from the course element?-->
<!--I am also trying to obtain the @url (also from the course element) in this case-->
</a>
</tr>
</xsl:for-each>
似乎沒有工作... – iggy2012 2012-03-19 18:04:08
啊是的。我試圖運行它沒有變量「課程」,出於某種原因,它的工作。 – iggy2012 2012-03-19 18:30:19
非常感謝馬丁。這非常有教育意義並且有幫助。你是一個紳士和學者。有一張支票。 – iggy2012 2012-03-19 18:30:57