.ANX (HotDocs XML) to HTML via XSLT Example

This is a reference sample of an XSL transform that can be used on any HotDocs XML style document. As you may know, A2J Guided Interviews output .ANX formatted XML. This transform converts the ANX file into an HTML table that lists all of the variables that were created by the A2J Guided Interview. Here is a sample ANX file generated by the Iowa Intake Interview that ask the user lots of questions about eligibility for legal aid:


As you can see, ANX XML uses a single element - "Answer" and puts the name of the variable into an attribute. The XSL transform looks like this:


Let's break it down so that you can see what is going on...

The first functional line ...

<xsl:template match="/AnswerSet">


... says that we are looking for the "AnswerSet" tag and anything inside it. That's pretty standard XQuery.

The next section of code ...

	<xsl:element name="table">
   <xsl:attribute name = "border" >1</xsl:attribute> 
   <xsl:attribute name = "cellpadding" >10</xsl:attribute> 
   <xsl:element name="tr">
   <xsl:element name="td">
   </xsl:element> <!-- td --> 
   <xsl:element name="td">
   <xsl:text>variable name</xsl:text>
   </xsl:element> <!-- td --> 
   <xsl:element name="td">
   </xsl:element> <!-- td --> 
   <xsl:element name="td">
   </xsl:element> <!-- td --> 
   </xsl:element> <!-- tr --> 


Creates the output table with a border of 1, cellpadding of 10 and 4 columns with column headers of "#", 'Variable name", "type" and ""value".

The next section of code...

<xsl:for-each select="//Answer">


loops through all of the "Answer" tags found inside of the "AnswerSet" tag and this code ...

 <xsl:variable name="getanswers" select="position()"/>


... keeps a counter for the first column of the table. For every "Answer" tag found, we want to start a new row in the table. This is accomplished with the next section of code...

<xsl:element name="tr">
   <xsl:element name="td">
   <xsl:value-of select="$getanswers"/>
   </xsl:element> <!-- td --> 
   <xsl:element name="td">
   <xsl:value-of select="@name"/>
   </xsl:element> <!-- td --> 
   <xsl:element name="td">

The table row is output with the counter and variable name. Notice we are selecting for "@name" which gets us the attribute named "name". That is where variable name is in ANX XML. It's not in the tag since all of the tags are "Answer" tags. Now to get the type and value of the variable, we have to use an XSL case statement which is called a "Choose/When" in XSL. This section of code looks for the type of variable by looking for the tag names "RptValue", "TextValue", etc.

   <xsl:when test="RptValue">
   <xsl:text>Multiple Text</xsl:text>
   <xsl:when test="TextValue">
   <xsl:when test="MCValue">
   <xsl:text>Multiple Choice</xsl:text>
   <xsl:when test="NumValue">
   <xsl:when test="TFValue">
   <xsl:when test="DateValue">


Getting the value of the variable is trivial at this point, since we are pointing at the variable, we use the "." shortcut notation.

 <xsl:element name="td">
   <xsl:value-of select="."/> 
   </xsl:element> <!-- td --> 
   </xsl:element> <!-- tr --> 


... The above code also closes off the table cell and the table row since we are all done with this variable.

This code closes the for-each loop ...

 </xsl:for-each> <!-- end of foreach for PersonInformation --> 


This code closes the table ...

 </xsl:element> <!-- table -->  


... and we are done.

Here is what the table looks like after the transform as run ...

# variable name type value
1 User Gender Multiple Choice Male
2 HOME_ADDRESS1 Text 111
4 HOME_CITY Text Akron
5 HOME_COUNTY Multiple Choice Adams
6 Problem Description TE Text  
7 User First Name TE Text John
8 Non Iowa TF True/False  
9 SSN NU Text 123-12-3123
10 Email TE Text jmayer@cali.org
11 Deadline TF True/False false
12 Hearing TF True/False false
13 OP HOME_ADDRESS1 Multiple Text 123 Maple
14 OP HOME_ADDRESS2 Multiple Text  
15 OP HOME_CITY Multiple Text Columbus
16 OP HOME_COUNTY Multiple Text  
17 OP HOME_STATE Multiple Text Ohio
18 User language TE Multiple Choice  
19 User Ethnicity TE Multiple Choice Hispanic and Black
20 Adult HH Member SSN NU Multiple Text 444-44-4444
21 Adult HH Member DOB NU Multiple Text 4/4/1984
22 English language TE True/False  
23 User Zip Code NU Text 44301
24 Citizenship MC Multiple Choice A
25 Problem Type TF Multiple Choice 1
26 Consumer MC Multiple Choice  
27 Benefits MC Multiple Choice  
28 Employment Problem MC Multiple Choice  
29 Income child support TF True/False true
30 Income disability TF True/False true
31 Income employment TF True/False true
32 Income farming TF True/False  
33 Income pension TF True/False true
34 Income self employment TF True/False  
35 Income SSI TF True/False true
36 Income social securty TF True/False  
37 Income unemployment TF True/False true
38 Income other 2 TF True/False true
39 Income no income TF True/False  
40 FIRST_NAME_OP TE Multiple Text Deefus
41 MIDDLE_NAME_OP TE Multiple Text dorfus
42 LAST_NAME_OP TE Multiple Text Doofus
43 Business Name OP TE Multiple Text  
44 Residence MC Multiple Choice Farm Labor Camp
45 Family problem MC Multiple Choice  
46 Housing Problem MC Multiple Choice  
47 Health Care MC Multiple Choice  
48 Marital Status MC Multiple Choice M
49 User Age NU Number 47
50 Adults served NU Number 2
51 Children served NU Number 3
52 User State MC Multiple Choice Ohio
53 Previous client MC Multiple Choice 101
54 User Home Phone NU Text (321) 321-3213
55 User Work Phone NU Text (432) 432-4324
56 User Cell Phone NU Text  
57 User Message phone NU Text  
58 User Middle Name TE Text Peter
59 User Last Name TE Text Mayer
60 OP NU Number  
61 No DeadlineTF True/False  
62 Handicapped TF True/False false
63 Other Party Zip NU Multiple Text  
64 PROBLEM_NU Text 1
65 CHILD_NU Text 4
66 ADULT_NU Text  
68 Employment Income NU Number 22
69 Farm Income NU Number  
70 FIP Income NU Number  
71 Child Support NU Number 55
72 Veterans benefits NU Number 6
73 Self Employment Income NU Number 8
74 Pension Income NU Number 7
75 Alimony Income NU Number 44
76 SSI Income NU Number 11
77 Social Security Income NU Number 12
78 Unemployment Income NU Number 9
79 Workers Comp Income NU Number 10
80 Other Income NU Number 15
81 Checking Asset NU Number 21
82 Savings Asset NU Number 22
83 Real Property Asset NU Number 24
84 Second Vehicle NU Number 25
85 Cash Asset NU Number 23
86 Pension NU Number 28
87 Income Workers Comp TF True/False true
88 Checking TF True/False true
89 Savings TF True/False true
90 Cash TF True/False true
91 Non-homestead property TF True/False true
92 Additional motor vehicles TF True/False true
93 Personal property TF True/False true
94 Pension_Other TF True/False true
95 Personal Property NU Number 27
96 No Assets TF True/False false
97 Income alimony TF True/False true
98 CHILD_FIRST_NAME_TE Multiple Text ChildOneChildTwoChildThree
99 CHILD_MIDDLE_NAME Multiple Text  
100 CHILD_LAST_NAME Multiple Text MayerMayerMayer
101 User Birth date Date 6/4/1961
102 Child SSN Multiple Text 111-11-1111222-22-2222333-33-3333
103 Child DOB Multiple Text 2/1/20002/2/20003/3/2000
104 Unaccepted problem MC Multiple Choice  
105 FIRST_NAME_Adult_TE Multiple Text James
106 MIDDLE_NAME_Adult_TE Multiple Text asd
107 LAST_NAME_Adult_TE Multiple Text Mayer
108 Poverty Amount Text 9800
109 Asset Amount Text  
110 Income veterans benefits TF True/False true
111 User Avatar Text  
112 Green card number TE Text  
113 Additional Status Information TE Text  
114 Birth date Date  
115 Papers Received DA Date  
116 Received DA Date  
117 Case Number TE Text  
118 Court TE Text  
119 Hearing DA Date  
120 Hearing Time TE Multiple Choice  
121 Income OWF TF True/False true
122 Income self-employment TF True/False true
123 Income other 2 TE Text  
124 Income other TE Text  
126 Abuse TF True/False false
127 No Deadline TF True/False  
128 Deadline Desc TL Text  
129 Deadline Desc TE Text  
130 Hearing Scheduled TF True/False  
131 Pension Problem MC Multiple Choice  
132 Other Housing TE Text  
133 OWF Income NU Number 33
134 Investment Income NU Number 13
135 Income social security TF True/False true
136 Income Other Decription TE Text paper route
137 FILESTATUS Multiple Choice  
138 Language MC Multiple Choice  
139 Primary Language MC Multiple Choice 2
140 Income investment TF True/False true
141 Court Papers TF True/False false
142 Court Papers DA Date  
143 Court Papers Case TE Text  
144 Court Papers Court TE Text  
145 Court Papers Hearing Date DA Date  
146 Court Papers Hearing Time TE Multiple Choice  
147 User Ethnicity Other TE Text  
148 Debt Credit Card TF True/False true
149 Debt Forclosed TF True/False true
150 Debt Judgement TF True/False true
151 Debt Utilities TF True/False true
152 Debt Loans TF True/False true
153 Debt Medical TF True/False true
154 Debt Mortgage TF True/False true
155 NOTA130 True/False false
156 Credit Card Payment Amount NU Number 3
157 Credit Card Owed Amount NU Number 30
158 Foreclosure Amount Owed NU Text 40
159 Foreclosure Payment NU Number 4
160 Judgements Amount Owed NU Number 50
161 Judgements Payment Amount NU Number 5
162 Utility Amount Owed NU Number 60
163 Utility Payment Amount NU Number 6
164 Loan Amount Owed NU Number 70
165 Loan Payment Amount NU Number 7
166 Medical Debt Amount Owed NU Text  
167 Medical Amount Owed NU Number 80
168 Mortgage Amount Owed NU Text 90
169 Mortgage Payment Amount NU Text 9
170 Medical Payment Amount NU Number 8
171 Expenses Medical TF True/False true
172 Expenses Child Care TF True/False true
173 Expenses Transportation TF True/False true
174 Expenses Other TF True/False true
175 NOTA139 True/False false
176 Expenses Medical NU Number 50
177 Expenses Child Care NU Number 51
178 Expenses Transportation NU Number 52
179 Expenses Other NU Number 53
180 NOTA39 True/False  
181 OPCount Text 1
182 NOTA113 True/False  
183 NOTA211 True/False true
184 Other_ADULT_NU Number 2
185 Adults_Helped_NU Number 1
186 Income Text  
187 Income TF Multiple Choice 1
188 No Income TF Multiple Choice  
189 Income MC Multiple Choice  
190 A2J_Bookmark Text  
191 Problem Type MC Multiple Choice Food Stamps
192 File status MC Multiple Choice  
193 Problem Type TE Multiple Choice  
194 Client marital status MC Multiple Choice  

Beside the illustrative or tutorial value of this transform, it could also be used by many word processing, spreadsheet and database applications that are able to import variables from HTML tables. The main value, however, is to demonstrate how to loop through the ANX XML and how the data can be transformed into any type of text output, not just more XML.

Here is the complete XSL transform file in a zip file in case you want to download it and modify it. I donate it to the public domain for anyone who wants to make use of it for any purpose whatsoever. If you have any questions or you want assistance with creating an XSL transform for your legal aid or court automation project, you can contact me at the following numbers or email...

John Mayer
Executive Director
Center for Computer-Assisted Legal Instruction / CALI
312-906-5307 (office)