4 Replies Latest reply on Jan 7, 2010 12:32 PM by AdobeScripts

    move stories in XML

    ThisGuy-500 Level 1

      Hi,

       

      I'm a newbie to scripting, and I'm wondering if someone can help me out.  I'm trying to write a script that will cluster two types of XML tags based on the numbers within them.  The tags are called "FigRef", and "FigCaption" respectively. 

       

      The figure references are disseminated throughout the text of the main stories. The captions are in separate "stories" in InDesign, and they appear at the end of the XML document.   What I want to do with scripting is move each caption story to the paragraph before the reference (see below).  I want the caption before the reference because in the final layout the captions are pushed out to the side with a float in CSS.

       

      The way I'd like it to appear:

       

      <story><FigCaption>Figure 1.1 This is the caption for Figure 1.1</FigCaption></story>

      <story>...Now examine <FigRef>Figure 1.1</FigRef>.  You can see that...</story>

       

      ...the way it is now:

       

      <story><paragraph>...Now examine <FigRef>Figure 1.1</FigRef>.  You can see that...</paragraph></story>

      <story><paragraph>...some other paragraphs</paragraph></story>

      <story><paragraph>...some other paragraphs</paragraph></story>

      <story><paragraph>...some other paragraphs</paragraph></story>
      <story><FigCaption>Figure 1.1 This is the caption for Figure 1.1</FigCaption></story>

       

      You can see an example of the final structure that I'd like to end up with from the picture attached.

       

      Thanks for any help!

       

      -ThisGuy

        • 1. Re: move stories in XML--revision
          ThisGuy-500 Level 1

          I can make my question even more simple, by starting out with all the elements in the same story.  Can someone suggest a way to move each FigCaption to its corresponding FigRef?

           

          The way I'd like it to appear:

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

          <story>

          <paragraph>...some other paragraphs</paragraph>

          <paragraph>...some other paragraphs</paragraph>

          <paragraph>...some other paragraphs</paragraph>

          <FigCaption>Figure 1.1 This is the caption for Figure 1.1</FigCaption>

          <paragraph>...Now examine <FigRef>Figure 1.1</FigRef>.  You can see that...</paragraph>

          <paragraph>...some other paragraphs</paragraph>

          <paragraph>...some other paragraphs</paragraph>

          <paragraph>...some other paragraphs</paragraph>

          </story>

           

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

           

          ...the way it is now:

           

          <story>

          <paragraph>...some other paragraphs</paragraph>

          <paragraph>...some other paragraphs</paragraph>

          <paragraph>...some other paragraphs</paragraph>

          <paragraph>...Now examine <FigRef>Figure 1.1</FigRef>.  You can see that...</paragraph>

          <paragraph>...some other paragraphs</paragraph>

          <paragraph>...some other paragraphs</paragraph>

          <paragraph>...some other paragraphs</paragraph>

          <FigCaption>Figure 1.1 This is the caption for Figure 1.1</FigCaption>

          </story>

          • 2. Re: move stories in XML--revision
            AdobeScripts Level 3

            hi

             

            you can use .Move of XMLElement with idLocationOptions.idAfter but this will change physical structure/order of Paragraphs in your Story ...

             

            Function Move(To As idLocationOptions, [Reference]) As XMLElement
                Member of InDesign.XMLElement
                Moves the element to the specified location. .
                Return value: The moved element.
                To: The location in relation to the reference object or within the containing object.
                Reference: The reference object. Note: Required when the to parameter specifies before or after. . Type: XMLItem or Text

             

            robin

            www.adobescripts.co.uk

            • 3. Re: move stories in XML--revision
              ThisGuy-500 Level 1

              Thanks, Robin.  My ultimate goal is to move figure reference paragraphs to the figure caption paragraphs, so that sounds right.

               

              But this looks like I would have to identify each caption using this script.  Would you know a way for me to search the document for the first instance of a  figure caption, moving it to the first instance of a figure reference, and repeat to the next one set?  This should work since the references are in order, and the captions are in order at the end of the document.

              • 4. Re: move stories in XML--revision
                AdobeScripts Level 3

                ThisGuy-500 wrote:

                 

                But this looks like I would have to identify each caption using this script.  Would you know a way for me to search the document for the first instance of a  figure caption, moving it to the first instance of a figure reference, and repeat to the next one set?  This should work since the references are in order, and the captions are in order at the end of the document.

                 

                You can walk through the XMLElements collection or use Search for specified ParagraphStyle.

                But in both cases - you need to walk from last to first element.

                 

                robin

                www.adobescripts.com