Eric White's Blog
Open XML, SharePoint, and Office
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.
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.
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:
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
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
Upon closer reading, this appears to be similar to the sort of functionality that I am looking for, as well.
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
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?
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?
[...] 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. [...]