Wrox Programmer Forums
Go Back   Wrox Programmer Forums > XML > XSLT
|
XSLT General questions and answers about XSLT. For issues strictly specific to the book XSLT 1.1 Programmers Reference, please post to that forum instead.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the XSLT section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old May 4th, 2006, 05:19 AM
Registered User
 
Join Date: May 2006
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default infinite recursion

i am trying to extract information from another xml doc. what i have done is to use the document method. The output that results is an infinite recursion. The following is my code

<?xml version="1.0"?>
<xsl:stylesheet
    version="1.0"
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    xmlns="http://www.w3.org/TR/REC-html40">

<xsl:output method="html"/>

<xsl:variable name ="CSE4500xml" select="document('tutorialCSE4500.xml')"/>

<xsl:template match="/">
    <xsl:apply-templates select = "units/unit"/>
</xsl:template>


<xsl:template match="unit">
    <HTML>
        <BODY>
        <H2>UNIT TIMETABLE:<xsl:value-of select="name"/></H2>
        Unit Code:
            <xsl:value-of select="code"/>
        <BR/>
        Unit Lecturer:
            <xsl:value-of select="unitLeader"/>
                <table border="1">
                    <th align="left">Tutorial ID</th>
                      <th align="left">Tutor</th>
                      <th align="left">TimeTable</th>
                    <xsl:apply-templates select="$CSE4500xml/tutorialClasses/unit"/>
                        <TD><xsl:value-of select="tutorialClasses/unit/class"/></TD>
                        <TD><xsl:value-of select="tutorialClasses/unit/tutor"/></TD>
                        <TD><xsl:value-of select="tutorialClasses/unit/timetable"/></TD>
                </table>

        </BODY>
    </HTML>
</xsl:template>

</xsl:stylesheet>
 I know that the error occurs in the line that I just put in bold. But i do not know how to resolve it. Please help.

Thanks

 
Old May 4th, 2006, 05:28 AM
joefawcett's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 3,074
Thanks: 1
Thanked 38 Times in 37 Posts
Default

You'll have to show some of the 'tutorialCSE4500.xml' for me to be sure but when you're inside the template that matches unit you make a call to $CSE4500xml/tutorialClasses/unit which then starts a recursion. As unit is the context node you can change the code to:
Code:
<table border="1"><tr>
                    <th align="left">Tutorial ID</th>
                      <th align="left">Tutor</th>
                      <th align="left">TimeTable</th></tr><tr>
                                            <TD><xsl:value-of select="class"/></TD>
                        <TD><xsl:value-of select="tutor"/></TD>
                        <TD><xsl:value-of select="timetable"/></TD></tr>
                </table>
That assumes you want a header for each unit which seems odd. You could move the header code a level up for example.

As I said if you this fails show an example of the source XML and your desired output.

On a side note why are you using the document function instead of just using the standard input method?

--

Joe (Microsoft MVP - XML)
 
Old May 4th, 2006, 05:50 AM
Registered User
 
Join Date: May 2006
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi joe, thanks for the quick reply. the expected output that i want is
UNIT TIMETABLE:

Unit Code:



Unit Lecturer:









Tutorial ID Tutor TimeTable

the source file for the xml is

<?xml version="1.0"?>
<tutorialClasses xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
                 xsi:noNamespaceSchemaLocation="tutorial.xsd">
    <unit>
        <unitCode>CSE4500</unitCode>
        <class ID="t1">
            <tutor>Evi Syukur</tutor>
            <timetable>
                <day>Wednesday</day>
                <time>2-4 PM</time>
            </timetable>
            <studentMark>
                <student ID="s112233441">
                    <name>James Hird</name>
                    <assignments>
                        <assignment no="1">80</assignment>
                        <assignment no="2">90</assignment>
                        <unitTest>75</unitTest>
                    </assignments>
                </student>



 
Old May 4th, 2006, 05:54 AM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

Within this template rule

<xsl:template match="unit">

you are doing

<xsl:apply-templates select="$CSE4500xml/tutorialClasses/unit"/>

which is going to match the template rule you are in, causing a recursive call. There's nothing to terminate the recursion so it goes on for ever.

Change the template to say match="units/unit": this will stop the recursive call. But I don't know what processing you actually want to apply to tutorialClasses/unit - perhaps you need another template rule to define this. Or perhaps you don't want to apply-templates to tutorialClasses/unit at all, since you then go on to output its details using xsl:value-of.

Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference





Similar Threads
Thread Thread Starter Forum Replies Last Post
infinite loop smilesmita Pro PHP 1 December 21st, 2007 10:44 AM
recursion yui0329 C# 6 April 28th, 2005 09:36 AM
Recursion shan9 JSP Basics 0 November 17th, 2004 09:29 PM
recursion nulogix PHP How-To 1 June 28th, 2004 03:58 PM
Infinite timer? acdsky VBScript 1 June 17th, 2004 02:59 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.