Use a simple XSL style sheet to convert XML data to HTML. With the continuous evolution of XML specification, it seems necessary to meet each person in the new version; unfortunately, simple conversion has always been plagued.
Suppose I have an XML data representing a page content, now I want to convert its content into layout. Here is the XML I want to convert:
XML Version = '1.0'?>
xml-stylesheet type = "text / xsl" href = "article.xsl"?>
folder 1 text>
file 1 text>
String type>
50 Length>
Some Data Value>
data>
field>
fields>
file>
files>
folder>
folders>
xml>
This content represents a set of folders, files, and domains. Each folder contains files, each file contains domains for entering data. Each folder in the folder group will behave as a TR element of a TABLE's first row and a TD element. Each file in the file group will represent a TR element of the first row of a Table element nested in the folder TR element and a TD element. Each domain in the domain group will appear as an Input in the relevant file.
In order to achieve this, we need to traverse XML then build a table according to XSL.
Here is the XSL used for this conversion:
XML Version = "1.0"?>
XMLns: XSL = "http://www.w3.org/1999/xsl/transform" Version = "1.0"
In the Stylesheet tag, we set a few namespaces, including the XSL namespace defined all XSL conversion tags. Ability to create MSXML namespaces that can be used in the style sheet. I use it to get all the child elements to get a COLSPAN property set of a TD tag. The FN namespace for joining a set of users defined functions, which is created by MSXML: Script Element.
Then we create external Table and the first TR. In TR, I created a TD for each folder specified in XML. I use the XSL: Element tag because it allows me to add a custom property or perform a function to set an attribute for the Colspa Attribute in another TD element.
After creating the required TD for each folder, I started to create TR for each folder. I only add a TD to this TR, but I set it with its colSpan property to equal to the number of file clips in the folder group plus one. Many out is to fill the air in a table in a fixed layout style.
In order to get colspan, I passed the current context (here "." Specified) and the name I want to calculate. In my function, I get the current context, ParawAntNode, and the number of nodes specified in the XPath query. The function is then returned to this quantity plus one to fill TD.
With this TD, I embed another table, which contains each file in the file group. From this point, the process is the same as the external Table conversion. The final step is to add a domain in each file. This time I didn't create an embedded table, just add these domains to the current TD.
Once I finish the general layout, I can start adding user interface features, such as hiding other folders and file lines until the user clicks the relevant tab. This feature can be implemented by writing a script that supports this feature, add an OnClick XSL: Attribute element to folder and file TD elements, and then set it to the name of the script function.
Finally, after the general function is complete, you can add Class XSL: Attributes and add ClassNames to the Style or CSS to get the look you want.
This example creates a foundation for the FILE-Folder-Field view used in the deployment Web data solution. Access MSDN find more information about Microsoft's XML specification.