XML and XSL connection
Posted
by Irgat
on Stack Overflow
See other posts from Stack Overflow
or by Irgat
Published on 2010-05-02T12:52:34Z
Indexed on
2010/05/02
12:57 UTC
Read the original article
Hit count: 362
I have a problem between XML and XSL files. In XML file, there are some elements such as
*<school>
<student studentID="12345">
<name>Stud I</name>
<takes>CMPE471</takes>
<takes>CMPE412</takes>
<takes>CMPE100</takes>
</student>
<student studentID="67890">
<name>Stud II</name>
<takes>CMPE471</takes>
<takes>CMPE412</takes>
</student>
<course courseCode="CMPE471">
<courseName>NAME I </courseName>
<description>DESC I </description>
</course>
<course courseCode="CMPE412">
<courseName>NAME II </courseName>
<description>DESC II </description>
</course>
<course courseCode="CMPE100">
<courseName>NAME III </courseName>
<description>DESC III </description>
</course>
In XSL file,I want to reach "description" element which I specified "courseCode".
Output should be like this,
1. Stud I
a. CMPE471 Desc I
b. CMPE412 Desc II
c. CMPE100 Desc III
2. Stud II
a. CMPE471 Desc I
b. CMPE412 Desc II
In XSL file, I tried to write something :
<ol>
<xsl:for-each select="/school/student">
<xsl:sort data-type="text" order="ascending" select="name"/>
<li><xsl:value-of select="name"/>
<ol type="a">
<xsl:for-each select="takes">
<xsl:sort data-type="text" select="text()" order="ascending"/>
<li>
<xsl:for-each select="/school/course">//PROBLEM
<xsl:value-of select="description [@courseCode = text()]"/>//PROBLEM
</xsl:for-each>//PROBLEM
</li>
</xsl:for-each>
</ol>
</xsl:for-each>
</ol>
Thanks.
© Stack Overflow or respective owner