XSLT in Arbortext APP
|
![]() |
|
|
SummaryThis chapter details the specifics of using the XSLT standard within the Arbortext APP environment. |
1 |
Introduction |
XSLT provides a method to transform and re-use XML data in a variety of formats and contexts. XSLT therefore increases document portability and transference across hardware and software. Arbortext APP and XSLT combine to make a flexible system for handling XML data and presentation. |
![]() |
Please note that this document is not a comprehensive technical overview of XSLT. This is because XSLT is well documented and there are many external resources for learning XSLT. This document assumes that the reader has some prior knowledge of XSLT and therefore the purpose is to provide a specific description of XSLT in Arbortext APP. It is assumed that the reader is familiar with XML. It is recommended that you read the XML section before reading the XSLT section. |
For more information see the XML in APP chapter. |
2 |
Overview |
This chapter provides an overview of XSLT and how it works in conjunction with Arbortext APP. XSL stands for Extensible Stylesheet Language. It is an XML application that transforms XML documents. |
XSL is split into two languages: |
|
![]() |
This chapter covers XSLT, for more information on XSL-FO see the XSL-FO in 3B2 chapter. |
XSLT is an official recommendation of the World Wide Web Consortium (W3C). It provides a flexible, functional, declarative programming language for transforming XML documents into other text based documents, for example an HTML document, another XML document or a mark-up of your choice. XSLT is a tree structured hierarchical transformation language that uses XPath to select elements and text which are output from the XML. An XSLT stylesheet is a well-formed XML document used to define the rules which an XSLT processor uses to transform a number of XML instances. |
XSLT has the following features: |
|
2.1 |
XSLT Processing |
XSLT processing enables you to apply template rules to selected nodes of XML documents. XSLT uses XML and XPath to transform XML source trees in to results trees. |
2.2 |
XSLT Transformation Example |
Below is a simple example of an XSLT transformation that converts one input XML instance into an output XML instance. |
![]() |
A similar process can be used to transform an XML document into the format of your choice. |
2.3 |
Input XML |
In this example the following Input XML is used: |
|
2.4 |
XSLT Stylesheet |
Below is an example of an XSLT stylesheet: |
|
Below is an explanation of each line in the above stylesheet: |
|
|
|
|
|
|
|
|
|
|
|
2.5 |
Output XML |
Below is the output XML that is created when the above stylesheet is applied to the input XML: |
|
3 |
XSLT Processing in Arbortext APP |
There are many potential uses of XSLT and Arbortext APP, for example it is possible to: |
|
3.1 |
Libxml parser |
The XSLT processing is used in the same manner as with the previous 3B2–XML processing, i.e. through the “txform” macro. If the document is being parsed with the libxml parser, then the libxml XSLT processor will automatically be used. Should the old XSLT processor need to be used for backward compatibility, then the 3B2–XML parser must be selected first. Any extensions and functionality mentioned in related chapters, for example XInclude or custom functions, also apply equally to XSLT. |
For more information on parsers in Arbortext APP see the XML inArbortext APP- Parsers and processors chapter. |
3.2 |
The txform macro |
XSLT transformations are controlled using the txform command. This macro allows you to specify and control the transformation parameters. |
The txform macro requires the following parameters: |
|
The txform macro controls more than just the XSLT type of transformations. It is also possible to specify the frequency of the transformation required, for example transformations can be performed automatically or as a one off. Other no-XSLT transformation can be performed such as using a translation map or a search and replace mini-script. |
It is also possible for multiple transformations to be applied simultaneously to one XML stream to generate multiple output streams with different formats. |
For more information see txform |
3.2.1 |
Passing Parameters |
Should the XSLT stylesheet require parameters to be passed in, i.e. they have <xsl:param> top-level elements, then it is possible to specify a parameter control stream that defines or overrides the default parameters in the stylesheet. |
However, in Arbortext APP, it is also possible to pass parameter values to a stylesheet using a Parameter Control Stream. This enables stylesheets and their output to be controlled and customised by a Arbortext APP script. |
![]() |
It is only possible to pass parameters to the XSLT Parameter Control Stream when using the libxml parser. |
Below is the syntax for a Parameter Control stream: |
Parameter name="parameter value" |
Below is an example of passing a Parameter Control stream: |
fact="real life" |
fiction="made up" |
Below is an example of the XSLT stylesheet that the control stream can be applied to: |
|
|
|
|
|
|
|
|
![]() |
Only one parameter is permitted per line, and the quotes around the value must be included in the control stream for the value to be recognised, but they do not appear when the value is used inside the XSLT stylesheet. To use the parameter control stream in a transformation, it should be specified as an input parameter to the txform dialogue or macro. |
3.3 |
Viewing transformation properties |
When you have set up a transformation on a tag using the txform command, it is possible to view its properties using the following syntax: |
txform "result_tagname |
The Tag Transform dialogue box will appear and all your previous transformation settings will be displayed in the entry boxes. |
It is also possible to see this information by selecting [Document/Tags/Browse Tags] to invoke the Browse Tags dialogue box. Select the |
3.4 |
The tttaginfo command |
Sometimes you may want to use information about an XSLT transformation in a script. To this end it is possible to use the ttaginfo macro to populate the ^ttaginfo_ variables for tag. The variables generated by an XSLT will have the following values set: |
|
For more information see ttaginfo |
3.5 |
Error Reports |
3.5.1 |
XML Error Streams |
Whenever there is an error the xslterr:namespace is created. Arbortext APP creates a text stream of the same name as the error namespace. This contains any error messages with the same name as the XSLT stream, of type 'XML Error' (.xe). |
3.5.2 |
Viewing Parser Errors |
To view parser errors: |
Select [XML/View Parser Errors] |
This invokes the Browse Tags dialogue box showing all of the '.xe' streams. |
3.5.3 |
The txmlerror macro |
It is also possible to use the txmlerror macro to view parser errors. |
For more information see txmlerror |
3.5.4 |
Saving XML Error Streams |
To specify whether to save the error stream with the XML document: |
|
3.5.5 |
Error Bar |
In order to see the last error code from the libxml parser you can use the libxml Error Bar. |
To enable the libxml Error Bar: |
|
Alternatively, enable the libxml Error Bar using the toolbars macro as shown below: |
|
The following is an explanation of the two fields in the libxml Error Bar: |
|
3.6 |
Inline XSLT Processing (V9) |
Should only a fragment of an XML document require transformation, then it is possible to do an XSLT transform inline during formatting in a show-string. The syntax for this is as follows: |
|
where "xml" is the name of the source XML, "xslt" is the name of the stream containing the XSLT stylesheet, "param" is the name of the parameter control stream, and "nodeid" or "path" are either the number or the location path of the nodes in the source XML to be transformed. |
The input node is treated as if it occurs in a separate XML document by itself, along with its children. If a location path is specified and the path contains multiple nodes, then the XSLT is processed against each node individually with the results being combined and formatted together. |
Any errors occurring during the transformation are returned by the function variable instead of the output. |
See also xslt |
3.7 |
XSLT Specification Compliance |
The XSLT processing is nearly fully compliant with the W3C XSLT 1.0 specification. |
3.8 |
XSLT Elements |
The XSLT elements available in Arbortext APP are shown below: |
|
3.9 |
XSLT Functions |
The XSLT functions available in Arbortext APP are shown below: |
|
4 |
EXSLT |
EXSLT is an initiative to provide extensions to XSLT. Libxml supports the EXSLT extension functions for use in XSLT processing in Arbortext APP. |
The EXSLT extension functions are accessed by declaring the relevant namespace for the EXSLT module: |
|
where <module> is the name of the required module. |
4.1 |
EXSLT Functions |
The following EXSLT functions are provided by the libxml parser in Arbortext APP: |
|
![]() |
All functions listed above, with the exception of exsl:document() are available to use in XPath expressions in the specified namespace providing the "x3b2 namespace" option is selected. |
5 |
Example XSLT transformation |
Below is an example of a XSLT transformation from XML to HTML. |
5.1 |
Input XML |
Below is the Input XML. It is a basic XML stream that will be transformed into HTML Output using an XSLT transformation within Arbortext APP. |
|
5.2 |
XSLT Stylesheet |
Below is the XSLT stylesheet that transforms the XML Input into HTML. |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
5.3 |
Output HTML |
Below is the HTML Output that has been transformed from XML. |
|
6 |
Further Information and References |
6.1 |
Associated documentation |
|
![]() |
If using HTML (online or local) documentation, mouse over the links above for a summary. |
6.2 |
Internet Resources |
The World Wide Web Consortium (W3C) XSLT activity and information: |
General and in-depth information about XML and XSLT: |
News, education, and information about XML in industrial and commercial settings: |
Information about EXSLT: |
6.3 |
Books/Literature |
XSLT |
Doug Tidwell |
Published by O'Reilly. |
XSLT Programmer's Reference |
Michael Kay |
Wrox Press Ltd. |
XSLT For Dummies |
Richard Wagner |
Published by Hungry Minds Inc. |
7 |
Subject Index |
![]() |
Subject index only applicable to the PDF version. |
Document created on 17-Sep-2002, last reviewed on 03-Oct-2005 (revision 3)