A project I was involved in required me to generate a HTML table from an XML file. Simple enough, right? The transformation would be easy; for each node create a new table row and each attribute would be a table cell. This would be a nice project to get introduced to XML and XSL.
The catch was that although the XML nodes were defined, the attribute names could vary from one time to the next. The column title had to reflect the dynamic attribute names and the HTML table had to be displayed in a certain format. So the challenge came when trying to figure out how to create the XSL and display empty cells when an attribute was not present, especially when I would not know the attribute name until runtime.
The XML is generated by a Sharepoint Web Service. The attribute names are names of custom fields created by the user in a Sharepoint Document Library. Sharepoint's list web service returns some standard attributes by default, those would always be known, as well as any columns specified by the query.
Hopefully this article will give you some ideas as to how to approach similar or more complicated XSL challenges.
The following was used in generating the example:
- Microsoft Visual Studio .NET 2003 (1.1 Framework)
- Microsoft Visual C#
- Web service running on IIS 5