Home > Online Product Documentation > Table of Contents > Working with XSLT Instructions in XSLT Mapper
As described in Graphical Support for Common XSLT Instructions and Expressions, you can create and work with XSLT instructions in the XSLT mapper using symbols called blocks. Each supported instruction is represented by a different block (symbols distinguish one block from another), and you complete the instruction's definition graphically, using drag and drop.
This section identifies the XSLT instructions supported by the mapper, their features, and how to use them. It covers the following topics:
The XSLT mapper represents the following XSLT instructions:
|
XSLT Instruction
|
Representation in the XSLT Mapper
|
|---|---|
|
xsl:value-of
|
|
|
xsl:for-each
|
|
|
xsl:if
|
|
|
xsl:choose
|
|
|
xsl:apply-templates
|
|
|
xsl:call-template
|
|
|
Note
|
|
You can create any XSLT instruction in the XSLT source, but only the instructions in Table 34 are represented graphically in the XSLT mapper. XSLT instructions that are not supported by the mapper have no graphical representation. |
All XSLT instruction blocks have at least three connectors, called
ports. Look at the
xsl:value-of instruction block shown in
Figure 222.
You use these ports to link source and target nodes, to perform processing on source document nodes, and to provide flow control as the result of a
xsl:choose or
xsl:if.
Ports are also part of XPath and Java function blocks, logical operator blocks, and text blocks. (See Processing Source Nodes for information on working with these types of blocks.)
After you have added an instruction block to the XSLT mapper, you need to complete its definition. You do this by linking the instruction block's input, output, and, optionally, flow ports to nodes and other blocks in the mapper.
The way you specify values for ports varies slightly between input ports and flow and output ports, but, generally speaking, you can either
|
Tip
|
|
To see the XSLT that is being generated based on the XSLT instruction you are creating, right click the instruction and select Go To Source from the shortcut menu. |
Stylus Studio interprets input ports differently for different XSLT instructions, as shown in Table 35:
|
XSLT Instruction
|
Meaning of Input Port
|
|---|---|
|
xsl:value-of
|
Used to define the value of the
select attribute. For example:
<xsl:value-of select="'Owen'">
|
|
xsl:for-each
|
Used to define the XPath expression for the
select attribute. For example:
<xsl:for-each select="books/book">
|
|
xsl:if
|
Used to define the value of the
test attribute. For example:
<xsl:if test="authors/author= 'Henry'">
See
xsl:if and xsl:choose to learn more about when to use this instruction.
|
|
xsl:choose
|
Used to define the value of the
test attribute of the nested
xsl:when element. For example:
<xsl:when test="contains(authors/author,'Marchese')">
See
xsl:if and xsl:choose to learn more about when to use this instruction.
|
|
xsl:apply-templates
|
Used to define the value of the
select attribute. For example:
<xsl:apply-templates select="subject"/>
|
|
xsl:call-template
|
Used to define the value of the
name attribute. For example:
<xsl:call-template name="newAuthorsTemplate"/>
|
You can specify values for input ports by:
If an xsl: instruction's attribute takes a literal or string value (such as
xsl:value-of select="'Recommended'"/, for example) and a value has been provided for the attribute, Stylus Studio fills the input port associated with that attribute with a deep red to indicate that a value has been specified.
Output ports for any of the following
xsl: instructions can be linked to the flow port of an instruction block:
You might decide you want a particular
xsl:for-each instruction executed only after performing a certain function, for example.
The shortcut menu appears.
The XSLT Instructions submenu appears.
The block for the instruction you selected appears in the mapper canvas.
Be aware of the following when working with XSLT instruction blocks in the XSLT mapper:
xsl:value-of instruction block and linking source and target document nodes. Stylus Studio displays the instruction block, but if you leave the
Mapper and later return to it, the block symbol for the
xsl:value-of instruction is replaced by a link with a small circle at its center, link the one shown in
Figure 223.
If you mouse over the circle, Stylus Studio displays the XSLT represented by the link (
xsl:value-of select="/books/book/@pubdate"/, for example).
This behavior also exists for text blocks created in the mapper that are not also linked to other blocks in the mapper. See Setting a Text Value.
xsl:for-each instruction, for example), it is not represented in the XSLT source, and it is removed from the XSLT mapper if you leave the
Mapper tab and then return to it.
You can change or specify the properties associated with an xsl: instruction by editing the instructions properties. Each xsl: instruction block (and blocks for XPath functions) is associated with a dialog box that allows you to edit its basic properties, like this
Function Property dialog box for the
contains function.
Stylus Studio displays the properties dialog box for the XSLT instruction or XPath function you selected from the mapper.
|
Note
|
|
The properties dialog box for
|
The
xsl:if instruction cannot express an else condition. It has a single input port, and a single output port, as shown in
Figure 225.
Once fully defined, the
xsl:if block generates code like the following:
If you need to express an else condition, use the
xsl:choose instruction block. This instruction block has two output ports by default, one for the
xsl:when test= attribute, and one for the one
xsl:otherwise element.
The
xsl:choose instruction block generates code like the following:
If you need to define more than one
xsl:when test= attribute, use the
xsl:choose properties dialog box for the
xsl:choose instruction block.
|
Note
|
|
Stylus Studio generates the
|
Use this procedure to
The
xsl:choose properties dialog box appears. Any attributes already defined for the
xsl:choose instruction you are editing are displayed in the
xsl:test conditions list box
A new entry field appears.
newCondition) with the XPath expression you want to use to define the
test= attribute and press Enter.
xsl:choose instruction to include the
xsl:otherwise element, click the Include
xsl:otherwise check box to deselect it.