Thread

Posted on Fri Sep 16 00:48:59 2005 by bob
insertParagraph -- path and position
Thanks for the tolerance in putting up with these posts. I'm having difficulty with some of the basics of the modules.

I don't understand what is to be used for path and position. I've not found any examples in the documentation. Are there some that I have missed ? Could someone give me an example ?

If my template file contained a marker/token such as "INSERT PARAGRAPH HERE", how would I go about replacing that token with an arbitrary paragraph of text.

Thanks again for all your patience.

Bob

insertParagraph(path, position [, options])<br><br> insertParagraph(element [, options])<br><br> Same as appendParagraph, but a new paragraph is inserted at the given position.<br><br> Position is that of an existing element which can be another paragraph or a header. Can be given by [path, position] or by element reference. <br><br> Options are the same as for appendParagraph, with the additional option 'position' which determines whether the paragraph is inserted before or after the element at the given position. Possible values for this options are 'before' and 'after'. By default, the element is inserted before the given element.
Direct Responses: 1002 | Write a response
Posted on Sat Sep 17 00:03:50 2005 by jmgdoc in response to 999
Re: insertParagraph -- path and position

If you want to insert a paragraph, you have to indicate an existing element, so the new paragraph is inserted before or after the given element.

An existing element can be selected by an XPath expression followed by a zero-based absolute position number. For example ("//text:p", 2) is the third paragraph and ("//text:h", 0) is the first header. So, if you want to insert a new paragraph before the 3rd existing paragraph, you can write
$doc->insertParagraph("//text:p", 2, position => 'before');
The 'position' option can be set to 'before' or 'after'; here, the new paragraph becomes the third one. With 'after' it would become the fourth.

Alternatively, if you previously got the third paragraph container, knowing that XPath query calculations are more time-consuming than direct element access, you should use it instead of the "path + absolute position", as below:
my $p = $doc->getParagraph(2); $doc->insertParagraph($p, position => 'before');
Write a response