Fun with InfoPath and XSLT – set repeating table | section rows number by user


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 )

RepatingTable Counting based on user input

Repeating Table Counting based on user input

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”

RepatingTable html from view xsl file

RepatingTable html from view xsl file

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”

RepatingTable after remove it's content

Repeating Table after remove it’s content

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”

XSL template with recursive calling for the repeating table content

XSL template with recursive calling for the repeating table content

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”

InfoPath SampleData.XML file

InfoPath SampleData.XML file

Sample data XML file and how to know the XPATH for template match attrbuite

Sample data XML file and how to know the XPATH for template match attrbuite

10-Now back to the “<tbody” tag and add the template calling on it rather than the HTML content as below image

Call template and pass the paramter "num" from the dropdownlist

Call template and pass the parameter “num” from the drop down list

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

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
.Set CabinetNameTemplate=Form1_Repacked.XSN

;Here the path for the repacked .xsn file that the tool will save the file into it
.set DiskDirectoryTemplate=”D:\RepackedFolder”
.Set Cabinet=on
.Set Compress=on

; 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


MakeCab DOS Command

MakeCab DOS Command



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


11 thoughts on “Fun with InfoPath and XSLT – set repeating table | section rows number by user

  1. This was great! I was able to get the test to work just fine! Now how do I manipulate this so it works for a web-based form? What should I change the mode to, since it looks like the xd; preserve mode is not compatible with web-based forms?

  2. i downloaded your example and it worked fine. but i could not find the number of rows to be selected when i tried to implement it. i could see there is one xml tag call drpNumber. where does it get incremented to 5 as i see in the form’s front end. and is there any possibility of having a text box instead of drop down? what changes should i make in case of text box?

  3. I know this is an old post, I just tried it, and while it works as far as creating the rows, if I edit anyone of them, all the values change. That is, none of my rows seem to be unique. Anyone else had that issue?

    • I’m having the same problem. The table rows appear in the form but any value entered in any cell is copied to all the cells in the column. If I save the form, the xml shows only one copy of the group containing the cells.

  4. Thank you. 🙂 And now that I’m all back together I’m not getting any rows at all. I used a field with integer value instead of the drop down and my fields have different names but other than that I don’t see a problem in code. Of course I don’t know xml. It’s all ‘monkey see monkey do’ for me.

    • Should “my” be replaced with “myFields” as the path? I don’t have a folder or group named “my” In looking over the code it’s the only thing I can think of.

    • It just the prefix that InfoPath added in XML elements , so when I use XPATH to select I must put the path of the element that I need to select started with the prefix whatever it’s started with My or MYFields or any other keywords

  5. I probably missed some small detail but rows didn’t increase. The last step was close the .xsl and open the form. The view was extracted from a .cab but we didn’t put it back in the .cab and rename to .xsn.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s