19 Replies Latest reply on Sep 11, 2009 4:00 AM by SB Masthan

    The styles with in footnote are not applied

      Hi,

      when adding footnote to indesign from xml, the contents method is not getting the tags with in footnote properly. After adding the footnote the underline and italic are applied to footnote, i check with alert as shown in Test code, the alert message is the text of the footnotes with square character in place of other tags.

      sample content:
      <footnote><para>Footnote with <underline>untext</underline> and <italic>italic</italic> </para></footnote>

      Test code:
      *********************
      function test(){
      var myXMLElements = new Array;
      var myRuleProcessor = app.xmlRuleProcessors.add([("//footnote"]);
      try{
      var myMatchData = myRuleProcessor.startProcessingRuleSet(app.documents.item(0).xmlElements.item(0));
      while(myMatchData != undefined){
      var myElement = myMatchData.element;
      myXMLElements.push(myElement);
      myMatchData = myRuleProcessor.findNextMatch();
      }
      myRuleProcessor.endProcessingRuleSet();
      myRuleProcessor.remove();
      return myXMLElements;
      }
      catch (myError){
      myRuleProcessor.endProcessingRuleSet();
      myRuleProcessor.remove();
      throw myError;
      }
      }

      function getContent(){
      var myXMLElements = new Array;
      myXMLElements = test();
      if(myXMLElements.length > 0){
      for(var myCounter = 0; myCounter <= myXMLElements.length-1; myCounter++){
      var myXMLElement = myXMLElements[myCounter];
      var myFootnoteString = myXMLElement.texts.item(0).contents;
      alert(myFootnoteString );

      }
      }
      }
      **********************************

      My next question is how can i remove the footnotes from indesign. I tried with the following code but i am getting error

      var myDocument = app.activeDocument;
      var ftcnt = 0;
      for(var s=1; s<myDocument.stories.count(); s++){
      var st = myDocument.stories[s];
      ftcnt = st.footnotes.count();
      for(var fn=1; fn<ftcnt; fn++){
      var myfn = st.footnotes[fn];
      myfn.remove();
      }
      }

      Thanks
        • 1. Re: The styles with in footnote are not applied
          srakete Level 1
          Soni, your variable for the alert with above script is: "Footnote with untext and italic". What do you expect it to be ?

          Stefan
          • 2. Re: The styles with in footnote are not applied
            Level 1
            Stefan,

            I expect it as "<para>Footnote with <underline>untext</underline> and <italic>italic</italic> </para>"

            So i think the style wil be applied automatically

            But the actual alert msg iam getting is

            "□Footnote with □untext□ and □italic□ □"

            thanks
            • 3. Re: The styles with in footnote are not applied
              Level 1
              Stefan,

              I tried manually appending <bold>bold string</bold> to the footstring.

              In indesin the footnote is displayed as
              Footnote with untext and italic <bold>bold string</bold>

              How can i get the footnote styles applied
              • 4. Re: The styles with in footnote are not applied
                Level 1
                Small correction to the second line in my orginal post

                After adding the footnote the underline and italic are not applied to footnote in indesign
                • 5. Re: The styles with in footnote are not applied
                  srakete Level 1
                  Hi Soni,

                  with your XML, I would a apply an XML rule for underline and one for italic.
                  Suppose you have a characterStyle named "underline" in your document.

                  function ProcessUnderline(){
                  this.name = "ProcessUnderline";
                  this.xpath = "//footnote/para/underline";
                  this.apply = function(myElement, myRuleProcessor){

                  myElement.applyCharacterStyle(myDocument.characterStyles.item("underline"));

                  return false;
                  }
                  }

                  Same with italic.
                  Hope this helps

                  Stefan Rakete
                  www.indesignscript.de
                  • 6. Re: The styles with in footnote are not applied
                    Level 1
                    Stefan,

                    In my test code where shall i call the processUnderline function
                    • 7. Re: The styles with in footnote are not applied
                      Level 1
                      Stefan,

                      I didn't understand from where i should call the above ProcessUnderline and how to pass myElement and myPuleProcessor. Could you please tell how shall use it. I need to apply nearly ten styles like that

                      thanks
                      • 8. Re: The styles with in footnote are not applied
                        srakete Level 1
                        Soni,

                        I would do it like this:

                        #include "glue code.jsx"
                        main();
                        function main(){
                        if (app.documents.length != 0){
                        var myDocument = app.documents.item(0);

                        var myRuleSet = new Array (
                        new processUnderline,
                        new processItalic,

                        );
                        with(myDocument){
                        var elements = xmlElements;
                        __processRuleSet(elements.item(0), myRuleSet);
                        } // Ende With
                        } // ende if
                        else{
                        alert("No open document");
                        } // ende Else

                        }

                        function processUnderline(){
                        this.name = "processUnderline";
                        this.xpath = "//footnote/para/underline";
                        this.apply = function(myElement, myRuleProcessor){

                        myElement.texts[0].underline = true;
                        //myElement.applyCharacterStyle(myDocument.characterStyles.item("underline"));

                        return false;
                        }
                        }

                        function processItalic(){
                        this.name = "processItalic";
                        this.xpath = "//footnote/para/italic";
                        this.apply = function(myElement, myRuleProcessor){

                        myElement.texts[0].fontStyle = "Italic";
                        //myElement.applyCharacterStyle(myDocument.characterStyles.item("italic"));

                        return false;
                        }
                        }

                        Stefan

                        http://www.indesignscript.de
                        • 9. Re: The styles with in footnote are not applied
                          Level 1
                          Stefan,

                          sorry, Iam confused, can i use the code as a part of my existing function (which is porecessing the footnote)
                          I tried by pasting
                          if (app.documents.length != 0){
                          var myDocument = app.documents.item(0);

                          var myRuleSet = new Array (
                          new processUnderline,
                          new processItalic,

                          );
                          with(myDocument){
                          var elements = xmlElements;
                          __processRuleSet(elements.item(0), myRuleSet);
                          } // Ende With
                          } // ende if
                          else{
                          alert("No open document");
                          } // ende Else

                          at the begining of my existing main function and the processUnderline and processItalic below my existing funtions.

                          when i try to execute the script it complained about glue code.jsx and i removed it and then it complained about __processRuleSet(elements.item(0), myRuleSet);
                          • 10. Re: The styles with in footnote are not applied
                            srakete Level 1
                            Soni,
                            replace the first line with the glueCode with this code:

                            var myGlueCodePath = app.filePath + "/Scripts/xml rules/glue code.jsx";
                            var myFile = File(myGlueCodePath);
                            app.doScript(myFile);

                            Stefan

                            http://www.indesignscript.de
                            • 11. Re: The styles with in footnote are not applied
                              Level 1
                              Stefan,

                              It didn't applied the styles there is no change

                              When i treid with either of the following, nothing changed
                              myElement.texts[0].applyCharacterStyle(myDocument.characterStyles.item("bold"));
                              or
                              myElement.applyCharacterStyle(myDocument.characterStyles.item("bold"));

                              When i tried with folowig line it gave me the error about bold.
                              myElement.texts[0].bold = true;

                              my document definetly had italic and bold charater styles in it.
                              • 12. Re: The styles with in footnote are not applied
                                Level 1
                                Stefan,

                                It didn't applied the styles there is no change

                                When i treid with either of the following, nothing changed
                                myElement.texts[0].applyCharacterStyle(myDocument.characterStyles.item("bold"));
                                or
                                myElement.applyCharacterStyle(myDocument.characterStyles.item("bold"));

                                When i tried with folowig line it gave me the error about bold.
                                myElement.texts[0].bold = true;

                                my document definetly had italic and bold charater styles in it.
                                • 13. Re: The styles with in footnote are not applied
                                  Level 1
                                  Stefan,

                                  I tried with
                                  myElement.texts[0].fontStyle = "Italic";

                                  but no use
                                  • 14. Re: The styles with in footnote are not applied
                                    Level 1
                                    Stefan,

                                    Here is my whole code in jsx, I didn't understand why the styles are not applied in footnote. all the alerts in code is displaying expected information

                                    --------------------

                                    var myGlueCodePath = app.filePath + "/Scripts/xml rules/glue code.jsx";
                                    var myFile = File(myGlueCodePath);
                                    app.doScript(myFile);

                                    main();
                                    function main(){
                                    var myDocument = app.activeDocument;
                                    if (app.documents.length != 0){
                                    var myRuleSet = new Array (
                                    new processParaBold,
                                    new processParaItalic
                                    );
                                    with(myDocument){
                                    var elements = xmlElements;
                                    __processRuleSet(elements.item(0), myRuleSet);
                                    } // End With
                                    } // end if
                                    else{
                                    alert("No open document");
                                    } // ende Else

                                    var myXMLElements = new Array;
                                    myXMLElements = myGetXMLElements("//footnote");

                                    if(myXMLElements.length > 0){
                                    for(var myCounter = 0; myCounter <= myXMLElements.length-1; myCounter++){
                                    var myXMLElement = myXMLElements[myCounter];
                                    var myStartIndex = myXMLElement.texts.item(0).insertionPoints.item(0).index;
                                    var myStory = myXMLElement.texts.item(0).parentStory;
                                    var myFootnoteString = myXMLElement.texts.item(0).contents;

                                    myXMLElement.texts.item(0).contents = "";
                                    var myInsertionPoint = myStory.insertionPoints.item(myStartIndex);

                                    var myFootnote = myInsertionPoint.footnotes.add();
                                    myFootnote.insertionPoints.item(-1).contents = myFootnoteString;

                                    }
                                    }
                                    }

                                    function myGetXMLElements(myXPath){
                                    var myXMLElements = new Array;
                                    var myRuleProcessor = app.xmlRuleProcessors.add([myXPath]);
                                    try{
                                    var myMatchData = myRuleProcessor.startProcessingRuleSet(app.documents.item(0).xmlElements.item(0));
                                    while(myMatchData != undefined){
                                    var myElement = myMatchData.element;
                                    myXMLElements.push(myElement);
                                    myMatchData = myRuleProcessor.findNextMatch();
                                    }
                                    myRuleProcessor.endProcessingRuleSet();
                                    myRuleProcessor.remove();
                                    return myXMLElements;
                                    }
                                    catch (myError){
                                    myRuleProcessor.endProcessingRuleSet();
                                    myRuleProcessor.remove();
                                    throw myError;
                                    }
                                    }

                                    function processParaBold(){
                                    var myDocument = app.activeDocument;
                                    this.name = "processParaBold";
                                    this.xpath = "//footnote/para/bold"
                                    this.apply = function(myElement, myRuleProcessor){
                                    //myElement.texts[0].applyCharacterStyle(myDocument.characterStyles.item("bold"));
                                    alert("test bold: " + myElement.texts.item(0).contents);
                                    var myCharacterStyle = myDocument.characterStyles.item("bold");
                                    if(myCharacterStyle != null){
                                    alert("bold exists");
                                    myElement.texts.item(0).applyCharacterStyle(myCharacterStyle);
                                    }

                                    //myElement.texts.item(0).applyCharacterStyle(myDocument.characterStyles.item("bold"));
                                    //myElement.texts[0].fontStyle = "Bold";
                                    return false;
                                    }
                                    }

                                    function processParaItalic(){
                                    var myDocument = app.activeDocument;
                                    this.name = "processParaItalic";
                                    this.xpath = "//footnote/para/italic"
                                    this.apply = function(myElement, myRuleProcessor){
                                    //myElement.applyCharacterStyle(myDocument.characterStyles.item("italic"));
                                    alert("test italic: " + myElement.texts.item(0).contents);
                                    var myCharacterStyle = myDocument.characterStyles.item("italic");
                                    if(myCharacterStyle != null){
                                    alert("italic exists");
                                    myElement.texts.item(0).applyCharacterStyle(myCharacterStyle);
                                    }

                                    return false;
                                    }
                                    }

                                    -------------------
                                    • 15. Re: The styles with in footnote are not applied
                                      srakete Level 1
                                      Soni,
                                      have you tried only the script that I posted. Works fine for me.
                                      What are you trying to do with myGetXMLElements() ?
                                      That part is deleting xml Elements in the InDesign structure.

                                      Stefan
                                      • 16. Re: The styles with in footnote are not applied
                                        Level 1
                                        Stefan,

                                        Sorry for the delay, getXMLElement returns all the footnote elements. So iam looping through that arry and adding footnotes as shown in my code
                                        • 17. Re: The styles with in footnote are not applied
                                          Level 1
                                          Stefan how didit worked for you how are you adding footnotes
                                          • 18. Re: The styles with in footnote are not applied
                                            Level 1
                                            Stefan,

                                            i didn't understand which you saying about deleting xml Elements in indesign strucutre.
                                            How can i test only your script, as i need the styles working in footnote. Could you please tell me how you aading the footnote to indesign. Its not working for me.
                                            When i import the xml, the styles of the content of footnote elements are displayed fine. But once i run the script (which will add the footnote by looping to footnote elements) the content of the footnote element is made as footnote but lost all the styles with in the content.

                                            You can see my code in my previous message.

                                            Thanks
                                            • 19. Re: The styles with in footnote are not applied
                                              SB Masthan

                                              Hi Soni or Stefan,

                                               

                                              I am also in the trouble with footnote font styles missing.  If you get the solution, kindly help me.

                                               

                                              regards

                                              Masthan