![]() |
![]() ![]() |
||||||||
|
|||||||||
Introduction |
You can use XML Script to convert XML into HTML so that you can view it in your browser. If you have a local web-server, you can do this dynamically, so that the HTML is generated every time you view it. In this example, however, we will save the HTML to a static file, so that it can be viewed like any other HTML. |
||||||||
Import the source data |
Use the _data command to open the existing XML file and read the contents in as data.
|
||||||||
Define the output file |
Use the _output command to create a new file which will contain the output generated by this script. mode="replace" tells the _output command to replace the file DisplayPO.html if one already exists.
|
||||||||
Defining the HTML format |
You will need to decide on the format of the HTML. The HTML shown below is standard, with one exception. Data values are not hard-coded: instead, we use interpolations which point to data items in the source XML. In this example we will display the contents of the Purchase Order. Note the interpolation in the BIG element, which will return the DealerID attribute of the Order root-level element. The BIG element includes both free text and an interpolation, which together will appear as text in the final output.
|
||||||||
Well-formed XML |
You must take care, when including HTML in an XML Script, that the
HTML is 'well-formed' XML. This is because the XML Script template
must itself be valid XML. What this means in practice is that each
opening HTML tag must be matched by a closing tag, or the element must
be represented by an empty-element tag. In this respect, XML
processors such as X-Tract are more 'fussy' about their input than
HTML browsers, who do not require certain HTML commands - for
instance, |
||||||||
Saving the script |
The finished script is shown below. Save the following script to a file in the directory where X-Tract is installed, and name it XMLtoHTML.xst.
|
||||||||
Running the script |
At the command line, type xtract XMLtoHTML.xst. This will create a file, DisplayPO.html, with the following content:
|
||||||||
Viewing the HTML |
Point your browser at the DisplayPO.html file.
The browser should display:
|
||||||||
Contents... | |||||||||
XML Script homepage | Documentation home | XML Script docs | Command list | Function list | X-Tract docs X-Stream, X-Tract and XML Script are trade marks of DecisionSoft Limited© Copyright 1998-2000 DecisionSoft Limited |