3 Replies Latest reply on Mar 31, 2008 7:31 AM by (soni)

    font styles in source xml are not set  on footnote text

      Hi,<br /><br />   could some please help. Not sure what iam missing.<br /><br />Iam using the following code to add footnote for each footnote element in imported xml. Iam running the script after importing xml. footnotes are added successfully but the font styles are not applied to the footnote text. The alerts in the code are as expected.<br /><br />Sample XML:<br /><para>This is begin</para><br /><para>Test footnote one follows<footnote id="f0"><para> FN1 This is<italic>italic</italic> and <bold>bold</bold>.</para><br /></footnote></para><br /><para>This is the second section</para><br /><para>Test footnote two follows<footnote id="f1"><para> FN2 This is<italic>italic</italic> and <bold>bold</bold>.<br /></footnote></para><br /><br />Code:<br /><br />var myGlueCodePath = app.filePath + "/Scripts/xml rules/glue code.jsx"; <br />var myFile = File(myGlueCodePath); <br />app.doScript(myFile); <br /><br />main(); <br />function main(){ <br />     var myDocument = app.activeDocument; <br />     if (app.documents.length != 0){ <br />          var myRuleSet = new Array ( <br />          new processParaBold, <br />          new processParaItalic <br />          ); <br />          with(myDocument){ <br />               var elements = xmlElements; <br />               __processRuleSet(elements.item(0), myRuleSet); <br />          } // End With <br />     } // end if <br />     else{ <br />          alert("No open document"); <br />     } // ende Else <br /><br />     var myXMLElements = new Array; <br />     myXMLElements = myGetXMLElements("//footnote"); <br /><br />     if(myXMLElements.length > 0){ <br />          for(var myCounter = 0; myCounter <= myXMLElements.length-1; myCounter++){ <br />               var myXMLElement = myXMLElements[myCounter]; <br />               var myStartIndex = myXMLElement.texts.item(0).insertionPoints.item(0).index; <br />               var myStory = myXMLElement.texts.item(0).parentStory; <br />               var myFootnoteString = myXMLElement.texts.item(0).contents; <br /><br />               myXMLElement.texts.item(0).contents = ""; <br />               var myInsertionPoint = myStory.insertionPoints.item(myStartIndex); <br /><br />               var myFootnote = myInsertionPoint.footnotes.add(); <br />               myFootnote.insertionPoints.item(-1).contents = myFootnoteString; <br />          } <br />     } <br />} <br /><br />function myGetXMLElements(myXPath){ <br />     var myXMLElements = new Array; <br />     var myRuleProcessor = app.xmlRuleProcessors.add([myXPath]); <br />     try{ <br />          var myMatchData = myRuleProcessor.startProcessingRuleSet(app.documents.item(0).xmlElements.item(0)); <br />          while(myMatchData != undefined){ <br />               var myElement = myMatchData.element; <br />               myXMLElements.push(myElement); <br />               myMatchData = myRuleProcessor.findNextMatch(); <br />          } <br />          myRuleProcessor.endProcessingRuleSet(); <br />          myRuleProcessor.remove(); <br />          return myXMLElements; <br />     } catch (myError){ <br />          myRuleProcessor.endProcessingRuleSet(); <br />          myRuleProcessor.remove(); <br />          throw myError; <br />     } <br />} <br /><br />function processParaBold(){ <br />     var myDocument = app.activeDocument; <br />     this.name = "processParaBold"; <br />     this.xpath = "//footnote/para/bold" <br />     this.apply = function(myElement, myRuleProcessor){ <br />          //myElement.texts[0].applyCharacterStyle(myDocument.characterStyles.item("bol d")); <br />          alert("test bold: " + myElement.texts.item(0).contents); <br />          var myCharacterStyle = myDocument.characterStyles.item("bold"); <br />          if(myCharacterStyle != null){ <br />               alert("bold exists"); <br />               myElement.texts.item(0).applyCharacterStyle(myCharacterStyle); <br />          } <br />          return false; <br />     } <br />} <br /><br />function processParaItalic(){ <br />     var myDocument = app.activeDocument; <br />     this.name = "processParaItalic"; <br />     this.xpath = "//footnote/para/italic" <br />     this.apply = function(myElement, myRuleProcessor){ <br />          //myElement.applyCharacterStyle(myDocument.characterStyles.item("italic")); <br />          alert("test italic: " + myElement.texts.item(0).contents); <br />          var myCharacterStyle = myDocument.characterStyles.item("italic"); <br />          if(myCharacterStyle != null){ <br />               alert("italic exists"); <br />               myElement.texts.item(0).applyCharacterStyle(myCharacterStyle); <br />          } <br />          return false; <br />     } <br />}<br /><br />Thanks