Note: you can download the full example by Click Here
Repeating table and repeating section are two controls in Microsoft InfoPath that takes a data source to bind , the number of rows for both are based on the data source rows count.
suppose you need to create a repeating table or section rows at run time by entering the number of rows for repeating table by the user !
To do that we will play around the XSL for the InfoPath form view – we will create a loop in XSL that count based on user input “For example from dropdown list that contains some numbers” , actually our example can apply in any section or control that you need to repeat here is the full example:
1-Create a blank InfoPath Form , add two controls drop down list and repeating table (see below image )
2- Close the form , rename the form and change the extension from “.xsn” to “.cab” then right click and extract it to suitable place using WINRAR program or any extraction program.
3-you will find an “XSL” file , the file name will be the view name , in my example i left the default view name as it is so the file name is “view1.xsl”.
4-Open the “view1.xsl” , prefer to open it using visual studio “it is colorful 🙂 and it will warn you if there is any mistake in XML format by you when modifying”
5-Find the element “<tbody xd:xctname=”RepeatingTable”>” this element for the HTML table body for the repeating table “as image below”
6-Remove the “<xsl:for-each” element from the beginning and the end of the “<tbody>”
7-Cut all HTML content inside the “<tbody” element and leave the “<tbody” element blank “as image below”
8-Go to the end of the file , we will create an XSL template that use recursive calling inside it based on the number from the drop down list , paste the copied content from step “7” inside it “see image below for full template with description for each part , click on image to reach the full size”
9-About the match attribute in the “template” element i got the XPATH for the repeating table from the “xsl:for-each” element that we removed in the step “6” 🙂 , or you can simply open “sampledata.xml” file that you can know the full XML schema for data “see two below images – click for full size”
10-Now back to the “<tbody” tag and add the template calling on it rather than the HTML content as below image
11-Close the XSL file.
12-Now we will repacking the these files to .XSN again in the next steps
Repacking the InfoPath extracted files to .XSN file again
1-Open this path in your machine “<Your windows drive>:\Windows\System32\” and find a tool “makecab.exe” on it , this tool that will create the CAB file again from extracted files , the tool has many functions to do you can review it from here http://support.microsoft.com/kb/310618/
2-Copy the below commands and put it into a .txt file and save it to suitable place , these CMD commands txt file will pass as a parameter to the Cabinet tool , you will find a comment line started with “;” read it to modify the variables with your paths and names
;Here the file name after repacked to xsn
;Here the path for the repacked .xsn file that the tool will save the file into it
; list here all extracted files paths
3-Open the CMD and write the following command “MakeCab /f <the path to the txt file that you saved>” for example “MakeCab / f D:\Form1\Repack.txt” then click enter
4-you will find the result like the below image and you will find the .XSN repacked on the path which you specified on the .txt file “in our example you will find it in D:\RepackedFolder\Form1_Repacked.XSN
1-You can remove ” insert” link from the repeating table as it is not necessary in this case , the insert link used by the user to add a new row and in this example the responsibility of adding rows is moved to the row numbers entered by the user .
2-The same example can applied at repeating section specially the repeating section creating a template automatically just you need to make recursive call with parameter “number”
3-This example demonstrate how you can edit in the form and make what you want by playing around XSL , here is very good reference for learn XSL quickly
hope it will help