XSLT - Edit XML
Data stored in XML files can be edited through internet browsers.
Open, Edit, and Save XML
Now, we will show you how to open, edit, and save XML files stored on the server.
We will use XSL to transform the XML document into an HTML form. The values of the XML elements will be written into HTML input fields. This HTML form is editable. After editing, the data is submitted back to the server, and the XML file is updated (this part is done by ASP).
XML File and XSL File
First, take a look at the XML document ("tool.xml") that will be used:
Next, take a look at the following style sheet ("tool.xsl"):
This XSL file will loop through the elements in the XML file and create an input field for each XML "field" element. The value of the "id" attribute of the XML "field" element is added to the "id" and "name" attributes of each HTML input field. The value of each XML "value" element is added to the "value" attribute of each HTML input field. The result is an editable HTML form containing the values from the XML file.
Then, we have a second style sheet: "tool_updated.xsl". This XSL file will be used to display the updated XML data. This style sheet does not output an editable HTML form but a static HTML table:
ASP File
In the "tool.xsl" file above, the action attribute of the HTML form is set to "edittool.asp".
The "edittool.asp" page contains two functions: the loadFile() function loads and transforms the XML file, and the updateFile() function updates the XML file:
Tip: If you are not familiar with how to write ASP, please study our ASP Tutorial.
Note: We are transforming and updating the XML file located on the server. This is a cross-platform solution. The client only receives HTML returned from the server - and HTML can run on any browser.