Search This Blog

Friday 24 January 2014

Listing all fields in a form

Because the XDP file that defines a Designer form is just a XML file we can run an XSLT over it.

In this case we will produce a list of all the field objects that we can view in Microsoft Excel,  so we will also use Excel to run the XSLT.

First download the XSLT file, XSPFieldList.xslt , and place it in the same directory as the XDP file of your form.

Edit your form XDP file using Notepad or similar and add the following line after the XML declaration;

<?xml-stylesheet type="text/xsl" href="XDPFieldList.xslt"?>

So it should look something like;


There is a line in the XSPFieldList.xslt that looks like;

xmlns:xfa="http://www.xfa.org/schema/xfa-template/2.8/"

This might need to change to match the namespace in your XDP file (see the last line in the screen shot above)  depending on which version of Reader your form is targeting. The namespace ending in  xfa-template/2.8 means my form is targeting Reader 9.0 and above. For Reader 9.1 and above it would be xfa-template/3.0.

Now in Microsoft Excel open the XDP file (Excel doesn't know about XDP files so your will have to select "All Files (*.*)" in the Open dialog).  The first thing Excel will do is popup an Import XML... dialog;


This means it has found our xml-stylesheet line and wants to confirm we want to run the XSLT, so select "Open the file with the following stylesheet applied (select one):"

You will then get a "different format" message, which is fair enough as the XSLT will have changed the format so select Yes;


Then you get an Open XML dialog, which defaults to "As an XML table" which is what we want to do, so select OK.

 
 
The final dialog is the no schema message.  We haven't provided a schema so Excel will create one for us.  This dialog you can turn off.
 
 
 
 
The final result will look something like;
 


There is a lot you can add to the XSLT so think of this as a starting point, and remember to remove the xml-stylesheet line from the XDP as Designer will think the form is created in a new version and not allow you to do much except look at the XML Source.

Response Files

This approach can also be helpful in working with a response file from the collection of returned forms.  If you export the responses as XML then they can be processed by an XSLT and loaded into Excel in the same way.

If your XSLT produces an HTML document containing a HTML table then Excel will still load it into a spreadsheet, but you now can specify business names for the columns not just the field names from the form, so you can now have spaces in the column names. 

The XSLT will also allow you to do some decoding, such as turning 1 and 0 into 'Yes' and 'No' or whatever formatting you want.

UPDATE

Radzmar has written a macro to make the first couple of steps easier, so you no longer need to make a temporary change to your XDP file and the macro works out the correct namespace.   More details in a later blog Listing all fields in a form - The macro.

3 comments:

  1. This looks interesting.... I admit I do not understand all of it or why a person may want to it.

    I did find this information interesting -
    "This approach can also be helpful in working with a response file from the collection of returned forms. If you export the responses as XML then they can be processed by an XSLT and loaded into Excel in the same way."

    Could you provide some detail on this? Is a response file a special output or are you simply talking about a filled form that has been saved? Sorry for the newbie question but I am interested in looking more.

    Thanks!

    ReplyDelete
  2. Hi Tom,

    One of the options for distributing a form is using Adobe Acrobat and the Tools ... Forms ... Distribute option. There are a few options offered but the simplest is probably the Email option and "manually send later". The forms can then be collected and a response file created. Have a look at http://www.adobe.com/content/dam/Adobe/en/products/acrobat/pdfs/adobe-acrobat-xi-distribute-pdf-forms-analyze-responses-tutorial-ue.pdf

    This all works well but the response file can be a bit raw and in need of some tidy-up work.

    The reason I wanted a list of form objects was so I could send them to my business area so they could review the captions, tooltips and error messages.

    Bruce

    ReplyDelete
  3. Hi Bruce,

    great idea.
    I tooked this and created a macro for Designer which will generate the XSLT and XML files with the correct namespaces.
    The user then only needs to open the generated XML file with Excel.

    Here's the macro:
    https://files.acrobat.com/preview/74781f70-aac4-4e09-8802-3161b0831281

    ;-)
    Marcus

    ReplyDelete