XML Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsProgramming Languages - MoreXML Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old May 25th, 2004, 09:33 AM
habibz habibz is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: May 2004
Posts: 4 habibz User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Exclamation XML to XSL problems!!

Hey,

I am having some problems converting this xml to xsl. I want the xsl to work for any XML files that are instance of the studentlist.dtd >> for example different course name, assessment items etc.).

Any help will be appreciated


--------------------------------------------------------
DTD below:

<!ATTLIST course code CDATA #REQUIRED>
<!ATTLIST item name CDATA #REQUIRED>
<!ELEMENT studentlist (course, student+)>
<!ELEMENT course (#PCDATA)>
<!ELEMENT student (snum, surname, firstname, results)>
<!ELEMENT results (item, total)>
<!ELEMENT snum (#PCDATA)>
<!ELEMENT surname (#PCDATA)>
<!ELEMENT firstname (#PCDATA)>
<!ELEMENT item (#PCDATA)>
<!ELEMENT total (#PCDATA)>

--------------------------------------------------------
XML below

<?xml version="1.0"?>
<?DOCTYPE markentry SYSTEM "studentlist.dtd"?>
<?xml-stylesheet type="text/xsl" href="results.xsl"?>

<studentList>
<course code="4545bus">Business Ethics
<student>

<snum>s11111</snum>
<surname>shi</surname>
<firstname>tan</firstname>
<results>
<item name="Assignment1">20</item>
<item name="Assignment2">20</item>
<item name="Exam">40</item>
<total>80</total>
</results>
</student>

<student>
....
....
....
</student>


</course>
</studentList>


-------------------------------------------------------
XSL below

<?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>4545bus Business Ethics</h2>

<table border="1">
<tr bgcolor="#9acd32">
<th align="left">snum</th>
<th align="left">Assignment1</th>
<th align="left">Assignment2</th>
<th align="left">Exam</th>
<th align="left">total</th>
</tr>

<xsl:for-each select="studentlist/course/student">
<xsl:sort select="snum"/>

<tr>
<td><xsl:value-of select="snum"/></td>

<td><xsl:value-of select="(results/item[@name='Assignment1'])" /></td>
<td><xsl:value-of select="(results/item[@name='Assignment2'])" /></td>
<td><xsl:value-of select="(results/item[@name='Exam'])" /></td>
<td><xsl:value-of select="(results/total)" /></td>

</tr>

</xsl:for-each>

</table>

</body>
</html>

</xsl:template>
</xsl:stylesheet>

Reply With Quote
  #2  
Old May 25th, 2004, 11:51 AM
ChrisRC ChrisRC is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Mar 2004
Location: Pittsburgh, PA
Posts: 30 ChrisRC User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 5
Well, you seem to have some idea what you're doing, iterating through the different students, so I'm not sure what actual difficulty you're having... I some some possible catch-points though:

Task 0: in the code you posted here, the xml file has a root node of studentList, while the xsl refers to studentlist. Since it appears twice in the xml and only once in the xsl, I'm assuming the capital should be there.

Task 1. Show the course code and course title based on data in the XML rather than explicit in the XSL.
Your <course> tag contains a lot of stuff other than the course title, so you'll have to either make the title an attribute or a seperate child tag. for the sake of this example let's say you make it an attribute. So then the line in your XSL which outputs this info would be:
Code:
<h2>
<xsl:value-of select="/studentList/course/@code"/> 
<xsl:text> </xsl:text> <!-- because xsl doesn't recognize it's own whitespace -->
<xsl:value-of select="/studentList/course/@title"/>
</h2>


Task 2: Iterate through results items names to get values for ths
picking the first instance of student as representative. If it might not be, you'll have figure something else out.
Code:
<tr bgcolor="#9acd32">
<th align="left">snum</th>
<xsl:for-each select="/studentList/course/student[1]/results/item">
<th align="left"><xsl:value-of select="@name"/></th>
</xsl:for-each>
<th align="left">total</th>
</tr>


Task 3: Iterate through results items values to get results for tds
Code:
<tr>
<td><xsl:value-of select="snum"/></td>
<xsl:for-each select="results/item">
<td><xsl:value-of select="current()" /></td>
</xsl:for-each>
<td><xsl:value-of select="results/total"/></td>
</tr>


Did I miss the point of your question? not address anything?


Full, modified xsl:
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><xsl:value-of select="/studentList/course/@code"/> <xsl:text> </xsl:text> <xsl:value-of select="/studentList/course/@title"/></h2>

<table border="1">
<tr bgcolor="#9acd32">
<th align="left">snum</th>
<xsl:for-each select="/studentList/course/student[1]/results/item">
<th align="left"><xsl:value-of select="@name"/></th>
</xsl:for-each>
<th align="left">total</th>
</tr>

<xsl:for-each select="studentList/course/student">
<xsl:sort select="snum"/>

<tr>
<td><xsl:value-of select="snum"/></td>

<xsl:for-each select="results/item">
<td><xsl:value-of select="current()" /></td>
</xsl:for-each>
<td><xsl:value-of select="results/total"/></td>
</tr>

</xsl:for-each>

</table>

</body>
</html>

</xsl:template>
</xsl:stylesheet>


Chris
crcdesign.net

Reply With Quote
  #3  
Old May 25th, 2004, 08:51 PM
habibz habibz is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: May 2004
Posts: 4 habibz User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Now I understand

Thanks alot for the help Chris, that was very helpful

Sam

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming Languages - MoreXML Programming > XML to XSL problems!!


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 3 hosted by Hostway
Stay green...Green IT