XSLT problems
Author |
Message |
StarGateSG-1
|
Posted: Thu Apr 13, 2006 7:34 am Post subject: XSLT problems |
|
|
Hello,
I am having trouble getting all my fields in XSLT script to show, most of them show, but this one field doesn't.
I will attach the fiels when i figure out were the attach section is?? |
|
|
|
|
|
Sponsor Sponsor
|
|
|
StarGateSG-1
|
Posted: Thu Apr 13, 2006 7:40 am Post subject: (No subject) |
|
|
hmm...
Were is the add attachments?
O well I will post them.
Note: you will be able to see the problem right away.
This is the data file, the dats is test data though.
code: | <?xml version="1.0" encoding="iso-8859-1"?>
<?xml-stylesheet type="text/xsl" href="Period Attend.xsl"?>
<Attendance>
<Student_Grade_Attendance>
<Grade_9></Grade_9>
<Grade_10></Grade_10>
<Grade_11></Grade_11>
<Grade_12></Grade_12>
</Student_Grade_Attendance>
<Student_Period_Attendance>
<Friday>
<Period_1>90</Period_1>
<Period_2>50</Period_2>
<Period_3>75</Period_3>
<Period_4>34</Period_4>
</Friday>
<Monday>
<Period_1>67</Period_1>
<Period_2>34</Period_2>
<Period_3>53</Period_3>
<Period_4>24</Period_4>
</Monday>
<Tuesday>
<Period_1>67</Period_1>
<Period_2>45</Period_2>
<Period_3>75</Period_3>
<Period_4>47</Period_4>
</Tuesday>
<Wednesday>
<Period_1>47</Period_1>
<Period_2>76</Period_2>
<Period_3>47</Period_3>
<Period_4>89</Period_4>
</Wednesday>
<Thursday>
<Period_1>19</Period_1>
<Period_2>78</Period_2>
<Period_3>86</Period_3>
<Period_4>45</Period_4>
</Thursday>
</Student_Period_Attendance>
<Students_by_Period>
<First_Period>900</First_Period>
<Second_Period>950</Second_Period>
<Third_Period>850</Third_Period>
<Fourth_Period>700</Fourth_Period>
</Students_by_Period>
<Attendance_Long_Term>
<Attendance_Yesterday></Attendance_Yesterday>
<Attendance_Last_Week></Attendance_Last_Week>
<Attendance_Last_Month></Attendance_Last_Month>
</Attendance_Long_Term>
</Attendance> |
This is the XSLT file.
code: | <?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>Attendance Report by Period</h2>
<table border="1">
<tr bgcolor="#FFFFFF">
<th align="left">Period</th>
<th align="left">Total Students</th>
<th align="left">Friday</th>
<th align="left">Monday</th>
<th align="left">Tuesday</th>
<th align="left">Wednesday</th>
<th align="left">Thursday</th>
</tr>
<xsl:for-each select="Attendance/Student_Period_Attendance">
<tr>
<td>Period 1</td>
<td>#<xsl:value-of select="Students_by_Period/First_Period"/></td>
<td>%<xsl:value-of select="Friday/Period_1"/></td>
<td>%<xsl:value-of select="Monday/Period_1"/></td>
<td>%<xsl:value-of select="Tuesday/Period_1"/></td>
<td>%<xsl:value-of select="Wednesday/Period_1"/></td>
<td>%<xsl:value-of select="Thursday/Period_1"/></td>
</tr>
<tr>
<td>Period 2</td>
<td>#<xsl:value-of select="Students_by_Period/Second_Period"/></td>
<td>%<xsl:value-of select="Friday/Period_2"/></td>
<td>%<xsl:value-of select="Monday/Period_2"/></td>
<td>%<xsl:value-of select="Tuesday/Period_2"/></td>
<td>%<xsl:value-of select="Wednesday/Period_2"/></td>
<td>%<xsl:value-of select="Thursday/Period_2"/></td>
</tr>
<tr>
<td>Period 3</td>
<td>#<xsl:value-of select="Students_by_Period/Third_Period"/></td>
<td>%<xsl:value-of select="Friday/Period_3"/></td>
<td>%<xsl:value-of select="Monday/Period_3"/></td>
<td>%<xsl:value-of select="Tuesday/Period_3"/></td>
<td>%<xsl:value-of select="Wednesday/Period_3"/></td>
<td>%<xsl:value-of select="Thursday/Period_3"/></td>
</tr>
<tr>
<td>Period 4</td>
<td>#<xsl:value-of select="Students_by_Period/Fourth_Period"/></td>
<td>%<xsl:value-of select="Friday/Period_4"/></td>
<td>%<xsl:value-of select="Monday/Period_4"/></td>
<td>%<xsl:value-of select="Tuesday/Period_4"/></td>
<td>%<xsl:value-of select="Wednesday/Period_4"/></td>
<td>%<xsl:value-of select="Thursday/Period_4"/></td>
</tr>
</xsl:for-each>
</table>
</body>
</html>
</xsl:template>
</xsl:stylesheet> | [/code] |
|
|
|
|
|
rdrake
|
Posted: Thu Apr 13, 2006 3:03 pm Post subject: (No subject) |
|
|
It looks like, while it's pulling data from the xml file, it's not pulling everything out. Take a look at the line as follows: code: | <xsl:for-each select="Attendance/Student_Period_Attendance"> | Now, it's pulling data from <Student_Period_Attendance>, right? However, your <Students_by_Period> section has no data pulled from it. You're trying to pull data that's not within the section the other data is contained in, it's on the same level as the parent from which you're extracting the data.
Now, as for a solution, I really don't know. Just heard of XSLT myself, and I've had no time to investigate it further. |
|
|
|
|
|
rdrake
|
Posted: Thu Apr 13, 2006 3:23 pm Post subject: (No subject) |
|
|
Sorry for the double post, but I couldn't seem to edit my previous post...
Anyways, I've dug up a solution. The level you want to get up to is one higher than where your for-each statement is looking, right? So, you must go up a level before you can access the data. This can be achieved as follows: code: | <xsl:value-of select="../Students_by_Period/Third_Period"/> | So, you should have something like the following: code: | <?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>Attendance Report by Period</h2>
<table border="1">
<tr bgcolor="#FFFFFF">
<th align="left">Period</th>
<th align="left">Total Students</th>
<th align="left">Friday</th>
<th align="left">Monday</th>
<th align="left">Tuesday</th>
<th align="left">Wednesday</th>
<th align="left">Thursday</th>
</tr>
<xsl:for-each select="Attendance/Student_Period_Attendance">
<tr>
<td>Period 1</td>
<td>#<xsl:value-of select="../Students_by_Period/First_Period"/></td>
<td>%<xsl:value-of select="Friday/Period_1"/></td>
<td>%<xsl:value-of select="Monday/Period_1"/></td>
<td>%<xsl:value-of select="Tuesday/Period_1"/></td>
<td>%<xsl:value-of select="Wednesday/Period_1"/></td>
<td>%<xsl:value-of select="Thursday/Period_1"/></td>
</tr>
<tr>
<td>Period 2</td>
<td>#<xsl:value-of select="../Students_by_Period/Second_Period"/></td>
<td>%<xsl:value-of select="Friday/Period_2"/></td>
<td>%<xsl:value-of select="Monday/Period_2"/></td>
<td>%<xsl:value-of select="Tuesday/Period_2"/></td>
<td>%<xsl:value-of select="Wednesday/Period_2"/></td>
<td>%<xsl:value-of select="Thursday/Period_2"/></td>
</tr>
<tr>
<td>Period 3</td>
<td>#<xsl:value-of select="../Students_by_Period/Third_Period"/></td>
<td>%<xsl:value-of select="Friday/Period_3"/></td>
<td>%<xsl:value-of select="Monday/Period_3"/></td>
<td>%<xsl:value-of select="Tuesday/Period_3"/></td>
<td>%<xsl:value-of select="Wednesday/Period_3"/></td>
<td>%<xsl:value-of select="Thursday/Period_3"/></td>
</tr>
<tr>
<td>Period 4</td>
<td>#<xsl:value-of select="../Students_by_Period/Fourth_Period"/></td>
<td>%<xsl:value-of select="Friday/Period_4"/></td>
<td>%<xsl:value-of select="Monday/Period_4"/></td>
<td>%<xsl:value-of select="Tuesday/Period_4"/></td>
<td>%<xsl:value-of select="Wednesday/Period_4"/></td>
<td>%<xsl:value-of select="Thursday/Period_4"/></td>
</tr>
</xsl:for-each>
</table>
</body>
</html>
</xsl:template>
</xsl:stylesheet> |
|
|
|
|
|
|
|
|