Apologies if the title is bit confusing, had to keep it concise.

Okay so the xml document looks like this

<students>
        <student sid="S2208">
            <fname>Ben</fname>
            <lname>Doe</lname>
            <scourses courseid="DSA" mode="full-time"/>
            <scourses courseid="INT" mode="part-time"/>
        </student>
<students>

<lecturers>
        <lecturer lid="L1101">
            <fname>Dohn</fname>
            <lname>Joe</lname>
            <lcourses courseid="DSA"/>
            <lcourses courseid="INT"/>
            <lcourses courseid="ACT"/>
        </lecturer>
<lecturers>

Using the courseid attribute of scourses in the /students/student is it possible to then retrieve the lid attribute of /lecturers/lecturer by testing whether it exists as an attribute of lcourses? I can only manage to get a 'true' evaluation with the methods I've come up with but not the actual content lid.

What are we working with here? XSLT? XPATH? Other?

As retrieving the value may differ slightly as a result

XSLT. Since XSLT uses XPATH to navigate the XML document, how would the result differ?

It wouldn't too much, just where the result came from and how the code was written to select such values.

XPath would return results directly through programming while XSLT creates a whole new XML/TXT/HTML file to which it outputs/reorders information

Okay, here's my xslt transformation to html.

    <xsl:template match="xt:students">
        <h1>Student Schedule</h1>
        <xsl:for-each select="xt:student">
            <p>
                <xsl:value-of select="@sid"/>
                <xsl:text> </xsl:text> 
                <xsl:value-of select="xt:fname"/> 
                <xsl:text> </xsl:text> 
                <xsl:value-of select="xt:lname"/>
            </p>
            <table border="1">
                <tr>
                    <td><b>Course</b></td>
                    <td><b>Lecturer</b></td>
                    <td><b>Time</b></td>
                    <td><b>Venue</b></td>
                </tr>
                <xsl:for-each select="xt:scourses">
                    <tr>
                        <td><xsl:value-of select="@courseid"/> - <xsl:value-of select="@mode"/></td>
                        <td>
                            <xsl:value-of select="../../../xt:lecturers/xt:lecturer/@lid"/>
                        </td>
                    </tr>
                </xsl:for-each>
            </table>
        </xsl:for-each>
    </xsl:template>

It generates a timetable for a particular student. There are going to be different subjects with one lecturer teaching one subject. The problem is, that i can't seem to find away of returning the lecturer id, by matching the attribute courseid of student/scourses to the attribute courseid of lecturer/lcourses.

Is that even possible with XSLT or XPATH?

Edited 4 Years Ago by Anark10n

This article has been dead for over six months. Start a new discussion instead.