I have two major xml elements: courses and CRNs
<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>
I am trying to use courseNum as a key in order to obtain the @name attribute from courses.
so far my code is:
<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>
Use
as a child of the
xsl:stylesheetelement and then inside of thefor-eachyou can do[edit]
I think it does work, here is a more complete sample, with the input XML being
the minimal stylesheet
outputs
so the key works.
If you still have problems then edit your question and show us more details.