29 Replies Latest reply on Mar 10, 2011 7:51 PM by Mac_06

    How to shift content with in cell in xml rules table

    Mac_06 Level 2

      Hi all scripters,

       

      I've created a table using xml rules with 3 nos of cells where first cell contain some data and so on but in next row first cell may of may not contain any data so in that row second cell data shifted to first cell and thired row data shifted to second cell which is very anxious for me since second cell data in each row should be in second cell only.

       

      For Instance-: Required output

       

      TitlePageNoSubject
      Title46The Subject
      50Another Subject
      54Subject
      Title60Another Subject
      64The subject

       

       

      The out put I am getting by script-:

       

      TitlePageNoSubject
      Title46The Subject
      50Another Subject
      54Subject
      Title60Another Subject
      64The subject

      myRuleSet = new Array ( new ProcessSec,
                 new ProcessPara,
                 new ProcessSecHead,
                 new ProcessArt,
                 new ProcessPG,
                 );
      with(myDocument){
          var elements = xmlElements;
           __processRuleSet(elements.item(0), myRuleSet);
            } 
      
      function ProcessSecHead(myXPath){
          this.name = "ProcessSecHead";
          this.xpath = myXPath; 
          this.apply = function(myElement, myRuleProcessor){
         with(myElement){
                  __skipChildren(myRuleProcessor);
                    var myNewElement = myContainerElement.xmlElements.item(-1).xmlElements.add(app.documents.item(0).xmlTags.item("Cell"));
           myElement.move(LocationOptions.atBeginning, myContainerElement.xmlElements.item(-1).xmlElements.item(-1));
           }
          return true;
          }  
      }
      function ProcessPara(){
          this.name = "ProcessPara";
          this.xpath = "//para"; 
          this.apply = function(myElement, myRuleProcessor){
                  var myNewElement = myContainerElement.xmlElements.add(app.documents.item(0).xmlTags.item("Row"));
              return true;
          }  
      }
      
      function ProcessArt(){
          this.name = "ProcessArt";
          this.xpath = "//para/aug"; 
          this.apply = function(myElement, myRuleProcessor){
              with(myElement){
                  __processChildren(myRuleProcessor);
                  var myNewElement = myContainerElement.xmlElements.item(-1).xmlElements.add(app.documents.item(0).xmlTags.item("Cell"));
                  myElement.move(LocationOptions.atBeginning, myNewElement);   
              }
              return true;
          }  
      }
      function ProcessPG(myXPath){
          this.name = "ProcessPG";
          this.xpath = myXPath; 
          this.apply = function(myElement, myRuleProcessor){
              with(myElement){
                  __skipChildren(myRuleProcessor);
                  var myNewElement = myContainerElement.xmlElements.item(-1).xmlElements.add(app.documents.item(0).xmlTags.item("Cell"));
                  myElement.move(LocationOptions.atBeginning, myNewElement);
              }
              return true;
          }  
      }
      

       

       

      Any would be greatly appreciated

       

      Mac

        • 1. Re: How to shift content with in cell in xml rules table
          John Hawkinson Level 5

          Well.

           

          I don't think this is a very good method to use. It's certainly true that the CS5 scripting guide gives some examples

          that sort of look like this for table conversions, but...I don't think this is really a good way to code it.

           

          Can you please supply some example XML that you are using as input? That would help a lot.

           

          Also, the script you pasted in is not complete. For instance, we never see the definition of myContainerElement. I could guess that it's just like the one in the XMLRulesTable.jsx, but maybe not? That's different from the CS5 Scripting Guide's definition. So right now it's not possible to run your script and see the output and make suggestions. That makes it nearly impossible to help you.

           

          I can't help thinking you would be better off using XSLT to translate your XML into standard <TABLE><TR><TD/></TR></TABLE>  markup and then just importing it into InDesign. Or perhaps translating it into <Row><Cell/></Row>  since that's what convertElementToTable seems to be fond of.

           

          So anyhow, give us a bit more information. But I just doubt this is the easiest way. Where's your data coming from, anyhow?

          • 2. Re: How to shift content with in cell in xml rules table
            Jeremy bowmangraphics Level 2

            I agree with most of what John said.

             

            In my opinion, XML and tables are about as well-matched as HTML and tables, which is to say "not much". I've often wondered why so many questions are asked about XML and tables in these forums. Sometimes I think: "these XML jockeys are amazing with their tables and all". Other times I think: "no wonder there are so many questions asked about XML and tables -- together they're bound to run into trouble".

             

            If your initial XML is not in table form, but you definitely want your final document to contain tables, you might import the XML with tabs and paragraph returns added in the appropriate places, and apply character style (using XML rules to do both), then afterwards "convert text to table". Converting text to table untags the contents of cells, so if you have already applied character styles to these contents, you retain control over them.

             

            If it is in table form, I'd try something with XSLT instead of XML rules.

             

            Jeremy

            • 3. Re: How to shift content with in cell in xml rules table
              Mac_06 Level 2

              Thanks, both of you for reply,

               

              Yeh.... This is obvious thinking while you see this table at a glance that it could be far better to process this by XSLT instead of Xml Rules but I first had taken a look over the XSLT approach but there were some technical cons which got hurdle with.

               

              Since there are several layout should have been handled by single script, given one is one of them and now I could not switch my approach because the script had been go live in production and client is satisfy with, except this kind of layout all other are working as desired.

               

              Have a look of xml-:

               

              <Sec>

                   <sh>Title</sh>

                   <p>

                        <sub>TheSubject<sub>

                        <page>46</page>

                   </p>

                   <p>

                        <sub>Another Subject<sub>

                        <page>50</page>

                   </p>

                   <p>

                        <sub>Subject<sub>

                        <page>54</page>

                   </p>

                   <sh>Title</sh>

                   <p>

                        <sub>Another Subject<sub>

                        <page>60</page>

                   </p>

                   <p>

                        <sub>The Subject<sub>

                        <page>64</page>

                   </p>

              </Sec>

               

              In above xml code first I am moving <sh> into <p> tag and afterwords <p> tag is converted to row and other are as a Cell.

               

              Yes, You are correct John, this idea is typically borrowed from xmlRulesTable.jsx and you could pick myContainerElement from said .jsx file from CS4 scripting

              myContainerElement = myVCOElement.xmlElements.add(myMarkupTag);

               

              Mac

              • 4. Re: How to shift content with in cell in xml rules table
                John Hawkinson Level 5

                Sorry, I am still confused.

                 

                Can you please post the entire script you would like us to debug for you?

                 

                I see your script makes reference to myXPath in a few cases -- what is that? More problematic, you also have "//para" and "//para/aug" but your sample XML doesn't have <para/> or <aug/> tags! You have <p>, <sub>, and <page> tags. How could that possibly work?

                 

                Moving the <sh/> tag into the <p> tag sounds fine. All you need to do is make sure that after you do that, you loop through and add an empty <sh/> tag if there isn't one already. That sounds easy enough, no?

                 

                Thanks!

                • 5. Re: How to shift content with in cell in xml rules table
                  Mac_06 Level 2

                  Sorry for ambiguity caused,

                   

                  Ignore previous one xml code, here is the live sample xml code also notice that xml file is supplied by client so we could not modify it.-:

                   

                  <section>
                   <section-head>Special Section on Offshore wind power planning, economics and environment</section-head>
                   <section-subhead/>
                   <para>
                    <aug>
                    <author>D. John</author>
                    </aug>
                    <article>Special issue on offshore wind power</article>
                    <page>495</page>
                   </para>
                   <para>
                    <aug>
                    <author>R. Smith</author> and <author>N. Vasil</author>
                    </aug>
                    <article>The economics of offshore wind</article>
                    <page>496</page>
                   </para>
                  </section>
                  <section>
                   <section-head>Special Section on Offshore wind power planning, economics and environment</section-head>
                   <section-subhead/>
                   <para>
                    <aug>
                    <author>C. Smith</author>
                    </aug>
                    <article>Understanding public responses to offshore wind power</article>
                    <page>503</page>
                   </para>
                   <para>
                    <aug>
                    <author>B. M&ouml;ller</author>
                    </aug>
                    <article>Continuous spatial modelling to analyse planning and economic consequences of offshore wind energy</article>
                    <page>511</page>
                   </para>
                   <para>
                    <aug>
                    <author>P. S&ouml;derholm</author> and <author>M. Pettersson</author>
                    </aug>
                    <article>Offshore wind power policy and planning in Sweden</article>
                    <page>518</page>
                   </para>
                    <para>
                    <aug>
                    <author>D. Toke</author>
                    </aug>
                    <article>The UK offshore wind power programme: A sea-change in UK energy policy?</article>
                    <page>526</page>
                   </para>
                  </section>
                  
                  


                  Hope this will let you understand my problem closly and would got any way to overcome.


                  Please let me know if still something would be ambiguous.

                   

                  Mac

                  • 6. Re: How to shift content with in cell in xml rules table
                    John Hawkinson Level 5

                    Thanks for posting the XML you need to process. That's a necessary component.

                     

                    But again: Can you please post the entire script you would like us to debug for you?

                     

                    Thank you!

                    • 7. Re: How to shift content with in cell in xml rules table
                      Mac_06 Level 2

                      Hi John,

                       

                      Sorry for keeping you unknown from live script, so please have a look below working code of script-:

                       

                      if(app.documents.length<1){
                         alert ("Open a document and run the Script")
                        }
                       
                       var myDocument = app.activeDocument;
                       var myPage = myDocument.pages.item(0);
                       var myRoot = myDocument.xmlElements.item(0);
                       try{   
                         var myTableTag = myDocument.xmlTags.add("Table")
                        }
                       catch(ex){}
                       
                        
                       myDocument.xmlImportPreferences.allowTransform = false;
                       myDocument.xmlImportPreferences.ignoreWhitespace = true;
                       var myScriptPath = myGetScriptPath();
                       var myFilePath = myScriptPath.path + "/myXml.xml"
                       app.scriptPreferences.userInteractionLevel = UserInteractionLevels.NEVER_INTERACT
                       myDocument.importXML(File(myFilePath));
                       app.scriptPreferences.userInteractionLevel = UserInteractionLevels.INTERACT_WITH_ALL
                       var myBounds = myGetBounds(myDocument, myDocument.pages.item(0));
                       myDocument.xmlElements.item(0).placeIntoFrame(myDocument.pages.item(0), myBounds);
                       
                       try{
                        myPage.textFrames.item(0).remove();
                       }
                       catch(myError){}
                       
                       var myScriptPath = myGetScriptPath();
                       var myRowTag = myDocument.xmlTags.add("Row");
                       var myColumnTag = myDocument.xmlTags.add("Column");
                       
                       var myVCOElement = myDocument.xmlElements.item(0).xmlElements.add(myMarkupTag);
                       
                       myContainerElement = myVCOElement.xmlElements.add("Table");
                       
                       var myRuleSet = new Array (new MoveToSibling("/sections/section/section-head"),
                                 new MoveElement("/sections/section/para/page", "aug"), 
                                 new (MoveArticleBeforeAug));
                                 
                       with(myDocument){
                             var elements = xmlElements;
                             __processRuleSet(elements.item(0), myRuleSet);
                              }
                             
                       var myMainFrame = myDocument.xmlElements.item(0).placeIntoFrame(myDocument.pages.item(0), myFrameBounds);
                       myMainFrame.remove(); 
                       
                       myRuleSet = new Array ( new ProcessPara,
                                new ProcessSectionHead,
                                new ProcessAug,
                                new ProcessPage,
                                );
                                 
                       with(myDocument){
                          var elements = xmlElements;
                           __processRuleSet(elements.item(0), myRuleSet);
                            } 
                           
                       var myTable = myContainerElement.convertElementToTable(myRowTag, myColumnTag);
                       
                       myTable.width = myFrameBounds[3]-myFrameBounds[1];
                       var myTableFrame = myVCOElement.placeIntoFrame(myPage, myFrameBounds);
                       
                       function MoveToSibling(myXpath){
                          this.name = "MoveToSibling";
                          this.xpath = myXpath; 
                          this.apply = function(myElement, myRuleProcessor){
                                      __skipChildren(myRuleProcessor);    
                           myElement.move(LocationOptions.before, myElement.parent.xmlElements.item(2).xmlElements.item("aug"));     
                              return false;
                          } 
                      }
                      function MoveArticleBeforeAug(){
                          this.name = "MoveArticleBeforeAug";
                          this.xpath = "/sections/section/para/article"; 
                          this.apply = function(myElement, myRuleProcessor){
                                      __skipChildren(myRuleProcessor);
                              myElement.move(LocationOptions.before, myElement.parent.xmlElements.item("aug").xmlElements.item(0));
                              return false;
                          } 
                      }
                      function MoveElement(myXpath, myMove){
                          this.name = "MoveElement";
                          this.xpath = myXpath; 
                          this.apply = function(myElement, myRuleProcessor){
                                      __skipChildren(myRuleProcessor);
                              myElement.move(LocationOptions.before, myElement.parent.xmlElements.item(myMove));
                              return false;
                          } 
                      }
                      function ProcessSectionHead(){
                          this.name = "ProcessSectionHead";
                          this.xpath = "//section/*/section-head"; 
                          this.apply = function(myElement, myRuleProcessor){
                         with(myElement){
                                  __skipChildren(myRuleProcessor);
                                    var myNewElement = myContainerElement.xmlElements.item(-1).xmlElements.add(app.documents.item(0).xmlTags.item("Cell"));
                           myElement.move(LocationOptions.atBeginning, myContainerElement.xmlElements.item(-1).xmlElements.item(-1));
                           }
                          return true;
                          }  
                      }
                      function ProcessPara(){
                          this.name = "ProcessPara";
                          this.xpath = "//para"; 
                          this.apply = function(myElement, myRuleProcessor){
                                  var myNewElement = myContainerElement.xmlElements.add(app.documents.item(0).xmlTags.item("Row"));
                              return true;
                          }  
                      }
                      function ProcessAug(){
                          this.name = "ProcessAug";
                          this.xpath = "//para/aug"; 
                          this.apply = function(myElement, myRuleProcessor){
                              with(myElement){
                                  __processChildren(myRuleProcessor);
                                  var myNewElement = myContainerElement.xmlElements.item(-1).xmlElements.add(app.documents.item(0).xmlTags.item("Cell"));
                                  myElement.move(LocationOptions.atBeginning, myNewElement);   
                              }
                              return true;
                          }  
                      }
                      function ProcessPage(){
                          this.name = "ProcessPage";
                          this.xpath = "//para/page"; 
                          this.apply = function(myElement, myRuleProcessor){
                              with(myElement){
                                  __skipChildren(myRuleProcessor);
                                  var myNewElement = myContainerElement.xmlElements.item(-1).xmlElements.add(app.documents.item(0).xmlTags.item("Cell"));
                                  myElement.move(LocationOptions.atBeginning, myNewElement);
                              }
                              return true;
                          }  
                      }
                      
                      function myGetBounds(myDocument, myPage){
                          var myPageWidth = myDocument.documentPreferences.pageWidth;
                          var myPageHeight = myDocument.documentPreferences.pageHeight;
                          if(myPage.side == PageSideOptions.leftHand){
                              var myX2 = myPage.marginPreferences.left;
                              var myX1 = myPage.marginPreferences.right;
                          }
                          else{
                              var myX1 = myPage.marginPreferences.left;
                              var myX2 = myPage.marginPreferences.right;
                          }
                          var myY1 = myPage.marginPreferences.top;
                          var myX2 = myPageWidth - myX2;
                          var myY2 = myPageHeight - myPage.marginPreferences.bottom;
                          return [myY1, myX1, myY2, myX2];
                      }
                      function myGetScriptPath() {
                          try {
                              return app.activeScript;
                          }
                          catch(myError){
                              return File(myError.fileName);
                          }
                      }
                      

                       

                      Hope now you could understand full requirement.

                       

                      Mac

                      • 8. Re: How to shift content with in cell in xml rules table
                        John Hawkinson Level 5

                        By the way, what OS are you using? Mac or PC or both?    


                        • 9. Re: How to shift content with in cell in xml rules table
                          Mac_06 Level 2

                          I am on Windows XP using InDesign CS4.

                           

                          Mac

                          • 10. Re: How to shift content with in cell in xml rules table
                            John Hawkinson Level 5

                            So, this is somewhat frustrating for me, because it looks like a lot of glue is still missing to even be able to replicate your failure. Did you actually test what you post?

                             

                            Your XML doesn't import into InDesign.  It appears to fail for two reasons. Firstly, it doesn't have an outer tag around everything. Like <Root>. Secondly, it contains HTML entity codes like &ouml; without a corresponding DOCTYPE or ENTITY declaration. I'm not sure what the right way to fix those is -- but I'm sure if you actually included the XML header for your file, then it might work? So it's really frustrating.

                             

                            Next, your script doesn't work, and couldn't work. Line 33 references a myMarkupTag variable that doesn't exist.

                            So obviously this isn't the complete script.

                             

                            Please give us what we need to replicate your problem.

                             

                            I'm sorry if I come off as rude. You have made it difficult to even attempt to help you, and we haven't gotten anywhere near the core issues.

                            • 11. Re: How to shift content with in cell in xml rules table
                              Mac_06 Level 2

                              Hi John,

                               

                              I am really appologies for getting back late and post some ambiguous script since this script is too big and also includes lots of other stuffs which are releated to other task the extracting of useable code is quite tuff Nevertheless now see the working one.

                               

                              Also please add <sections> as Root tag in provided xml code and remove entity reference &ouml; since it hard to paste our DTD here.

                               

                              Include glue code.jsx provided by adobe CS4 JS

                               

                              #include "glue code.jsx";
                              if(app.documents.length<1){
                                 alert ("Open a document and run the Script")
                                }
                               
                               var myDocument = app.activeDocument;
                               var myPage = myDocument.pages.item(0);
                               var myRoot = myDocument.xmlElements.item(0);
                               try{   
                                 var myTableTag = myDocument.xmlTags.add("Table")
                                }
                               catch(ex){}
                               
                                
                               myDocument.xmlImportPreferences.allowTransform = false;
                               myDocument.xmlImportPreferences.ignoreWhitespace = true;
                               var myScriptPath = myGetScriptPath();
                               var myFilePath = myScriptPath.path + "/temp.xml"
                               app.scriptPreferences.userInteractionLevel = UserInteractionLevels.NEVER_INTERACT
                               myDocument.importXML(File(myFilePath));
                               app.scriptPreferences.userInteractionLevel = UserInteractionLevels.INTERACT_WITH_ALL
                               var myBounds = myGetBounds(myDocument, myDocument.pages.item(0));
                               myDocument.xmlElements.item(0).placeIntoFrame(myDocument.pages.item(0), myBounds);
                               
                               try{
                                myPage.textFrames.item(0).remove();
                               }
                               catch(myError){}
                               
                               //var myScriptPath = myGetScriptPath();
                               
                               
                               var myRuleSet = new Array (new MoveToSibling("/sections/section/section-head"),
                                         new MoveElement("/sections/section/para/page", "aug"), 
                                         new (MoveArticleBeforeAug));
                                         
                               with(myDocument){
                                     var elements = xmlElements;
                                     __processRuleSet(elements.item(0), myRuleSet);
                                      }
                                     
                               var myMainFrame = myDocument.xmlElements.item(0).placeIntoFrame(myDocument.pages.item(0), myBounds);
                               myMainFrame.remove(); 
                               
                               try{
                               var myRowTag = myDocument.xmlTags.add("Row");
                               }
                              catch(e){};
                              try{
                               var myColumnTag = myDocument.xmlTags.add("Column");
                               }
                              catch(e){};
                              try{
                              var myAddStoryTag = myDocument.xmlTags.add("Story");
                               }
                              catch(e){};
                              var myRowTag = myDocument.xmlTags.item("Row");
                               var myColumnTag = myDocument.xmlTags.item("Cell");
                               var myMarkupTag = myDocument.xmlTags.item("Story");
                               
                              var myVCOElement = myDocument.xmlElements.item(0).xmlElements.add(myMarkupTag);
                               
                               myContainerElement = myVCOElement.xmlElements.add("Table");
                               
                               var myRuleSet = new Array ( new ProcessSectionData,
                                 new ProcessPara,
                                        new ProcessSectionHead,
                                        new ProcessAug,
                                        new ProcessPage,
                                        );
                                         
                               with(myDocument){
                                  var elements = xmlElements;
                                   __processRuleSet(elements.item(0), myRuleSet);
                                    } 
                                   
                               var myTable = myContainerElement.convertElementToTable(myRowTag, myColumnTag);
                               
                               //myTable.width = myFrameBounds[3]-myFrameBounds[1];
                               var myTableFrame = myVCOElement.placeIntoFrame(myPage, myBounds);
                               
                               function MoveToSibling(myXpath){
                                  this.name = "MoveToSibling";
                                  this.xpath = myXpath; 
                                  this.apply = function(myElement, myRuleProcessor){
                                              __skipChildren(myRuleProcessor);    
                                   myElement.move(LocationOptions.before, myElement.parent.xmlElements.item(2).xmlElements.item("aug"));     
                                      return false;
                                  } 
                              }
                              function MoveArticleBeforeAug(){
                                  this.name = "MoveArticleBeforeAug";
                                  this.xpath = "/sections/section/para/article"; 
                                  this.apply = function(myElement, myRuleProcessor){
                                              __skipChildren(myRuleProcessor);
                                      myElement.move(LocationOptions.before, myElement.parent.xmlElements.item("aug").xmlElements.item(0));
                                      return false;
                                  } 
                              }
                              function MoveElement(myXpath, myMove){
                                  this.name = "MoveElement";
                                  this.xpath = myXpath; 
                                  this.apply = function(myElement, myRuleProcessor){
                                              __skipChildren(myRuleProcessor);
                                      myElement.move(LocationOptions.before, myElement.parent.xmlElements.item(myMove));
                                      return false;
                                  } 
                              }
                              function ProcessSectionData(){
                                  this.name = "ProcessSectionData";
                                  this.xpath = "//section"; 
                                  this.apply = function(myElement, myRuleProcessor){  
                                         var myNewElement = myContainerElement.xmlElements.add(app.documents.item(0).xmlTags.item("Row"));
                                return false;
                                  }  
                              }
                              function ProcessSectionHead(){
                                  this.name = "ProcessSectionHead";
                                  this.xpath = "//section/*/section-head"; 
                                  this.apply = function(myElement, myRuleProcessor){
                                 with(myElement){
                                          __skipChildren(myRuleProcessor);
                                            var myNewElement = myContainerElement.xmlElements.item(-1).xmlElements.add(app.documents.item(0).xmlTags.item("Cell"));
                                   myElement.move(LocationOptions.atBeginning, myContainerElement.xmlElements.item(-1).xmlElements.item(-1));
                                   }
                                  return true;
                                  }  
                              }
                              function ProcessPara(){
                                  this.name = "ProcessPara";
                                  this.xpath = "//para"; 
                                  this.apply = function(myElement, myRuleProcessor){
                                          var myNewElement = myContainerElement.xmlElements.add(app.documents.item(0).xmlTags.item("Row"));
                                      return true;
                                  }  
                              }
                              function ProcessAug(){
                                  this.name = "ProcessAug";
                                  this.xpath = "//para/aug"; 
                                  this.apply = function(myElement, myRuleProcessor){
                                      with(myElement){
                                          __processChildren(myRuleProcessor);
                                          var myNewElement = myContainerElement.xmlElements.item(-1).xmlElements.add(app.documents.item(0).xmlTags.item("Cell"));
                                          myElement.move(LocationOptions.atBeginning, myNewElement);   
                                      }
                                      return true;
                                  }  
                              }
                              function ProcessPage(){
                                  this.name = "ProcessPage";
                                  this.xpath = "//para/page"; 
                                  this.apply = function(myElement, myRuleProcessor){
                                      with(myElement){
                                          __skipChildren(myRuleProcessor);
                                          var myNewElement = myContainerElement.xmlElements.item(-1).xmlElements.add(app.documents.item(0).xmlTags.item("Cell"));
                                          myElement.move(LocationOptions.atBeginning, myNewElement);
                                      }
                                      return true;
                                  }  
                              }
                               
                              function myGetBounds(myDocument, myPage){
                                  var myPageWidth = myDocument.documentPreferences.pageWidth;
                                  var myPageHeight = myDocument.documentPreferences.pageHeight;
                                  if(myPage.side == PageSideOptions.leftHand){
                                      var myX2 = myPage.marginPreferences.left;
                                      var myX1 = myPage.marginPreferences.right;
                                  }
                                  else{
                                      var myX1 = myPage.marginPreferences.left;
                                      var myX2 = myPage.marginPreferences.right;
                                  }
                                  var myY1 = myPage.marginPreferences.top;
                                  var myX2 = myPageWidth - myX2;
                                  var myY2 = myPageHeight - myPage.marginPreferences.bottom;
                                  return [myY1, myX1, myY2, myX2];
                              }
                              function myGetScriptPath() {
                                  try {
                                      return app.activeScript;
                                  }
                                  catch(myError){
                                      return File(myError.fileName);
                                  }
                              }
                              

                               

                               

                              Looking forward with your solution.
                              Mac

                              • 12. Re: How to shift content with in cell in xml rules table
                                John Hawkinson Level 5

                                Wow, sorry. I didn't have much time for this stuff today.

                                 

                                > Also please add <sections> as Root tag in provided xml code and  remove entity reference &ouml; since it hard to paste our DTD here.

                                 

                                What?

                                 

                                Do you mean

                                 

                                <Root>
                                <section>
                                 <section-head>...</section-head>
                                 ...
                                </section>
                                ...
                                </Root>
                                

                                 

                                Because if that's what you mean, that imports the XML fine, but the script complains because there is no XML rule associated with the Root node.

                                 

                                If you mean replace the <section> tags with <root> tags, I don't see how that could possibly work, since an XML document needs to be wrapped in a single outer node.

                                 

                                If you mean something else alltogether, well, I'm having trouble guessing what it is...

                                 

                                 

                                • 13. Re: How to shift content with in cell in xml rules table
                                  Mac_06 Level 2

                                  It should be like this-:

                                   

                                  <sections>
                                  <section>
                                   <section-head>...</section-head>
                                   ...
                                  </section>
                                  ...
                                  </sections>
                                  
                                  

                                   

                                  Mac

                                  • 14. Re: How to shift content with in cell in xml rules table
                                    Mac_06 Level 2

                                    see the complete xml code-:

                                     

                                     

                                    <sections>
                                    <section>
                                     <section-head>Special Section on Offshore wind power planning, economics and environment</section-head>
                                     <section-subhead/>
                                     <para>
                                      <aug>
                                      <author>D. John</author>
                                      </aug>
                                      <article>Special issue on offshore wind power</article>
                                      <page>495</page>
                                     </para>
                                     <para>
                                      <aug>
                                      <author>R. Smith</author> and <author>N. Vasil</author>
                                      </aug>
                                      <article>The economics of offshore wind</article>
                                      <page>496</page>
                                     </para>
                                    </section>
                                    <section>
                                     <section-head>Special Section on Offshore wind power planning, economics and environment</section-head>
                                     <section-subhead/>
                                     <para>
                                      <aug>
                                      <author>C. Smith</author>
                                      </aug>
                                      <article>Understanding public responses to offshore wind power</article>
                                      <page>503</page>
                                     </para>
                                     <para>
                                      <aug>
                                      <author>B. Moller</author>
                                      </aug>
                                      <article>Continuous spatial modelling to analyse planning and economic consequences of offshore wind energy</article>
                                      <page>511</page>
                                     </para>
                                     <para>
                                      <aug>
                                      <author>P. Soderholm</author> and <author>M. Pettersson</author>
                                      </aug>
                                      <article>Offshore wind power policy and planning in Sweden</article>
                                      <page>518</page>
                                     </para>
                                      <para>
                                      <aug>
                                      <author>D. Toke</author>
                                      </aug>
                                      <article>The UK offshore wind power programme: A sea-change in UK energy policy?</article>
                                      <page>526</page>
                                     </para>
                                    </section>
                                    </sections>
                                    

                                     

                                     

                                    Mac

                                    • 15. Re: How to shift content with in cell in xml rules table
                                      John Hawkinson Level 5

                                      Error Number: 54

                                      Error String: Uncaught JavaScript exception: Invalid

                                      value for paramater 'markupTag' of method 'add'.

                                      Expected String or XMLTag, but received nothing.

                                       

                                      Engine: main

                                      FIle: .../glue code.jsx

                                      Line: 78

                                      Source: throw e;

                                      Interpreter: CS4 (6.0)

                                      • 16. Re: How to shift content with in cell in xml rules table
                                        Mac_06 Level 2

                                        I think this is hard luck for me.

                                         

                                        Change this line-:

                                        var myColumnTag = myDocument.xmlTags.add("Column");

                                         

                                        With this-:

                                        var myColumnTag = myDocument.xmlTags.add("Cell");

                                         

                                         

                                        Mac

                                         

                                         

                                        • 17. Re: How to shift content with in cell in xml rules table
                                          John Hawkinson Level 5

                                          That does it! OK!

                                          Now for actually looking at the real problem!

                                          • 19. Re: How to shift content with in cell in xml rules table
                                            John Hawkinson Level 5

                                            It's the weekend, Mac!

                                             

                                            I got it to a point where it succesfully transforms to a table, though then I broke something else and I haven't had a chance to clean it up and make it real. Oh, and crashed InDesign half-a-bazillion times.

                                             

                                            I'll hopefully have time to finish it tonight (UTC-0500).

                                            • 20. Re: How to shift content with in cell in xml rules table
                                              John Hawkinson Level 5

                                              Wow, sorry for the delay.

                                              This paradigm is difficult enough to deal with, but Adobe's example code really does not encourage you to handle this reasonably at all.

                                               

                                              I've basically rewritten the entire process, and I've introduced a new paradigm for creating rules that I think is a lot more readable and flexible and allows for parametrization. Anyhow, here you go. Any questions?

                                               

                                              /*jslint undef: true, newcap: true, nomen: false, regexp: true,
                                                      bitwise: true, onevar: true, indent: 4, white: false */
                                              /*global File, LocationOptions, PageSideOptions,
                                                UserInteractionLevels,
                                                __processChildren, __processRuleSet, alert, app */
                                              
                                              #include "glue code.jsx";
                                              
                                              // handy debugging function; e.g.: $.writeln(dumplist(x.xmlElements));
                                              function dumplist(l) {
                                                  var i, rv = [];
                                              
                                                  rv.push("has "+l.length+" elements:");
                                                  for (i=0; i<l.length; i++) {
                                                      rv.push("  "+i+"\t"+l[i].toSpecifier()+
                                                                  "\t"+l[i].markupTag.name);
                                                  }
                                                  return rv.join("\n");
                                              }
                                              
                                              // Initialize a tags object to map strings to tags.
                                              function initTags(doc, tagnames) {
                                                  var i, t, tags = {};
                                                  
                                                  for (i=0; i<tagnames.length; i++) {
                                                      try {
                                                          t = doc.xmlTags.add(tagnames[i]);
                                                      } catch (e0) {}
                                                      tags[tagnames[i]] = doc.xmlTags.itemByName(tagnames[i]);
                                                  } 
                                                   return tags;
                                              }
                                              
                                              // Handy subtree functions
                                              function firstChildTag(node, tag) {
                                                  var i, e = node.xmlElements;
                                                  
                                                  for (i=0; i<e.length; i++) {
                                                      if (e[i].markupTag === tag) {
                                                          return e[i];
                                                      }
                                                  }
                                                  return node;
                                              }
                                              
                                              function lastChildTag(node, tag) {
                                                  var i, e = node.xmlElements;
                                                  
                                                  for (i=e.length-1; i>=0; i--) {
                                                      if (e[i].markupTag === tag) {
                                                          return e[i];
                                                      }
                                                  }
                                                  return node;
                                              }
                                              
                                              
                                              //// XML rule functions
                                              //
                                              // Adobe's sample for how to define these is HORRIBLE.
                                              // Let's fix several of these problems.
                                              //
                                              // First, a handy object to make clearer the return values
                                              // of XML rules:
                                              
                                              var XMLmm = { stopProcessing: true, continueProcessing: false}; 
                                              
                                              // Adobe suggest defining rules constructors like this:
                                              //
                                              //   function RuleName() {
                                              //       this.name = "RuleNameAsString";
                                              //       this.xpath = "ValidXPathSpecifier";
                                              //       this.apply = function (element, ruleSet, ruleProcessor){
                                              //       //Do something here.
                                              //       //Return true to stop further processing of the XML element
                                              //       return true;
                                              //       }; // end of Apply function
                                              //   }
                                              //
                                              // And then creating a ruleset like this:
                                              // 
                                              //   var myRuleSet = new Array (new RuleName, new anotherRuleName);
                                              // 
                                              // That syntax is ugly and, and is especially bad if
                                              // you need to parametrize the rule parameters, which is the only
                                              // reasonable approach to writing reasonable rules. Such as:
                                              // 
                                              //   function addNode(xpath, parent, tag) {
                                              //       this.name = "addNode";
                                              //       this.xpath = xpath;
                                              //       this.apply = function (element, ruleProcessor) {
                                              //           parent.xmlElements.add(tag);
                                              //           return XMLmm.stopProcessing;
                                              //       }
                                              //   }
                                              //
                                              // and then creating a ruleset like:
                                              //
                                              //   rule = new Array (new addNode("//p", someTag));
                                              //
                                              // So instead we introduce a makeRule function, that
                                              // allows us to leave behind all the crud. So then we can write:
                                              //
                                              // 
                                              // addNode = makeRule("addNode",
                                              // function(element, ruleProcessor, parent, tag) {
                                              //     parent.xmlElements.add(tag);
                                              //     return XMLmm.stopProcessing;
                                              // });
                                              //
                                              // and use:
                                              //
                                              // rule = [ addNode("//p", someTag ];
                                              //
                                              //
                                              
                                              function makeRule(name, f) {
                                                  return function(xpath) {
                                                      var
                                                          //xpath=arguments[0],
                                                             // "arguments" isn't a real array, but we can use
                                                             // Array.prototype.slice on it instead...
                                                             args=Array.prototype.slice.apply(arguments, [1]);
                                                      return {
                                                          name: name,
                                                          xpath: xpath,
                                                          apply: function(element, ruleProcessor) {
                                                                  // Slice is necessary to make a copy so we don't
                                                                  // affect future calls.
                                                              var moreargs = args.slice(0);
                                                              moreargs.splice(0, 0, element, ruleProcessor);
                                              
                                                              return f.apply(f,moreargs);
                                                          }
                                                      };
                                                  };
                                              }
                                              
                                              // Create a new node at parent. Doesn't do
                                              // anything with the XPath context node.
                                              var addNode = makeRule("addNode",
                                              function(element, ruleProcessor, parent, tag) {
                                                  parent.xmlElements.add(tag);
                                                  return XMLmm.stopProcessing;
                                              });
                                                 
                                              // Create a cell for a table, adding a node to
                                              // the last node of the last node of the
                                              // table. Duplicate the context
                                              // node as a child of that cell.
                                              var makeCell = makeRule("makeCell",
                                              function(element, rp, table, outertag, innertag) {
                                                  var
                                                      cell = table.xmlElements[-1].xmlElements.add(outertag),
                                                      copy = element.duplicate();           
                                                  copy.markupTag = innertag;
                                                  copy.move(LocationOptions.AT_BEGINNING, cell);
                                                  return XMLmm.stopProcessing;
                                              });
                                              
                                              // Apply from() to the context node to get
                                              // a source node. Copy that source node
                                              // to be the first child of the context node.
                                              var copyFromToChild = makeRule("copyFromToChild",
                                              function(element, ruleProcessor, from) {
                                                  var copy = from(element).duplicate();        
                                                  copy.move(LocationOptions.BEFORE,
                                                    element.xmlElements[0]);    
                                                  // __skipChildren(ruleProcessor);
                                                  return XMLmm.continueProcessing;
                                              });
                                              
                                              // We don't actually use this, but it was useful
                                              // in debugging. Essentially "rename" a node.
                                              // Set the tag of the context node to the
                                              // specified tag.
                                              var setTag = makeRule("setTag",
                                              function(element, ruleProcessor, newtag) {
                                                  element.markupTag = newtag;
                                                  return XMLmm.stopProcessing;
                                              });
                                              
                                              // Apply from() to the context node to get
                                              // a source node. Apply to() to the
                                              // context node to get a destination node.
                                              // Move the source node in the specified
                                              // location (how) to the destination node.
                                              var moveFromTo = makeRule("moveFromTo",
                                              function (element, ruleProcessor, from, how, to) {
                                                  __processChildren(ruleProcessor);
                                                  var src = from(element);
                                                  src.move(how, to(element));
                                                  return XMLmm.continueProcessing;
                                              });
                                              
                                              // end rule functions
                                              
                                              // It's just not worth rewriting some of Adobe's ugly functions...
                                              // but at least fix it up so it JSLints.
                                              function myGetBounds(myDocument, myPage){
                                                  var
                                                      myPageWidth = myDocument.documentPreferences.pageWidth,
                                                      myPageHeight = myDocument.documentPreferences.pageHeight,
                                                      myX1, myX2, myY1, myY2;
                                              
                                                  if(myPage.side === PageSideOptions.leftHand){
                                                      myX2 = myPage.marginPreferences.left;
                                                      myX1 = myPage.marginPreferences.right;
                                                  }
                                                  else{
                                                      myX1 = myPage.marginPreferences.left;
                                                      myX2 = myPage.marginPreferences.right;
                                                  }
                                                  myY1 = myPage.marginPreferences.top;
                                                  myX2 = myPageWidth - myX2;
                                                  myY2 = myPageHeight - myPage.marginPreferences.bottom;
                                                  return [myY1, myX1, myY2, myX2];
                                              }
                                              
                                              function myGetScriptPath() {
                                                  try {
                                                      return app.activeScript;
                                                  }
                                                  catch(myError){
                                                      return new File(myError.fileName);
                                                  }
                                              }
                                              
                                              
                                              // OK, the actual program.
                                              function main() {
                                                  var
                                                      doc = app.activeDocument,
                                                      page = doc.pages[0],
                                                      root = doc.xmlElements[0],
                                                      //inputFile = new File(myGetScriptPath().path+ "/mac.xml"), 
                                                      inputFile = File.openDialog(),
                                                      tags = {},
                                                      p, table;
                                                     
                                                  if (app.documents.length<1) {
                                                     alert ("Open a document and run the Script");
                                                     return false;
                                                  }
                                                  
                                                   // Let's not use a seperate variable for each tag. Instead,
                                                   // we'll keep an Object that maps strings to tags.
                                                  tags = initTags(doc,
                                                                       ["table", "para", "article",
                                                                        "section", "section-head", "tr", "td", "p"]);
                                                
                                                  doc.xmlImportPreferences.allowTransform = false;
                                                  doc.xmlImportPreferences.ignoreWhitespace = true;
                                              
                                                  app.scriptPreferences.userInteractionLevel =
                                                        UserInteractionLevels.NEVER_INTERACT;
                                                  doc.importXML(inputFile);
                                                  app.scriptPreferences.userInteractionLevel =
                                                        UserInteractionLevels.INTERACT_WITH_ALL;
                                                    
                                                  // For each <para>, copy the parent's <section-head> inside.
                                                  // Next, move each <article> node to the end of the <para>,
                                                  // placing it after the <page> node.
                                                  __processRuleSet(root, [
                                                      copyFromToChild(
                                                          "//para",
                                                          function(n) {
                                                                  return firstChildTag(n.parent,tags["section-head"]);
                                                             }),
                                                      moveFromTo(
                                                          "//para",
                                                          function(n) { return firstChildTag(n, tags.article); },
                                                          LocationOptions.AT_END,
                                                          // This is more general than we need to be; we're moving
                                                          // to "the end", but the end of WHAT? It need not be the
                                                          // <para>, it could be some other node.
                                                          function(n) { return n; })
                                                 ]);
                                                      
                                                  // Add a <p> node to hold the table we're about to create.  It's
                                                   // not super-clear from the documentation, but
                                                   // convertElementToTable creates a text node of the table in the
                                                   // XLM structure. In order to then place that into a frame, there
                                                   // has to be an enclosing XML node to do so. We choose <p> for
                                                   // lack of a better tag.
                                                  p = root.xmlElements.add(tags.p);
                                                  table = p.xmlElements.add(tags.table);
                                              
                                                  // For each para node, add a <tr> to the table.  For each
                                                  // <section-head>, <page>, or <article>, add a <td> to the last
                                                  // <tr> of the table
                                                  __processRuleSet(root, [
                                                      addNode("//para", table, tags.tr),
                                                      makeCell("//para/section-head", table, tags.td, tags.p),
                                                      makeCell("//para/page", table, tags.td, tags.p),
                                                      makeCell("//para/article", table, tags.td, tags.p)
                                                  ]);
                                              
                                                   // Make it a table and GO!
                                                  table.convertElementToTable(tags.tr, tags.td);
                                                  p.placeIntoFrame(page, myGetBounds(doc, page));
                                              }
                                              
                                              main();
                                              

                                               

                                              I also tried to format this to 72 columns so that it doesn't scroll on the forums. Let's see if that works...Nope, not quite. Oh well. Close enough.

                                              • 21. Re: How to shift content with in cell in xml rules table
                                                Mac_06 Level 2

                                                Many Thanks John, for reply and show me the path of working with even if the code is supplied by Adobe, we should not adopt it blindly.

                                                 

                                                I shall get back to you after a while.

                                                 

                                                Mac

                                                • 22. Re: How to shift content with in cell in xml rules table
                                                  Mac_06 Level 2

                                                  Highly intelligent script, but the only thing wanted to ask why does it copy xml element to next row also incase of blank cell appeared.

                                                   

                                                  e.g. section-head tag text is copied in next row also while it should be blank.

                                                   

                                                  Once again many thanks to pave me the way of writing intelligent script.

                                                   

                                                  Mac

                                                  • 23. Re: How to shift content with in cell in xml rules table
                                                    John Hawkinson Level 5

                                                    Oops, I apologize. I misunderstood the requirement.

                                                     

                                                    And this example shows us why XML rules processing in InDesign is not the most convenient approach...

                                                    Beforehand, for each <para>, we went up to it's parent and found a <section-head> and copied it in.

                                                    But we actually only want to do that for the first <para>.

                                                     

                                                    But we convert all <section-head>, <page>, and <article> nodes into table cells later, so we need to insert some placeholder in that spot to avoid having a problem. (Alternatively, we could hardcode the column numbers for <page> and <article> nodes and prepopulate the table nodes...).

                                                     

                                                    So, I'll offer several changes to the script piecemeal, so you can intergrate them and learn what's going on:

                                                     

                                                    First, let's change these helper functions to return null in the event they do not find a child node, rather than to return the parent node. This means it is easier now to test their return values in the event of not finding something, which is a case we have today:

                                                     

                                                    // Handy subtree functions
                                                    function firstChildTag(node, tag) {
                                                        var i, e = node.xmlElements;
                                                        
                                                        for (i=0; i<e.length; i++) {
                                                            if (e[i].markupTag === tag) {
                                                                return e[i];
                                                            }
                                                        }
                                                        return null;
                                                    }
                                                    
                                                    function lastChildTag(node, tag) {
                                                        var i, e = node.xmlElements;
                                                        
                                                        for (i=e.length-1; i>=0; i--) {
                                                            if (e[i].markupTag === tag) {
                                                                return e[i];
                                                            }
                                                        }
                                                        return null;
                                                    }
                                                    

                                                     

                                                     

                                                     

                                                    Next, we need to be able to copy nodes in particular places. Before the we used copyFromToChild() that always copied nodes into the context node. But we need to be more general, in order to copy <section-head> tags. So let's create a version that lets us specify the destination:

                                                     

                                                    // Apply from() to the context node to get
                                                    // a source node. Apply to() to the
                                                    // context node to get a destination node.
                                                    // Copy the source node in the specified
                                                    // location (how) to the destination node.
                                                    var copyFromTo = makeRule("copyFromTo",
                                                    function (element, ruleProcessor, from, how, to) {
                                                        var copy;
                                                        
                                                        // __processChildren(ruleProcessor);
                                                        copy = from(element).duplicate();
                                                        copy.move(how, to(element));
                                                        __skipChildren(ruleProcessor);
                                                        return XMLmm.stopProcessing;
                                                    });
                                                    

                                                     

                                                    We also need to be able to add an empty <section-head> tag in the other <para> nodes. In retrospect maybe I should have just made a new <section-head> node outside the subtree we're working on, and then copied that in each time with the above copyFromTo() function. But instead, I extended addNode() (Which is currently used to create table rows) to take not a fixed destination, but rather a function that returns a destination, so the destination can then be relative to the context node:

                                                     

                                                    // Create a new node at parent. Doesn't do
                                                    // anything with the XPath context node.
                                                    var addNode = makeRule("addNode",
                                                    function(element, ruleProcessor, where, tag) {
                                                        var parent = where(element);
                                                        
                                                        if (parent) {
                                                            parent.xmlElements.add(tag);
                                                        }
                                                        return XMLmm.continueProcessing;
                                                    });
                                                    

                                                     

                                                    Now, we can replace the first rule-processing section (that used to copy <section-head> into all <para>s) with one that operates on each <section-head> and copies to the beginning of the first following-sibling <para>. Note that the XPath specifier is "//section/section-head" rather than "//section" because we don't want to operate on the copy that we just made inside the tree. Otherwise we get duplicate <section-head> nodes.

                                                     

                                                    // For each <section-head>, that it is a direct child of a <section>,
                                                    // copy it inside the first <para> child.
                                                    // Next, move each <article> node to the end of the <para>,
                                                    // placing it after the <page> node.
                                                    __processRuleSet(root, [
                                                        copyFromTo(
                                                            "//section/section-head",
                                                             function(n) { return n; },
                                                             LocationOptions.AT_BEGINNING,
                                                             function(n) {
                                                                    return firstChildTag(n.parent,tags["para"]);
                                                                }),
                                                        moveFromTo(
                                                            "//para",
                                                            function(n) { return firstChildTag(n, tags.article); },
                                                            LocationOptions.AT_END,
                                                            // This is more general than we need to be; we're moving
                                                            // to "the end", but the end of WHAT? It need not be the
                                                            // <para>, it could be some other node.
                                                            function(n) { return n; })
                                                    );
                                                    

                                                     

                                                    Now, we need to deal with the other <para>s that have no <Section-head> in them. I'm not proud of this, it could probably be done better. And certainly would be easier without XML rules. Or if we had position() XPath functions:

                                                     

                                                    // This is kind of gross.
                                                    // For each <para>, if it does not contain a <section-head>, 
                                                    // add a <section-head> to it. This adds it to the *end*
                                                    // of the <para>'s chilld list.
                                                    __processRuleSet(root, [
                                                          addNode("//para", function(n) { 
                                                              if (!firstChildTag(n, tags["section-head"])) {
                                                                 return n;
                                                             } else {
                                                                 return null;
                                                             }
                                                          }, tags["section-head"]),
                                                          moveFromTo(
                                                              "//para",
                                                              function(n) { return firstChildTag(n, tags["section-head"]); },
                                                              LocationOptions.AT_BEGINNING,
                                                              function(n) { return n; })]);
                                                    

                                                     

                                                    Oh, and lastly, we changed the way addNode() worked, so we need to adjust the one other call to addNode to take a function rather than an explicit node:

                                                     

                                                    So in the last ruleset, change it to:

                                                     

                                                    addNode("//para", function() { return table; }, tags.tr),
                                                    

                                                     

                                                    Does this work for you?

                                                    • 24. Re: How to shift content with in cell in xml rules table
                                                      Mac_06 Level 2

                                                      That's it what I wanted, perfectly working code.

                                                       

                                                      Thanks John.

                                                       

                                                      Mac

                                                      • 25. Re: How to shift content with in cell in xml rules table
                                                        John Hawkinson Level 5

                                                        OK, great!

                                                         

                                                        So did you understand the code?

                                                         

                                                        If not, remember, I didn't do all this work for free! The price you have to pay is you have to keep asking questions until you understand how it works. Let's get started!

                                                        • 26. Re: How to shift content with in cell in xml rules table
                                                          Mac_06 Level 2

                                                          Sure John, I will get back to you, if anything get out of reach.

                                                           

                                                          Thanks

                                                          Mac

                                                          • 27. Re: How to shift content with in cell in xml rules table
                                                            Mac_06 Level 2

                                                            I am sorry John for once again disturbing you,

                                                             

                                                            Even though in complete code, more then half lines are written in comment but still something is hard to reach.

                                                             

                                                            The stuff we both skipped is to move <article> inside <aug>tag as first element in <aug> then we need to move <page> before <aug> or move <aug> after <page> and at last we need to create Cell of <aug> instead of <article>.

                                                             

                                                            e.g. you could run and see in my finally given ugly code.

                                                             

                                                            I tried a lot but all time failed.

                                                             

                                                            Apart from this something I wanted to reach

                                                             

                                                            function(n) is too tough to understand for me, How is it working? what is it resulting?

                                                             

                                                            Sorry... I am not a good scripter.

                                                             

                                                            Mac

                                                            • 28. Re: How to shift content with in cell in xml rules table
                                                              John Hawkinson Level 5

                                                              Don't apologize! Happy to help.

                                                               

                                                              Though...I'm sorry I'm not quite sure what you're asking for. What do you want the output to look like?

                                                              The function(n) stuff is a bit confusing, but let's break it down.

                                                               

                                                              Let's take the first ruleset run:

                                                               

                                                              // For each <section-head>, that it is a direct child of a <section>,
                                                              // copy it inside the first <para> child.
                                                              // Next, move each <article> node to the end of the <para>,
                                                              // placing it after the <page> node.
                                                              __processRuleSet(root, [
                                                                  copyFromTo(
                                                                      "//section/section-head",
                                                                       function(n) { return n; },
                                                                       LocationOptions.AT_BEGINNING,
                                                                       function(n) {
                                                                              return firstChildTag(n.parent,tags["para"]);
                                                                          }),

                                                               

                                                              Every time we say "function(n) { ...} " that means it returns a function, that we can then pass around. We could do the same thing by giving the function a name; which makes the code list a little more verbose:

                                                               

                                                              var self = function(node) { return node; };
                                                              

                                                               

                                                              Which is exactly the same as the more-familiar:

                                                               

                                                              function self(node) { return node; };
                                                              

                                                               

                                                              Now, we just need to handle the other function:

                                                               

                                                              function first-para-child-of-parent(node) {
                                                                  return firstChildTag(node.parent,tags["para"]);
                                                              }
                                                              
                                                              

                                                               

                                                              So, the self() function simply returns itself. So that means if the context-node (the result of the XPath expression)

                                                              is a <section-head> inside a <section>, then self() will return that <section>. node. Remember what copyFromTo takes:

                                                               

                                                              // Apply from() to the context node to get
                                                              // a source node. Apply to() to the
                                                              // context node to get a destination node.
                                                              // Copy the source node in the specified
                                                              // location (how) to the destination node.
                                                              var copyFromTo = makeRule("copyFromTo",
                                                              function (element, ruleProcessor, from, how, to) {
                                                                  var copy;
                                                                 
                                                                  // __processChildren(ruleProcessor);
                                                                  copy = from(element).duplicate();
                                                                  copy.move(how, to(element));
                                                                  __skipChildren(ruleProcessor);
                                                                  return XMLmm.stopProcessing;
                                                              });

                                                               

                                                              makeRule() provides the first 2 args to copyFromTo, so the three are (from, how, to).

                                                               

                                                              Anyhow, so with the 2 named functions, we can replace the first ruleset run with:

                                                               

                                                              __processRuleSet(root, [
                                                                  copyFromTo(
                                                                      "//section/section-head",
                                                                       self,
                                                                       LocationOptions.AT_BEGINNING,
                                                                      
                                                              first-para-child-of-parent),

                                                               

                                                              Does that help make it clearer? We pass copyFromTo two functions that it uses to determine what the from and to nodes to copy are. We're not calling them directly from the main() , we're passing them into copyFromTo so that it can use them.

                                                              • 29. Re: How to shift content with in cell in xml rules table
                                                                Mac_06 Level 2

                                                                Great help..., finally I got it.

                                                                 

                                                                Thanks John