<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML dir=ltr><HEAD><TITLE>Having problems duplicating nodes</TITLE>
<META http-equiv=Content-Type content="text/html; charset=us-ascii">
<META content="MSHTML 6.00.6000.16735" name=GENERATOR></HEAD>
<BODY>
<DIV dir=ltr align=left><FONT face=Verdana color=#0000ff size=2><SPAN
class=228424621-03122008>Well, apparently I was. I had the duplicate code in the
entry frame of lesson 1, so I guess it was executing each time I moved from page
to page in lesson 1? I moved the code to just above the interface icon (so it
can only run once), made the necessary changes to the childNodes structure, and
it was still acting funny. I then found that I had both a variable and an icon
id of 'lesson1Counter' so it's no wonder it was acting inconsistently. ;o)
I fixed that and now I'm consistently getting the correct number of question
nodes.</SPAN></FONT></DIV>
<DIV dir=ltr align=left><FONT face=Verdana color=#0000ff size=2><SPAN
class=228424621-03122008></SPAN></FONT> </DIV>
<DIV dir=ltr align=left><FONT face=Verdana color=#0000ff size=2><SPAN
class=228424621-03122008>I still have one problem though: it only displays one
question. When I get to the first question node, it displays the question
correctly, the second node displays the same question, and if I back up to the
first question node, it's blank. Here is the code where I get the question
number:</SPAN></FONT></DIV>
<DIV dir=ltr align=left><FONT face=Verdana color=#0000ff size=2><SPAN
class=228424621-03122008></SPAN></FONT> </DIV>
<DIV dir=ltr align=left><FONT face="Courier New" color=#0000ff size=2><SPAN
class=228424621-03122008>questIndex = icon.parentNode.index() -
1;</SPAN></FONT></DIV>
<DIV dir=ltr align=left><FONT face=Verdana color=#0000ff size=2><SPAN
class=228424621-03122008></SPAN></FONT> </DIV>
<DIV dir=ltr align=left><FONT face=Verdana color=#0000ff size=2><SPAN
class=228424621-03122008>The script icon with this code is the first icon in the
proto Wrap Up page (what I was calling the question node above), and the proto
Wrap Up page is the second child of the wrap up framework (the Entry
Frame being the first child), so questIndex should be 0 for the first question,
and 1 for the next, right? I'm using questIndex+1 for a page counter, and that
is correctly displaying 1 for question 1 and 2 for question 2, but the questions
don't change. Any insight on that?</SPAN></FONT></DIV>
<DIV dir=ltr align=left><FONT face=Verdana color=#0000ff size=2><SPAN
class=228424621-03122008></SPAN></FONT> </DIV>
<DIV dir=ltr align=left><FONT face=Verdana color=#0000ff size=2><SPAN
class=228424621-03122008>Thanks for all your help!</SPAN></FONT></DIV>
<DIV dir=ltr align=left><FONT face=Verdana color=#0000ff size=2><SPAN
class=228424621-03122008></SPAN></FONT> </DIV>
<DIV dir=ltr align=left><FONT face=Verdana color=#0000ff size=2><SPAN
class=228424621-03122008>P</SPAN></FONT></DIV><BR>
<BLOCKQUOTE dir=ltr
style="PADDING-LEFT: 5px; MARGIN-LEFT: 5px; BORDER-LEFT: #0000ff 2px solid; MARGIN-RIGHT: 0px">
<DIV class=OutlookMessageHeader lang=en-us dir=ltr align=left>
<HR tabIndex=-1>
<FONT face=Tahoma size=2><B>From:</B> xerte-bounces@lists.nottingham.ac.uk
[mailto:xerte-bounces@lists.nottingham.ac.uk] <B>On Behalf Of </B>Julian
Tenney<BR><B>Sent:</B> Wednesday, December 03, 2008 12:45 PM<BR><B>To:</B>
Xerte discussion list<BR><B>Subject:</B> RE: [Xerte] Having problems
duplicating nodes<BR></FONT><BR></DIV>
<DIV></DIV>
<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><FONT face=Verdana color=#0000ff
size=2></FONT> </DIV></BLOCKQUOTE></BODY></HTML>