Repeating Content in Document Generation System that uses XPath Expressions in Content Controls

I recently received a very good request for an enhancement to this document generation system.  The request was for a “Repeat” control that works in a similar way to tables, but instead of putting child records into a table, the document generation system generates a repeating section of content.

To review, here is what the template document looked like in the last iteration of this document generation system.  Below, you can see a screen-shot of the template document.  Following that screen-shot, there is a listing of the XML file that contains the data that will be used in the document generation process.

  • The green oval in the template document contains the XPath expression that selects the XML elements that contain the data for each of the documents.  That XPath expression selects the Customer elements in the XML document (also circled with a green oval).
  • Then, having selected the records for documents, the XPath expression in the blue oval selects the child records for the rows in the table.  The context nodes for that XPath expression are the Customer elements selected by the XPath expression in the green oval.  The selected elements in the XML document are encircled by a blue rounded rectangle.
  • And then finally, the XPath expressions circled by red select the values to place in the cells in the table.  In the XML document, the first set of nodes selected by those XPath expressions are also circled with a red oval.

Template1

XML1

The Repeat construct is parallel to that of a table. The following template document is similar in structure to the above template document, except that instead of generating a table, it generates repeating content.

Template2

When generated with the above XML document, the first document in the generated document looks as follows. I have encircled the repeating content with green rounded rectangles:

GenDocs1

Of course, due to the recursive implementation, you can get really elaborate with this setup. You can, for instance have repeating content within repeating content, or conditional content that contains a table within repeating content, and so on.

Download: 12-02-21-Gen-Docs-XPath

!!!

15 Comments »

  1. Tom W said,

    February 28, 2012 @ 9:52 pm

    Nice post Eric.
    You never got around to adding repeating in horizontally across cells did you? To refresh your memory, like if I wanted a column per Year for financial data.

    Tom

  2. chirag said,

    March 23, 2012 @ 11:28 am

    Hi Eric,
    Your written blog is very useful, I want to generate Document using this method.

    I am already generating very complex document using COM+. But it’s too slow and very tedious to handle.

    I found your article it’s very useful, I want to Generate Document with this method. now I have query is that I want to generate table for amount column and at last I want to do some of the column, Now I tried lots but I can’t found it.

    My table like this.

    ——————————————————————————————
    Description Amount Field1 Amount Field2 Amount Field3

    ——————————————————————————————-
    Total Sum of Field1 Sum of Field2 sum of Field3
    ——————————————————————————————-

    Please Help.

    Chirag

  3. John Holliday said,

    April 9, 2012 @ 12:55 pm

    After reviewing your excellent code samples, I noticed that in your templates, you use both the “Title” and “Tag” fields of the content controls, but in your code, you rely only on the “Title” (alias) field to locate your placeholders, even though your routine is called “GetContentControlByTag”.

    Is there a particular reason you decided to switch from using the Tag field to using the Title field?

  4. Joe Cardali said,

    May 31, 2012 @ 2:19 pm

    Hi Eric – I am looking to use this system to generate some documents that use tables the purposes of structure (no tabular data). I am having some trouble accomplishing this, my one bright idea was wrapping individual cells in “SelectValue” tags, but this yielded no results. Can you think of any way to accomplish this?

  5. Joe Cardali said,

    May 31, 2012 @ 7:26 pm

    Upon closer reading, this appears to be similar to the sort of functionality that I am looking for, as well.

  6. Document Management – A better means to actively engage global business!Document Generation Software said,

    March 8, 2013 @ 11:05 pm

    [...] Document management using web wizards is an innovative approach to high-speed documentation. Exploring the potential of XML helps to manage document authoring in the conventional querying manner. However, web wizards simplify this process for ordinary users. The most commonly observed phenomena why employees resist automation is the inertia to learn new methods with hours of intensive training. Wizards eliminate entire process and ensure these users master the tool with minimal learning. This flexible platform offers complete control of the document dynamics of its built-in features to define designs, layouts, and other formatting options. [...]

  7. Tor said,

    August 8, 2013 @ 12:10 pm

    Eric,

    Thanks for all your hard work. I have been following your blog posts for a while, and I am very impressed with how much material you are able to produce. I don’t see how you find time for it all. In any case, keep up the good work.

    My question is:

    Any chance that you will translate this app: “Repeating Content in Document Generation System that uses XPath Expressions in Content Controls” using your new javascript libraries?

  8. Eric White said,

    August 8, 2013 @ 1:23 pm

    Hi Tor,

    I’m glad you like the blog posts / etc.

    Funny you should ask about this – very definitely this is high on my list. As *one* example of a use case, supply an XML data source, along with a template document to a JavaScript application. It returns a zip file that contains all generated documents. This can even be a JavaScript application that I host on OpenXmlDeveloper.org or on this blog, there for anybody to use as a ‘service’.

    Another use case – use Node.JS to generate the documents.

    A third use case – a JavaScript application that is a Word app – while editing the template document, supply an XML file, and immediately save a ZIP file that contains the generated documents.

    There are more use cases.

    Anyway, I have some other projects to get out of the way first, but this is definitely on the radar.

    Cheers, Eric

  9. Victor said,

    September 12, 2013 @ 5:41 am

    Hi, Eric. The example sources is not avaibale.

  10. Mauro Garcia said,

    March 27, 2014 @ 5:56 pm

    Hey Eric, I want the example too :/

    (Nice blog btw)

  11. Rich P said,

    April 8, 2014 @ 12:20 pm

    Eric – great blog. I was really looking forward to playing around with this example but can’t find the download. Will it ever be available again?

    Thanks,
    Rich P

  12. Eric White said,

    April 9, 2014 @ 3:53 pm

    Hi Rich, Here is the link:

    https://skydrive.live.com/redir?resid=5E385848AF211BA9!5731&authkey=!AOs_0PT_ICgWjcg

    Cheers, Eric

  13. Dave said,

    June 19, 2014 @ 4:19 pm

    Eric,
    I love your coverage of what is possible with the OpenXML technologies and am learning a lot from your articles and code listings. I cannot seem to access the link to the download for the article (refer to the URI) and was wondering if you could please make the download available once again?
    thanks,
    Dave

  14. Dave said,

    June 19, 2014 @ 4:25 pm

    Eric,
    Sorry for the oversight regarding the download link…I was able to get to the download from your response to a previous comment post.
    thanks,
    Dave

  15. mactavish2191 said,

    July 29, 2014 @ 10:28 pm

    Eric Please help me out in processing word document.
    I have to extract the contents of word files with formatting and everything
    within special tags.Can u help me.

RSS feed for comments on this post · TrackBack URI

Leave a Comment