5 Replies Latest reply on Apr 22, 2009 11:26 PM by Kees van Daalen

    moving xml elements to table cells

    grefel Level 2

      hi there,


      i just tried to move xmlElements into a table cell. my first approach was:

       

      1. create a table
        _indTable = _insertionP.tables.add(LocationOptions.AFTER,_insertionP,{columnCount:3,bodyRowCount:3} )
      2. autoTag the newly created table
        _indTable.autoTag();
      3. try to move an existing element into a cell:
        app.activeDocument.xmlElements[0].xmlElements[0].move(LocationOptions.UNKNOWN, _indTable.rows[0].cells[0].texts[0]);
        this crashes indesign.
      4. the next idea was to choose the XMLElement
        ...move(LocationOptions.UNKNOWN, _indTable.rows[0].cells[0].associatedXMLElement);
        but: Error: This operation cannot be performed on the selected element.
      5. next approach was cut/paste
        _td.select();
        app.cut();
        _indTable.rows[j].cells[k].associatedXMLElement.select();
        app.paste();

       

      i wonder if there is any more elegant way to move xmlElements into table cells? and do i understand the move() method in it's intended way...

       

      any hints, ideas and answers a greatly appreciated!

      gregor

       

      Message was edited by: grefel    sorry hit return ....

        • 1. Re: moving xml elements to table cells
          Kees van Daalen Level 1

          The elegant way to get your content in an table is to transform your xml.

          In this pdf

          wwwimages.adobe.com/www.adobe.com/products/indesign/scripting/pdfs/indesign_and_xml_techni cal_reference.pdf

          you can read all about making InDesign tables from xml.

          • 2. Re: moving xml elements to table cells
            grefel Level 2

            thanks, i knew this document (-:

             

            xsl-transformation for rowspan can get quite complicated. i'm looking for a scripting only solution to keep the dependencies low (and don't even try the built in xslt processor).

             

            without the bug (?) a scripting only solution could be quite interesting, especially in combination with evaluating additional styling attributes.

            • 3. Re: moving xml elements to table cells
              Kees van Daalen Level 1

              Hi Gregor,

               

              I think there is an error because you try to move a XMLElement to Text.

              You can move a XMLElement to another XMLElement.

              The table is already autotagged, now you should move the right element to the right cell.

              Beware: the structure changes evereytime you move a xmlelement, so you need to make a new reference to the table and the next element you want to move.

               

              Another possibility is to move the text of the elements to the texts of the cells.

              That way the structure does not change.

               

              I hope this helps.

               

              Grtn, Kees

              • 4. Re: moving xml elements to table cells
                grefel Level 2

                hi kees,

                 

                i tried both (see my first post point 3+4) either my command is wrong or this is an indesign bug with table/xml handling. especially given that in one case the table simply disappears without notice or exception.

                 

                if you move only the text into the cells you loose child elements.

                 

                regards,

                gregor

                • 5. Re: moving xml elements to table cells
                  Kees van Daalen Level 1

                  Hmmm...

                  I tried to move a xmlelement into a tagged table, but "computer says no".

                  I don't think InDesign allows you to move a xmlelement to a cell.