XSLT
Transformations with XSLT stylesheets
Background
With this feature you have the possibility to transform files and entire folders by means of XSLT stylesheets as well as to pass on parameters.
Further links on the subject XSLT:
data2type: XML technologies → XSLT
Modifications of the transformation process
You may make various settings on the Saxon XSLT processor used.
A description of these possibilities can be found in the following section:
data2type: antillesXML help → Settings
Tab: Single
Transformations of single files
Here you can see how a single file can be transformed with XSLT into a new output file. Usually, such a file is already a XML file.
Calling up the XSLT window
- Select the XSLT entry in the XSL menu.
→ The XSLT window appears. - → The Single tab is already selected by default with the first call.
If this is not the case, please select now the Single tab.
Selection of the input document
As input document you need a file whose elements and data shall be transformed.
Depending on the purpose of application and the XSL stylesheet used, this file may consist of different forms of processible data.
- Press the button.
→ The Open dialogue appears.
- Choose the path to the input document in your file system.
- Click Open.
Indication of the stylesheet file
As stylesheet you need a XSLT file which transforms the input document into the new output format.
The parameters set in the stylesheets can later be modified in antillesXML. In addition, further parameters can be added.
- Press the button.
→ The Open dialogue appears.
- Choose the path to the stylesheet in your file system.
- Click Open.
Selection of the target document
As target document you need a file in which the transformation can be written in.
- Press the button.
→ The Save as dialogue appears.
- Choose the path to the target file in your file system.
- Enter a unique name for the target document under File name.
XSL → XSLT → Single → Selection of the target document →
<xsl:output>
The top-level element
<xsl:output>
basically indicates which kind of output the processor has to generate. Three output formats are possible: XML, HTML and text and in XSLT 2.0 also XHTML. They are indicated as values of themethod
attribute. The standard output of XSLT is XML. Except there is a HTML tag in the document, then HTML 4.0 is generated.Further links regarding the
<xsl:output>
element:
data2type: XML technologies → XSLT → XSLT introduction → The output element<xsl:output method="xml|html|text|name"/>
Please refer to the target format indicated in the stylesheet when choosing the file extension.
- Click Save.
Starting the transformation
Press the button.
→ The target document has been written to the location selected by you.
In addition, the result of the transformation is shown in the Statistics window in the Results tag.
In case error messages occur during the transformation, they are displayed in the Statistics window in the Log tag.
Tab: Folder
Transformations of entire folders
Here you can see how entire folders are transformed with XSLT into new output files.
Usually, such data are already XML files.
Calling up the XSLT window
- Select the XSLT entry in the XSL menu.
→ The XSLT window appears.
- Select the Folder tab.
Selection of the input folder
As input folder you need a folder whose files shall be transformed.
Depending on the purpose of application and the XSL stylesheet used, this folder may consist of different forms of processible files.
- Press the button.
→ The Search folder dialogue appears.
- Choose the path to the input folder in your file system.
- Click OK.
Indication of the stylesheet file
As stylesheet you need a XSLT file which transforms the input documents into the new output format.
- Press the button.
→ The Open dialogue appears.
- Choose the path to the stylesheet in your file system.
- Click Open.
Selection of the target folder
As target folder you need a folder in which the target documents are stored.
- Press the button.
→ The Search folder dialogue appears.
- Choose the path to the target folder in your file system.
- Click OK.
Starting of the transformation
- Press the button.
→ The target documents have been written to the location selected by you.
In addition, the result of the transformation is displayed in the Statistics window in the Results tab.
In case error messages occur during the transformation, they are displayed in the Statistics window in the Log tab.
Tab: Pipeline
Transformations with several XSL stylesheets
Here you can see how to transform an input document with several, successive stylesheets.
With the help of this feature, processing loops can be realised. After each transformation, the input document is passed on to the following stylesheet in virtual form and passes through a further transformation process.
Only after the sequential processing by an included stylesheet the final target document is generated and stored in the folder.
Further links on the subject XSL pipelines:
Sam Page Blog: Using XML → XSL Pipeline Processing
Calling up the XSLT window
- Select the XSLT entry in the XSL menu.
→ The XSLT window appears.
- Select the Pipeline tab.
Selection of the input document
As input document you need a file whose elements and data shall be transformed.
Depending on the purpose of application and the XSL stylesheet used, this file may consist of different forms of processible data.
- Press the button.
→ The Open dialogue appears.
- Choose the path to the input document in your file system.
- Click Open.
Selection of the target document
As target document you need a file in which the transformation can be written in.
- Press the button.
→ The Save as dialogue appears.
- Choose the path to the target folder in your file system.
- Enter a unique name for the target document under File name.
XSL → XSLT → Pipeline → Selection of the target document →
<xsl:output>
The top-level element
<xsl:output>
basically indicates which kind of output the processor has to generate. Three output formats are possible: XML, HTML and text and in XSLT 2.0 also XHTML. They are indicated as values of themethod
attribute. The standard output of XSLT is XML. Except there is a HTML tag in the document, then HTML 4.0 is generated.Further links regarding the
<xsl:output>
element:
data2type: XML technologies → XSLT → XSLT introduction → The output element<xsl:output method="xml|html|text|name"/>
Please refer to the target format indicated in the last stylesheet when choosing the file extension.
- Click Save.
Indication of the stylesheet files
As stylesheet you need one or more XSLT files which transform the input document into the new output format.
Manual selection of the stylesheets
- Generation of the first stylesheet
- Double-click the empty field in the Stylesheets column.
→ The Open dialogue appears. - Choose the path to the stylesheet in your file system.
- Click Open.
- Double-click the empty field in the Stylesheets column.
- Generation of the following stylesheets
- Double-click the newly generated empty field in the Stylesheets column.
→ The Open dialogue appears. - Choose the path to the stylesheet in your file system.
- Click Open.
- Double-click the newly generated empty field in the Stylesheets column.
- Removing of stylesheets in the list entries
Removing of single rows
- Select the stylesheet to be removed with a click in the first column before the appropriate row.
→ The appropriate row is now highlighted in blue. - In order to remove the row, press now the Delete key.
→ Now, the appropriate row is deleted.
Removing of several rows at the same time
- In case the stylesheets shall be selected individually:
- Press and hold the Ctrl key.
- Select the stylesheets to be removed with a click in the first column before the appropriate row.
→ The appropriate rows are now highlighted in blue. - In order to remove the rows, press now the Delete key.
→ Now, the appropriate rows are deleted.
- In case the stylesheets lie below each other:
- Press and hold the Shift key.
- Select the top and bottom stylesheet to be removed with a click in the first column before the appropriate row.
→ The appropriate rows are now highlighted in blue. - In order to remove the rows, press now the Delete key.
→ Now, the appropriate rows are deleted.
- Select the stylesheet to be removed with a click in the first column before the appropriate row.
- Activation & deactivation of the stylesheets in the pipeline
Activation of the stylesheets in the pipeline
Activate the check box in the Include Stylesheet column next to the stylesheets to be used.
→ The stylesheets having a check mark are part of the pipeline chain.Deactivation of the stylesheets in the pipeline
Deactivate the check box in the Include Stylesheet column next to the stylesheet to be used.
→ Only the stylesheets having a check mark are part of the pipeline chain. - Saving a pipeline in a file
You may save the generated pipelines to a XML file and then reuse them.
XSL → XSLT → Pipeline → Saving a pipeline → The structure of the pipeline in XML
<?xml version="1.0"?>
<ArrayOfString xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<string>
C:\workspace\antillesXML\testFiles\XSL\XSLT\style\style_01.xsl
</string>
<string>
C:\workspace\antillesXML\testFiles\XSL\XSLT\style\style_02.xsl
</string>
<string>
C:\workspace\antillesXML\testFiles\XSL\XSLT\style\style_03.xsl
</string>
<string>
C:\workspace\antillesXML\testFiles\XSL\XSLT\style\style_04.xsl
</string>
</ArrayOfString>
The XML file which is generated for the pipeline contains the paths to the stylesheets. The sequential order of the pipline is taken into account.
The XML file does not contain information regarding the stylesheets being already activated for the transformation process.
→ These have to be reactivated manually.
Selection of the already generated pipeline
- Press the button.
→ The Open dialogue appears.
- Choose the path to the already generated pipeline in your file system.
- Click Open.
- Activate the required stylesheets in the pipeline.
Starting the transformation
Press the button.
→ The stylesheets are now run through in the pipeline and the target document is written to the location selected by you.
In addition, the result of the transformation is shown in the Statistics window in the Results tab.
In case error messages occur during the transformation, they are displayed in the Statistics window in the Log tag.
Tab: Parameters
Transformations with passing of parameters
Here you can see how to pass parameters to a XSLT stylesheet.
Requirements for the passing of parameters:
Select the required tab in the XSLT window and there the files or folders needed for the transformation process.
Then select the Parameters tab.
Passing the parameters
XSL → XSLT → Parameters → <xsl:param>
Parameters can be found in the XSLT stylesheet in the following form:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:param name="collection"/>
<html>
<body>
<h1><xsl:value-of select="$collection"/></h1>
Here a parameter is declared as global element.
The argument for the parameter passed on by the XSLT processor is called up within the <h1>
element.
Further links regarding the <xsl:param>
element:
data2type: XML technologies → XSLT → XSLT 1.0 reference → xsl:param
">w3schools: XSLT → <xsl:param>
element
Indication of the parameter values
The parameter names of the previously selected XSLT styesheets are listed in the left column under Parameter.
Enter the value to be passed on to the appropriate parameter in the right column under Value.
Saving the parameter values
Press the button.
→ During the next transformation process, the values are passed on as arguments to the XSLT processor.
Switch back to the previously selected tab and start the transformation.
XSL → XSLT → Parameters → <xsl:param>
The result of the passing of parameters from our example:
<html> <body> <h1>data2type</h1>
The argument passed on during the transformation can now be found as headline in the HTML code.