This tutorial assumes:
In the Perl Tutorial, a Perl program converts a text file containing exported email messages to an XML file. In this tutorial, XSLT converts the XML file to HTML. Note that you do not need to complete the Perl Tutorial before doing the XSLT Tutorial. Each tutorial can be completed independently. In this tutorial you will:
From the Help > Tutorials menu, click XSLT Tutorial, or open the xslttutorial.kpf_ file from the samples/xslttutorials_ subdirectory of Komodo's user data directory
The tutorial project will open in the Places sidebar.
In the Placessidebar, double-click the files mailexport, mailexport.xml, and mailexport2html.xsl. These files open in the Editor Pane; a tab at the top of the pane displays each of their names.
In this step, you will analyze the XSLT program on a line-by-line basis. Open the XSLT Tutorial Project and associated files as described in the previous step. Be sure Line Numbers are enabled in Komodo (View|View Line Numbers). Be sure the mailexport2html.xsl file is displayed in the Komodo Editor Pane.
xsl:to prevent confusion with user-defined element names and non-XSLT elements
xsl:outputcontrols the appearance of the generated output; for example, the presence of this line generates a
METAdeclaration in the head of the HTML output
|**Komodo Tip**: Notice that different types of language elements are displayed in different colors. Adjust the display options for language elements in the [Preferences](../prefs#prefs_top) dialog box.|
|**XSLT Pointer**: Processing routines in XSLT programs are enclosed in opening and closing tags similar to those in XML.|
templateis the main processing element in an XSLT program
match="/"attribute specifies that the template is selected when the document element is processed
|**XSLT Pointer**: XSLT commands have (up to) four components: namespace ("xsl"), element ("template"), attribute(s) ("match="), and attribute value(s) ("/").|
|**XSLT Pointer**: XSLT uses XPath expressions to select data from XML documents. On line 6, `match="/"` selects a "node" in the XML document's hierarchy, rather than a specific item of data.|
<HEADER>tags in the XML document are processed
value-ofstatement selects content contained in the
<SUBJECT>tag and writes it to the output document
|**Komodo Tip**: Click the minus symbol to the left of line 19\. The entire section of nested code is collapsed. This is called [Code Folding](../editor#Folding).|
call-templateroutine causes the XSLT program to proceed to the template
formatEmailon line 51; after completing the
formatEmailroutine, processing returns to line 23
with-paramindicates that the parameter
addressshould be applied to the contents of the
<DESTADDRESS>XML tag on lines 26 to 28
**XSLT Pointer**: Notice the `
` HTML tag on line 25\. XML and XSLT treat all tags as container tags that have both opening and closing elements. However, some HTML tags (like `
` and ``) stand alone, and do not require a closing tag. They are represented with a closing slash. XSLT tags also use a closing slash if they are not a tag pair (as shown on line 23).
apply-templatestag in line 12 is encountered, processing jumps to line 33
HEADERnode is selected and processing jumps to line 18
|**XSLT Pointer**: Comments in XSLT programs are enclosed in the tags ``, the same as in HTML.|
BODYtag are placed in the HTML tags
|**Komodo Tip**: XSLT programs and XML input documents must be "well-formed" in order to perform transformations. Komodo's [Background Syntax Checking](../editor#Linting) makes it easy to identify and fix coding errors.|
addressparameter contents are determined on lines 23 and 27
addressparameter are converted to a variable and concatenated with the text that constitutes a valid email address reference in HTML
To start, generate program output by running the program through the debugger without setting any breakpoints.
This section reviews how to add breakpoints to the program and "debug" it. Adding breakpoints lets you to run the program in parts, making it possible to watch variables and view output as they are generated. Before beginning, be sure that line numbering is enabled in Komodo (View|View Line Numbers).
|**Komodo Tip**: Debugger commands can be accessed from the **Debug** menu, by shortcut keys, or from the **Debug Toolbar**. For a summary of debugger commands, see the [Debugger Command List](../debugger#How_use_Debugger).|
|**Komodo Tip**: Breakpoints can be set at any time. An enabled breakpoint is a solid red circle. A disabled breakpoint is a white circle with a red outline. Click once in the gray margin to enable a breakpoint. Click an enabled breakpoint once to disable it.|
xsl:apply-templates), it looked for a template that matched the top node in the XML document (
<EMAILCOMMENTS>). When no matching template was found, it proceeded to the next node in the XML document (
<EMAIL>) and found a matching template on line 33.
xsl:value-ofstatement selects the contents of the
<SUBJECT>field on line 7 of the XML file and places it within the HTML tags on lines 19 and 21.
formatEmailon line 45. Continue to step in until line 49 is processed. The
formatEmailtemplate is processed with the
addressparameter on line 46. This routine processes the contents of the
<ORIGADDRESS>node in the XML document. In order to generate the hyperlink in the output HTML document, lines 48 and 49 concatenate the string
mailto:with the contents of the
The W3C (World Wide Web Consortium) specifications are available online:
There are many XSLT tutorials and beginner XSLT sites on the Internet, including:
© 2017 ActiveState Software Inc. All rights reserved. ActiveState®,
Komodo®, ActivePerl®, ActivePython®, and ActiveTcl® are registered
trademarks of ActiveState.
All other marks are property of their respective owners.