<HTML dir=ltr><HEAD><TITLE>Having problems duplicating nodes</TITLE>
<META http-equiv=Content-Type content="text/html; charset=unicode">
<META content="MSHTML 6.00.6000.16735" name=GENERATOR></HEAD>
<BODY>
<DIV id=idOWAReplyText71498 dir=ltr>
<DIV dir=ltr><FONT face=Arial color=#000000 size=2>You're not duplicating icons more than once are you? When you call duplicate, you are manipulatingthe xml in the rlo file:</FONT></DIV>
<DIV dir=ltr><FONT face=Arial size=2></FONT> </DIV>
<DIV dir=ltr><FONT face=Arial size=2>//this makes n + 1 children on icon.nextSibling:</FONT></DIV>
<DIV dir=ltr><FONT face=Arial size=2>icon.nextSibling.firstChild.duplicate(n);</FONT></DIV>
<DIV dir=ltr><FONT face=Arial size=2></FONT> </DIV>
<DIV dir=ltr><FONT face=Arial size=2>//call it again (perhaps because we revisit this page):</FONT></DIV>
<DIV dir=ltr><FONT face=Arial size=2>icon.nextSibling.firstChild.duplicate(n);</FONT></DIV>
<DIV dir=ltr><FONT face=Arial size=2></FONT> </DIV>
<DIV dir=ltr><FONT face=Arial size=2>//how many children?</FONT></DIV>
<DIV dir=ltr><FONT face=Arial size=2>debug(icon.nextSibling.childNodes.length); //duh. Twice as many as I needed.</FONT></DIV>
<DIV dir=ltr><FONT face=Arial size=2></FONT> </DIV>
<DIV dir=ltr><FONT face=Arial size=2>//so, only let the duplicate run once, 'cos if we revisit a page, we'll end up with too many xml nodes...</FONT></DIV>
<DIV dir=ltr><FONT face=Arial size=2>if (someFlag != true){</FONT></DIV>
<DIV dir=ltr><FONT face=Arial size=2> duplicate(....make icons here...);</FONT></DIV>
<DIV dir=ltr><FONT face=Arial size=2> someFlag = true;</FONT></DIV>
<DIV dir=ltr><FONT face=Arial size=2>}</FONT></DIV>
<DIV dir=ltr><FONT face=Arial size=2></FONT> </DIV>
<DIV dir=ltr><FONT face=Arial size=2>//i tend to do it like this, so duplicate code in icon will only ever run once:</FONT></DIV>
<DIV dir=ltr><FONT face=Arial size=2>if (icon.attributes.built != 'true'){</FONT></DIV>
<DIV dir=ltr><FONT face=Arial size=2> //duplicate and other logic here</FONT></DIV>
<DIV dir=ltr><FONT face=Arial size=2> icon.attributes.built = 'true';</FONT></DIV>
<DIV dir=ltr><FONT face=Arial size=2>}</FONT></DIV>
<DIV dir=ltr><FONT face=Arial size=2></FONT> </DIV>
<DIV dir=ltr><FONT face=Arial size=2>sort that out and the see if you've got any issues left. The thing is that 'icon' refers to the underlying xml node - that is key to understanding what's happening with duplicate(); make sure the code that builds the piece only runs once.</FONT></DIV>
<DIV dir=ltr><FONT face=Arial size=2></FONT><FONT face=Arial size=2></FONT> </DIV>
<DIV dir=ltr><FONT face=Arial size=2>J</FONT></DIV></DIV>
<DIV dir=ltr><BR>
<HR tabIndex=-1>
<FONT face=Tahoma size=2><B>From:</B> xerte-bounces@lists.nottingham.ac.uk on behalf of Paul Swanson<BR><B>Sent:</B> Wed 03/12/2008 18:59<BR><B>To:</B> Xerte discussion list<BR><B>Subject:</B> [Xerte] Having problems duplicating nodes<BR></FONT><BR></DIV>
<DIV>
<P><FONT face=Verdana size=2>Hi,</FONT> </P>
<P><FONT face=Verdana size=2>Sorry for the length of this post. I've been banging my head on this for a few days, trying to work it out for myself, but not having much success.</FONT></P>
<P><FONT face=Verdana size=2>I have a course with test questions in an external xml file. The course is broken up into lessons with each lesson having some questions, but the test includes the questions for all the lessons. The full test works fine, but at the end of each lesson we want a Wrap Up Quiz, which consists of the questions for just that lesson. I am struggling with getting just the pertinent lesson questions to display. What is happening is that the lesson questions duplicate the wrong number of times, and only one question is displayed. And worst of all, it's inconsistent in the behavior. Lesson 1 has 2 questions, but each time I run it I get a different number of questions - sometimes it's 2, but usually it is more - 3, 5, 10 - all over the place. Usually a question only appears on one of the pages, when it appears on multiple pages it's the same question on each page. Bizarre.</FONT></P>
<P><FONT face=Verdana size=2>The structure of the xml file is as follows (for brevity, I've just included a couple of questions for a couple of lessons):</FONT></P>
<P><FONT face="Courier New" size=2><quiz></FONT> </P>
<P><FONT face="Courier New" size=2> <!-- Lesson 1 --></FONT> </P>
<P><FONT face="Courier New" size=2> <question lesson="1"></FONT> <BR><FONT face="Courier New" size=2> <prompt><![CDATA[What section of General System Setup allows you to establish access rights to various levels of program use?]]></prompt></FONT></P>
<P><FONT face="Courier New" size=2> <answer correct="false"><![CDATA[Tools > Security]]></answer></FONT> <BR><FONT face="Courier New" size=2> <answer correct="false"><![CDATA[File > View Licenses]]></answer></FONT> <BR><FONT face="Courier New" size=2> <answer correct="false"><![CDATA[General > Institution Setup]]></answer></FONT> <BR><FONT face="Courier New" size=2> <answer correct="true"><![CDATA[Personnel > Access Groups]]></answer></FONT> <BR><FONT face="Courier New" size=2> <answer correct="false"><![CDATA[Libraries > Financial Institution]]></answer></FONT> <BR><FONT face="Courier New" size=2> </question></FONT> <BR><FONT face="Courier New" size=2> </FONT><BR><FONT face="Courier New" size=2> <question lesson="1"></FONT> <BR><FONT face="Courier New" size=2> <prompt><![CDATA[What telephone number would you call to inquire about interpreting certain language in a Truth-In-Savings Disclosure?]]></prompt></FONT></P>
<P><FONT face="Courier New" size=2> <answer correct="false"><![CDATA[Training Dept: 800-274-7255]]></answer></FONT> <BR><FONT face="Courier New" size=2> <answer correct="false"><![CDATA[Main HFS Line: 800-724-7280]]></answer></FONT> <BR><FONT face="Courier New" size=2> <answer correct="true"><![CDATA[Compliance Support: 800-274-7287]]></answer></FONT> <BR><FONT face="Courier New" size=2> <answer correct="false"><![CDATA[Sales: 800-274-7259]]></answer></FONT> <BR><FONT face="Courier New" size=2> </question></FONT> <BR><FONT face="Courier New" size=2> </FONT><BR><FONT face="Courier New" size=2> <!-- Lesson 2 --></FONT> <BR><FONT face="Courier New" size=2> </FONT><BR><FONT face="Courier New" size=2> <question lesson="2"></FONT> <BR><FONT face="Courier New" size=2> <prompt><![CDATA[Which menu item(s) on the DepositPro Admin menu allows you to set up your fee structure for Cashiers Checks?]]></prompt></FONT></P>
<P><FONT face="Courier New" size=2> <answer correct="false"><![CDATA[Use Setup > Fees]]></answer></FONT> <BR><FONT face="Courier New" size=2> <answer correct="true"><![CDATA[Use Policies > Policy Components]]></answer></FONT> <BR><FONT face="Courier New" size=2> <answer correct="false"><![CDATA[Use Products > Update Fees]]></answer></FONT> <BR><FONT face="Courier New" size=2> <answer correct="false"><![CDATA[None of the Above]]></answer></FONT> <BR><FONT face="Courier New" size=2> </question></FONT> <BR><FONT face="Courier New" size=2> </FONT><BR><FONT face="Courier New" size=2> <question lesson="2"></FONT> <BR><FONT face="Courier New" size=2> <prompt><![CDATA[How do you allow Options Other Than Those Listed for Marketing Categories and Funds Sources Library?]]></prompt></FONT></P>
<P><FONT face="Courier New" size=2> <answer correct="false"><![CDATA[Use an Edit Code of "Editable" on the drop-down list]]></answer></FONT> <BR><FONT face="Courier New" size=2> <answer correct="true"><![CDATA[Use the menu item Policies > Marketing Categories and check the box labeled "During Transaction Processing, Allow Options Other Than Those Listed"]]></answer></FONT></P>
<P><FONT face="Courier New" size=2> <answer correct="false"><![CDATA[This is an editable field. You may include any option at any time.]]></answer></FONT> <BR><FONT face="Courier New" size=2> <answer correct="false"><![CDATA[None of the Above. Only listed options are allowed.]]></answer></FONT> <BR><FONT face="Courier New" size=2> </question></FONT> </P>
<P><FONT face="Courier New" size=2></quiz></FONT> </P>
<P><FONT face=Verdana size=2>The xml data is saved to a variable called quizData (</FONT><FONT face="Courier New" size=2>quizData = templateData.quiz[0];</FONT><FONT face=Verdana size=2>). In the Entry Frame of my lesson, I have the following:</FONT></P>
<P><FONT face="Courier New" color=#800000 size=2>// create arrays for lesson 1 quiz</FONT> <BR><FONT face="Courier New" color=#800000 size=2>lesson1quiz = new Array ();</FONT> <BR><FONT face="Courier New" color=#800000 size=2>wrapupBuilt = new Array ();</FONT> <BR><FONT face="Courier New" color=#800000 size=2>wrapupTracking = new Array ();</FONT> <BR><FONT face="Courier New" color=#800000 size=2>wrapupAnswers = new Array ();</FONT> </P>
<P><FONT face="Courier New" color=#800000 size=2>lesson1Counter = 0; // counter for number of questions</FONT> </P>
<P><FONT face="Courier New" color=#800000 size=2>// loop through all questions to get lesson 1</FONT> <BR><FONT face="Courier New" color=#800000 size=2>for (i = 0; i < quizData.question.length; i++;) {</FONT> </P>
<P><FONT face="Courier New" color=#800000 size=2> if (quizData.question[i].lesson == '1') {</FONT> <BR><FONT face="Courier New" color=#800000 size=2> </FONT><BR><FONT face="Courier New" color=#800000 size=2> lesson1quiz[lesson1Counter].question = quizData.question[i];</FONT> <BR><FONT face="Courier New" color=#800000 size=2> lesson1Counter++;</FONT> </P>
<P><FONT face="Courier New" color=#800000 size=2> } // end of quizData.question[i] conditional</FONT> </P>
<P><FONT face="Courier New" color=#800000 size=2>} // end of for loop</FONT> </P>
<P><FONT face="Courier New" color=#800000 size=2>// create the right number of questions</FONT> <BR><FONT face="Courier New" color=#800000 size=2>icon.parentNode.nextSibling.nextSibling.childNodes[0].childNodes[1].duplicate(lesson1Counter-1);</FONT> </P>
<P><FONT face=Verdana size=2>The script icon is in the Entry Frame of the Lesson framework, and the page with the wrap up questions follows one other page with introductory text, so icon.parentNode.nextSibling.nextSibling should point to the wrap up page. The wrap up page contains a framework as the first icon (childNodes[0]) with an Entry Frame, and the proto Wrap Up page (childNodes[0].childNodes[1]), which displays the question, and includes radio buttons for the multiple-choice answers. The entry frame doesn't include any code that deals with the actual questions. The proto Wrap Up page includes a script icon that gets the current question number:</FONT> <FONT face="Courier New" size=2>questIndex = icon.parentNode.index() - 1;</FONT><FONT face=Verdana size=2>. There is a text icon for displaying the question using the following expression:</FONT> <FONT face="Courier New" size=2>{lesson1quiz[questIndex].question.prompt}</FONT><FONT face=Verdana size=2>. And another icon that sets up the answer radio buttons that seems to work properly, duplicating the correct answers for the question.</FONT></P>
<P><FONT face=Verdana size=2>I believe the problem is with the script that duplicates the questions, which I've marked in maroon colored text. Not only is it creating the wrong number of questions, but it also is affecting the display of Page x of y that normally prints on the introductory page. The variable lesson1Counter holds the correct value - as part of my debugging, I started printing it out as part of the question, and it always prints the correct number of questions for that lesson. So why is it creating an inconsistent number of questions when I use that same variable for the duplicate() method?</FONT></P>
<P><FONT face=Verdana size=2>I can strip down the file and zip it for download, if that would help. But I would really like to learn what I'm doing wrong so I don't do it again.</FONT></P>
<P><FONT face=Verdana size=2>Thanks for any assistance!</FONT> </P>
<P><FONT face="Courier New" color=#808080 size=2>_____________________________</FONT> </P>
<P><FONT face="Courier New" color=#808080 size=2> Paul Swanson</FONT> <BR><FONT face="Courier New" color=#808080 size=2> Instructional Designer</FONT> <BR><FONT face="Courier New" color=#808080 size=2> Harland Financial Solutions</FONT> <BR><FONT face="Courier New" color=#808080 size=2> 800.274.7280 Ext. 2462</FONT> <BR><FONT face="Courier New" color=#808080 size=2> Paul.Swanson@harlandfs.com</FONT> <BR><FONT face="Courier New" color=#808080 size=2>_____________________________</FONT> </P></DIV></BODY></HTML>