Author
XML to ASCII text
Ronald Wee
Greenhorn
Joined: Jul 02, 2001
Posts: 1
posted Jul 02, 2001 20:35:00
0
I'm new to XML/XSL and would appreciate any assistance. I would like to traverse the <event> tag and retrieve all the info as a single text record. But I'm having trouble with extracting the remaining <participants> and <entity> info (see expected output). So far, only managed to display partial info. Below are the given xsl & xml files. Thanks in advance. EXPECTED OUTPUT ================ 1 , PHYSICS , Monday , 8:00 , 10:00 , 1A , Bush , Lab 2 , MATHS , Tuesday , 16:00 , 18:00 , 1A , Clinton , TutRm 1-2 1 , PHYSICS , Wednesday , 10:00 , 12:00 , 1A , Bush , Lab 3 , POLITICS , Thursday , 13:00 , 16:00 , 1A , Bush + Clinton , TutRm 1-1 reliefhelp.xsl ============== <?xml version="1.0" ?> - <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> - <xsl:template match="timetable"> - <xsl:for-each select="//event"> <xsl:value-of select="@courseId" /> <xsl:variable name="v_id4" select="@courseId" /> <xsl:text>,</xsl:text> <xsl:value-of select="/project/courses/course[@id=$v_id4]/@name" /> <xsl:variable name="v_index1" select="/project/slots/@first" /> <xsl:variable name="v_index2" select="/project/slots/@last" /> <xsl:variable name="total_slots" select="number($v_index2) - number($v_index1) + 1" /> <xsl:variable name="v_day1" select="/project/days/@first" /> <xsl:variable name="v_day2" select="/project/days/@last" /> <xsl:text>,</xsl:text> <xsl:variable name="v_day" select="floor(@weekhour div $total_slots)" /> <xsl:value-of select="/project/days/day[@index=$v_day]/@name" /> <xsl:variable name="v_starttime" select="@weekhour mod $total_slots + $v_index1" /> <xsl:variable name="v_endtime" select="$v_starttime + @duration" /> <xsl:text>,</xsl:text> <xsl:value-of select="/project/slots/slot[@index=$v_starttime]/@name" /> <xsl:text>,</xsl:text> <xsl:value-of select="/project/slots/slot[@index=$v_endtime]/@name" /> <br> <br /> <!-- need help to extract remaining info --> </xsl:for-each> </xsl:template> </xsl:stylesheet> reliefhelp.xml ============== <?xml version="1.0" encoding="UTF-8"?> <?xml:stylesheet type="text/xsl" href="reliefhelp.xsl"?> <project name="relief"> <slots first="8" last="17"> <slot index="8" name="8:00" /> <slot index="9" name="9:00" /> <slot index="10" name="10:00" /> <slot index="11" name="11:00" /> <slot index="12" name="12:00" /> <slot index="13" name="13:00" /> <slot index="14" name="14:00" /> <slot index="15" name="15:00" /> <slot index="16" name="16:00" /> <slot index="17" name="17:00" /> <slot index="18" name="18:00" /> </slots> <days first="0" last="4"> <day index="0" name="Monday" /> <day index="1" name="Tuesday" /> <day index="2" name="Wednesday" /> <day index="3" name="Thursday" /> <day index="4" name="Friday" /> </days> <entities entityType="1"> <entity id="5" entityType="1" name="1A" > </entity> </entities> <entities entityType="2"> <entity id="1" entityType="2" name="Clinton" > </entity> <entity id="2" entityType="2" name="Bush" > </entity> </entities> <entities entityType="3"> <entity id="3" entityType="3" name="Lab" > </entity> <entity id="4" entityType="3" name="TutRm 1-1" > </entity> <entity id="8" entityType="3" name="TutRm 1-2" > </entity> </entities> <courses> <course id="1" name="PHYSICS" duration="2+2" > <participants> <and id="1" entityId="5" /> <and id="2" entityId="2" /> <or id="3" entityType="3"> <and id="4" entityId="3" /> </or> </participants> </course> <course id="2" name="MATHS" duration="2" > <participants> <and id="5" ententityId="5" /> <and id="6" entityId="1" /> <or id="7" entityType="3"> <and id="8" entityId="4" /> <and id="9" entityId="8" /> </or> </participants> </course> <course id="3" name="POLITICS" duration="3.0" > <participants> <and id="10" entityId="5" /> <and id="11" entityId="2" /> <and id="12" entityId="1" /> <and id="16" entityId="4" /> </participants> </course> </courses> <timetable> <event id="1" courseId="1" duration="2" weekhour="0"> <resources> <resource nodeId="4" entityId="3" /> </resources> </event> <event id="3" courseId="2" duration="2" weekhour="18"> <resources> <resource nodeId="9" entityId="8" /> </resources> </event> <event id="2" courseId="1" duration="2" weekhour="22" > <resources> <resource nodeId="4" entityId="3" /> </resources> </event> <event id="4" courseId="3" duration="3" weekhour="35" > <resources /> </event> </timetable> </project>
subject: XML to ASCII text