<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>&nbsp;</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>&nbsp;</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>&nbsp;</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>&nbsp;</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>&nbsp; duplicate(....make icons here...);</FONT></DIV>
<DIV dir=ltr><FONT face=Arial size=2>&nbsp; someFlag = true;</FONT></DIV>
<DIV dir=ltr><FONT face=Arial size=2>}</FONT></DIV>
<DIV dir=ltr><FONT face=Arial size=2></FONT>&nbsp;</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>&nbsp; //duplicate and other logic here</FONT></DIV>
<DIV dir=ltr><FONT face=Arial size=2>&nbsp; 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>&nbsp;</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>&nbsp;</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>&lt;quiz&gt;</FONT> </P>
<P><FONT face="Courier New" size=2>&nbsp; &lt;!-- Lesson 1 --&gt;</FONT> </P>
<P><FONT face="Courier New" size=2>&nbsp; &lt;question lesson="1"&gt;</FONT> <BR><FONT face="Courier New" size=2>&nbsp;&nbsp;&nbsp; &lt;prompt&gt;&lt;![CDATA[What section of General System Setup allows you to establish access rights to various levels of program use?]]&gt;&lt;/prompt&gt;</FONT></P>
<P><FONT face="Courier New" size=2>&nbsp;&nbsp;&nbsp; &lt;answer correct="false"&gt;&lt;![CDATA[Tools &gt; Security]]&gt;&lt;/answer&gt;</FONT> <BR><FONT face="Courier New" size=2>&nbsp;&nbsp;&nbsp; &lt;answer correct="false"&gt;&lt;![CDATA[File &gt; View Licenses]]&gt;&lt;/answer&gt;</FONT> <BR><FONT face="Courier New" size=2>&nbsp;&nbsp;&nbsp; &lt;answer correct="false"&gt;&lt;![CDATA[General &gt; Institution Setup]]&gt;&lt;/answer&gt;</FONT> <BR><FONT face="Courier New" size=2>&nbsp;&nbsp;&nbsp; &lt;answer correct="true"&gt;&lt;![CDATA[Personnel &gt; Access Groups]]&gt;&lt;/answer&gt;</FONT> <BR><FONT face="Courier New" size=2>&nbsp;&nbsp;&nbsp; &lt;answer correct="false"&gt;&lt;![CDATA[Libraries &gt; Financial Institution]]&gt;&lt;/answer&gt;</FONT> <BR><FONT face="Courier New" size=2>&nbsp; &lt;/question&gt;</FONT> <BR><FONT face="Courier New" size=2>&nbsp; </FONT><BR><FONT face="Courier New" size=2>&nbsp; &lt;question lesson="1"&gt;</FONT> <BR><FONT face="Courier New" size=2>&nbsp;&nbsp;&nbsp; &lt;prompt&gt;&lt;![CDATA[What telephone number would you call to inquire about interpreting certain language in a Truth-In-Savings Disclosure?]]&gt;&lt;/prompt&gt;</FONT></P>
<P><FONT face="Courier New" size=2>&nbsp;&nbsp;&nbsp; &lt;answer correct="false"&gt;&lt;![CDATA[Training Dept: 800-274-7255]]&gt;&lt;/answer&gt;</FONT> <BR><FONT face="Courier New" size=2>&nbsp;&nbsp;&nbsp; &lt;answer correct="false"&gt;&lt;![CDATA[Main HFS Line: 800-724-7280]]&gt;&lt;/answer&gt;</FONT> <BR><FONT face="Courier New" size=2>&nbsp;&nbsp;&nbsp; &lt;answer correct="true"&gt;&lt;![CDATA[Compliance Support: 800-274-7287]]&gt;&lt;/answer&gt;</FONT> <BR><FONT face="Courier New" size=2>&nbsp;&nbsp;&nbsp; &lt;answer correct="false"&gt;&lt;![CDATA[Sales: 800-274-7259]]&gt;&lt;/answer&gt;</FONT> <BR><FONT face="Courier New" size=2>&nbsp; &lt;/question&gt;</FONT> <BR><FONT face="Courier New" size=2>&nbsp; </FONT><BR><FONT face="Courier New" size=2>&nbsp; &lt;!-- Lesson 2 --&gt;</FONT> <BR><FONT face="Courier New" size=2>&nbsp; </FONT><BR><FONT face="Courier New" size=2>&nbsp; &lt;question lesson="2"&gt;</FONT> <BR><FONT face="Courier New" size=2>&nbsp;&nbsp;&nbsp; &lt;prompt&gt;&lt;![CDATA[Which menu item(s) on the DepositPro Admin menu allows you to set up your fee structure for Cashiers Checks?]]&gt;&lt;/prompt&gt;</FONT></P>
<P><FONT face="Courier New" size=2>&nbsp;&nbsp;&nbsp; &lt;answer correct="false"&gt;&lt;![CDATA[Use Setup &gt; Fees]]&gt;&lt;/answer&gt;</FONT> <BR><FONT face="Courier New" size=2>&nbsp;&nbsp;&nbsp; &lt;answer correct="true"&gt;&lt;![CDATA[Use Policies &gt; Policy Components]]&gt;&lt;/answer&gt;</FONT> <BR><FONT face="Courier New" size=2>&nbsp;&nbsp;&nbsp; &lt;answer correct="false"&gt;&lt;![CDATA[Use Products &gt; Update Fees]]&gt;&lt;/answer&gt;</FONT> <BR><FONT face="Courier New" size=2>&nbsp;&nbsp;&nbsp; &lt;answer correct="false"&gt;&lt;![CDATA[None of the Above]]&gt;&lt;/answer&gt;</FONT> <BR><FONT face="Courier New" size=2>&nbsp; &lt;/question&gt;</FONT> <BR><FONT face="Courier New" size=2>&nbsp;&nbsp;&nbsp; </FONT><BR><FONT face="Courier New" size=2>&nbsp; &lt;question lesson="2"&gt;</FONT> <BR><FONT face="Courier New" size=2>&nbsp;&nbsp;&nbsp; &lt;prompt&gt;&lt;![CDATA[How do you allow Options Other Than Those Listed for Marketing Categories and Funds Sources Library?]]&gt;&lt;/prompt&gt;</FONT></P>
<P><FONT face="Courier New" size=2>&nbsp;&nbsp;&nbsp; &lt;answer correct="false"&gt;&lt;![CDATA[Use an Edit Code of "Editable" on the drop-down list]]&gt;&lt;/answer&gt;</FONT> <BR><FONT face="Courier New" size=2>&nbsp;&nbsp;&nbsp; &lt;answer correct="true"&gt;&lt;![CDATA[Use the menu item Policies &gt; Marketing Categories and check the box labeled "During Transaction Processing, Allow Options Other Than Those Listed"]]&gt;&lt;/answer&gt;</FONT></P>
<P><FONT face="Courier New" size=2>&nbsp;&nbsp;&nbsp; &lt;answer correct="false"&gt;&lt;![CDATA[This is an editable field. You may include any option at any time.]]&gt;&lt;/answer&gt;</FONT> <BR><FONT face="Courier New" size=2>&nbsp;&nbsp;&nbsp; &lt;answer correct="false"&gt;&lt;![CDATA[None of the Above. Only listed options are allowed.]]&gt;&lt;/answer&gt;</FONT> <BR><FONT face="Courier New" size=2>&nbsp; &lt;/question&gt;</FONT> </P>
<P><FONT face="Courier New" size=2>&lt;/quiz&gt;</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 &lt; quizData.question.length; i++;) {</FONT> </P>
<P><FONT face="Courier New" color=#800000 size=2>&nbsp; if (quizData.question[i].lesson == '1') {</FONT> <BR><FONT face="Courier New" color=#800000 size=2>&nbsp; </FONT><BR><FONT face="Courier New" color=#800000 size=2>&nbsp;&nbsp;&nbsp; lesson1quiz[lesson1Counter].question = quizData.question[i];</FONT> <BR><FONT face="Courier New" color=#800000 size=2>&nbsp;&nbsp;&nbsp; lesson1Counter++;</FONT> </P>
<P><FONT face="Courier New" color=#800000 size=2>&nbsp; } // 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>&nbsp;Paul Swanson</FONT> <BR><FONT face="Courier New" color=#808080 size=2>&nbsp;Instructional Designer</FONT> <BR><FONT face="Courier New" color=#808080 size=2>&nbsp;Harland Financial Solutions</FONT> <BR><FONT face="Courier New" color=#808080 size=2>&nbsp;800.274.7280 Ext. 2462</FONT> <BR><FONT face="Courier New" color=#808080 size=2>&nbsp;Paul.Swanson@harlandfs.com</FONT> <BR><FONT face="Courier New" color=#808080 size=2>_____________________________</FONT> </P></DIV></BODY></HTML>