XML Instance offers built-in processing for eXtensible Stylesheet Language: Transformations (XSLT). XSLT is an XML-based language used to transform the grammar (tags) and structure of XML documents. Common applications of XSLT include transforming XML into well-formed HTML for display in a web browser, transforming XML files based on one schema to files based on another, and extracting information from one XML document for use in another.
The XML document used to define XSLT transformations is called a stylesheet. XML Instance provides facilities for setting and editing stylesheets and for viewing stylesheet output in a web browser or within XML Instance.
Note: The DTD (industrial_sales.dtd), XML document (ind_sale.xml), and stylesheet (industrial_sales.xsl) used in the screen shots below are available in the Samples folders of the XML Instance folder (XI11).
Tip: Use a web browser (e.g. Internet Explorer or Netscape) in place of the internal java browser for the best results when viewing the output of XSLT transformations. A web browser can be selected in your preference settings.
Set Stylesheet
To add a stylesheet reference to an XML document, select the Set Stylesheet option from the Stylesheet menu. A second menu will appear allowing you to select a stylesheet from your computer file system or from a list of recently used stylesheets (Figure A).
Figure A-Setting an XSLT Stylesheet
Edit Stylesheet
Once a stylesheet has been set, it can be edited directly within XML Instance. To open a stylesheet for editing, select Edit Stylesheet from the Stylesheet menu. Because XSLT stylesheets are written in XML, stylesheet editing is performed using the normal XML document editing interface.
Preview
If you are using a stylesheet to transform your XML document into HTML, the resulting display can be viewed in a web browser by selecting the Preview option of the Stylesheet menu. For example, in Figures B through F, an XML document has been restructured as HTML in order to format the XML content within a table.
Tip: If a stylesheet has not been set, the Preview option will allow you to select a stylesheet for preview purposes only (i.e. a stylesheet reference will not be added to the document.) If a stylesheet has been set, the preview will use the set stylesheet.
NOTE: Your preferences settings allow you to specify how your XSLT transformations should be delivered to your browser. The HTTP localhost server option delivers the generated document to the browser from memory, while the Preview directory option first outputs the document to a file (stored in the XML Instance preview folder) which is in turn called by the browser. The preview directory option is required for Mac users, but can also be used by those wishing to save a copy of the HTML file generated in XML to HTML transformations. Files saved to the preview folder will never be erased by XML Instance.
Figure B - XML Document Displayed in Content View
Figure C - XML Document Displayed in Source View
|
|
Figure D - Stylesheet (excerpt) displayed in Content view |
Figure E- Stylesheet (excerpt) displayed in Source view |
Figure F - XML Transformation to HTML using XSLT
Transform
The Transform option of the Stylesheet menu maps the XML content form one tag set into another based on the rules of a stylesheet. The resulting XML document is loaded in a second window. Figure F depicts the XML content in Figure C transformed into an HTML tag set.
Note: If a stylesheet has not been set, the Transform option will allow you to select a stylesheet for transformation purposes only (i.e. a stylesheet reference will not be added to the document.) If a stylesheet has been set, the transformation will use the set stylesheet.
Figure F - Transformation to HTML tags