Jesper Tverskov, February 27, 2006

XSLT 1.0 Element Syntax Summary (a-z)

a-z | group

This element syntax summary is an enhanced and a more user-friendly version of the syntax summary in the XSLT 1.0 Recommendation. The headings link to the spec for additionel information.

1. xsl:apply-imports

<!-- Category: instruction --> [1]
<xsl:apply-imports/>

2. xsl:apply-templates

<!-- Category: instruction --> [2]
<xsl:apply-templates select=node-set-expression mode=qname>
  <!-- Content: (xsl:sort | xsl:with-param)* -->
</xsl:apply-templates>

3. xsl:attribute

<!-- Category: instruction --> [3]
  <xsl:attribute name={qname} namespace={uri-reference}>
<!-- Content: template -->
</xsl:attribute>

4. xsl:attribute-set

<!-- Category: top-level --> [4]
<xsl:attribute-set name=qname use-attribute-sets=qnames>
  <!-- Content: xsl:attribute* -->
</xsl:attribute-set>

5. xsl:call-template

<!-- Category: instruction -->
<xsl:call-template name=qname>
  <!-- Content: xsl:with-param* -->
</xsl:call-template>

6. xsl:choose

<!-- Category: instruction --> [5]
<xsl:choose>
  <!-- Content: (xsl:when+, xsl:otherwise?) -->
</xsl:choose>

7. xsl:comment

<!-- Category: instruction -->
<xsl:comment>
  <!-- Content: template -->
</xsl:comment>

8. xsl:copy

<!-- Category: instruction --> [6]
<xsl:copy use-attribute-sets=qnames>
  <!-- Content: template -->
</xsl:copy>

9. xsl:copy-of

<!-- Category: instruction -->
<xsl:copy-of select=expression/>

10. xsl:decimal-format

<!-- Category: top-level -->
<xsl:decimal-format name=qname decimal-separator=char grouping-separator=char infinity=string minus-sign=char NaN=string percent=char per-mille=char zero-digit=char digit=char pattern-separator=char/>

11. xsl:element

<!-- Category: instruction -->
<xsl:element name={qname} namespace={uri-reference} use-attribute-sets=qnames>
  <!-- Content: template -->
</xsl:element>

12. xsl:fallback

<!-- Category: instruction -->
<xsl:fallback>
  <!-- Content: template -->
</xsl:fallback>

13. xsl:for-each

<!-- Category: instruction -->
<xsl:for-each select=node-set-expression>
  <!-- Content: (xsl:sort*, template) -->
</xsl:for-each>

14. xsl:if

<!-- Category: instruction -->
<xsl:if test=boolean-expression>
  <!-- Content: template -->
</xsl:if>

15. xsl:import

<!-- Category: top-level --> [7]
<xsl:import href=uri-reference/>

16. xsl:include

<!-- Category: top-level -->
<xsl:include href=uri-reference/>

17. xsl:key

<!-- Category: top-level --> [8]
<xsl:key name=qname match=pattern use=expression/>

18. xsl:message

<!-- Category: instruction --> [9]
<xsl:message terminate="yes"|"no">
  <!-- Content: template -->
</xsl:message>

19. xsl:namespace-alias

<!-- Category: top-level -->
<xsl:namespace-alias stylesheet-prefix=prefix|"#default" result-prefix=prefix|"#default"/>

20. xsl:number

<!-- Category: instruction --> [10]
<xsl:number level="single"|"multiple"|"any" count=pattern from=pattern value=number- expression format={string} lang={nmtoken} letter-value={"alphabetic"|"traditional"} grouping-separator={char} grouping-size={number}/>

21. xsl:otherwise

<!-- Category: part of instruction element -->
<xsl:otherwise>
  <!-- Content: template -->
</xsl:otherwise>

22. xsl:output

<!-- Category: top-level --> [11]
<xsl:output method="xml"|"html"|"text"|qname-but-not-ncname version=nmtoken encoding=string omit-xml-declaration="yes"|"no" standalone="yes"|"no" doctype-public=string doctype-system=string cdata-section-elements=qnames indent="yes"|"no" media-type=string />

23. xsl:param

<!-- Category: top-level --> [12]
<!-- Category: instruction -->
<xsl:param name=qname select=expression >
  <!-- Content: template -->
</xsl:param>

24. xsl:preserve-space

<!-- Category: top-level -->
<xsl:preserve-space elements=tokens/>

25. xsl:processing-instruction

<!-- Category: instruction -->
<xsl:processing-instruction name={ncname}>
  <!-- Content: template -->
</xsl:processing-instruction>

26. xsl:sort

<!-- Category: part of instruction element --> [13]
<xsl:sort select=string-expression lang={nmtoken} data-type={"text"|"number"|qname-but-not-ncname} order={"ascending"|"descending"} case-order={"upper-first"|"lower-first"}/>

27. xsl:strip-space

<!-- Category: top-level --> [14]
<xsl:strip-space elements=tokens />

28. xsl:stylesheet

<!-- Category: document -->
<xsl:stylesheet id=id extension-element-prefixes=tokens exclude-result-prefixes=tokens version=number>
  <!-- Content: (xsl:import*, top-levels) -->
</xsl:stylesheet>

29. xsl:template

<!-- Category: top-level --> [15]
<xsl:template match=pattern name=qname priority=number mode=qname>
  <!-- Content: (xsl:param*, template) -->
</xsl:template>

30. xsl:text

<!-- Category: instruction --> [16]
<xsl:text disable-output-escaping="yes"|"no">
  <!-- Content: #PCDATA -->
</xsl:text>

31. xsl:transform

<!-- Category: document --> [17]
<xsl:transform id=id extension-element-prefixes=tokens exclude-result-prefixes=tokens version=number>
  <!-- Content: (xsl:import*, top-levels) -->
</xsl:transform>

32. xsl:value-of

<!-- Category: instruction --> [18]
<xsl:value-of select=string-expression disable-output-escaping="yes"|"no"/>

33. xsl:variable

<!-- Category: top-level --> [19]
<!-- Category: instruction -->
  <xsl:variable name=qname select=expression>
<!-- Content: template -->
</xsl:variable>

34. xsl:when

<!-- Category: part of instruction element -->
<xsl:when test=boolean-expression>
  <!-- Content: template -->
</xsl:when>

35. xsl:with-param

<!-- Category: part of instruction element --> [20]
<xsl:with-param name=qname select=expression>
  <!-- Content: template -->
</xsl:with-param>

36. Table of Syntax Vocabulary

Table 1: Syntax Vocabulary

No

Syntax

    Explanation

1

Category: document

This category is my invention. It is not in the spec giving os elements "out of category".

  The outer-most element of the XSLT stylesheet.

2

Category: top-level

  1. Most be a child of xsl:stylesheet.
  2. All top-level elements are optional but we need at least one xsl:template to get things done.
  3. The order of top-level elements is not important with one exception: if xsl:import is used, it must be the first top-level element.
  4. All top-level elements except xsl:output, xsl:preserve-space and xsl-strip-space can be used more than once.

3

Category: top-level/instruction

The xsl:variable and xsl:param elements can be used both as top-level and instruction. In xsl:template the xsl:param element must be the first child if used.

4

Category: instruction

Can only be used inside xsl:template and inside many of the instruction elements.

5

Category: part of instruction

This category is my invention. It is not in the spec giving us elements "out of category".

Can only be used inside one or two specific instruction elements.

  1. xsl:otherwise inside xsl:choose.
  2. xsl:sort inside xsl:for-each and inside xsl:apply-templates.
  3. xsl:when inside xsl:choose.
  4. xsl:with-param inside xsl:call-templates and inside xsl:apply-templates.

6

?

Optional or one time.

7

+

One or many times.

8

*

Optional or one or many times.

9

|

Alternative or choice.

10

Bold

Attributes in both bold and red are mandatory (required).

11

Content: template

The element can contain other elements and or markup/text. Not to be confused with xsl:template.

12

{...}

The curly braces indicate that the value is an "attribute value template". A sort of "xsl:value-of" used inside an attribute. Often a variable is used like: <xsl:element name="{$myName}"/>.

13

qname

Just a name you make up yourself. E.g.: <xsl:variable name="x"> or <xsl:template mode="toc">. "X" and "toc" are qnames.

14

tokens

A whitespace separated list of "names". E.g.: <xsl:preserve-whitespace elements="headlines summary description"/>

15

nmtoken

"Others" have decided what "names" you can use. E.g.: The version attribute in xsl:stylesheet can be version="1.0" or "2.0". "1.0" and "2.0" are nmtokens. The xsl:number element can use a "lang" attribute to get things sorted after local tradition: lang="en", lang="fr", etc. The values "en" and "fr" are nmtokens.

16

expression

XPath

17

pattern

XPath

18

uri-reference

HTTP address or path/filename.

Footnotes

[1]

xsl:apply-imports is of category "instruction" meaning that it is to be used inside the xsl:template element. It is always an empty element, and it does not have any attributes.

[2]

xsl:apply-templates is most often emty and could look like this <xsl:apply-templates match="@*|node()"/>. If it is not an empty element it can only have two other XSLT elements as content, xsl:sort and xsl:with-param.

[3]

xsl:attribute. Note the curly braces around the values of the attributes. This is to indicate that the values do not need to be a qname or an uri-reference but can also be an XPath expression creating such values.

Also note that the content of the attribute elemente must be "Content: template". This has nothing to do with XSLT templates, they can only exist as children of the xsl:stylesheet element. "Content: template" simply means that the content of the attribute element must be a "template" in the more generic sense of the word, that is a template creating text, that is text and or XSLT elements creating text.

[4]

xsl:attribute-set is "top-level" that is it can only be a child of xsl:stylesheet.

[5]

Note that there must be at least one (+) xsl:when element in xsl:choose and that xsl:otherwise is optional or one (?).

[6]

Many beginners in XSLT don't understand xsl:copy and never use it. You need to understand the magic of the "identity" template (see my article: Identity Template: xsl:copy with recursion), and xsl:copy becomes the one XSLT element you want to use as much as possible.

[7]

The xsl:import element must be the first top-level element if present.

[8]

xsl:key. All three attributes are required.

[9]

What xsl:message actually does depends on the XSLT processor. If terminate="yes" the processing usually stops and your text message is shown in a status line somewhere or as a pop-up message.

[10]

xsl:number is used in the XSLT stylesheet behind this article to generate the numbering of the TOC, the numbering of the heading levels, the id's in the heading elements and the urls to go to them, and the numbering of the table in "Table 1: Syntax Vocabulary". The numbering of the table rows are normaly made with the position() function but is in this case hard coded.

[11]

Note that xsl:output is alwas an empty element. If the transformation is made through a programming language like .NET it can have classes overriding xsl:output.

[12]

xsl:param can be used both at top-level receiving input from outside or as the first element in a an XSLT templete receiving input from other templates.

[13]

Note that xsl:sort is always an empty element.

[14]

The two elements xsl:strip-space and xsl:preserve-space are some of the most tricky. They are only about stripping or preserving whitespace in nodes containing only whitespace. Many XSLT processors is doing it by default making the two XSLT elements irrelevant. See my article: Tricky whitespace handling in XSLT.

[15]

Note that the xsl:param element must be the first child if used in xsl:template.

[16]

The xsl:text element is the only element that can only contain #PCDATA (parsed character data). Many elements accepts #PCDATA like xsl:for-each, xsl:variable, etc. As a rule of thumb xsl:text should not be used around text unless necessary to preserve or control whitespace.

[17]

The xsl:transform element should be ignored. It is just an alias for xsl:stylesheet. Almost nobody uses it. Somebody probably forgot to delete it from the final draft of the Recommendation.

[18]

Note that xsl:value-of and xsl:copy-of and many other xsl:elements never have any content. They are alwas single tag elements.

[19]

Note that xsl:variable is both "top-level" and "instruction" that is it can be used globally or locally as in other programming languages.

[20]

xsl:with-param can only be used inside xsl:apply-templates and xsl:call-template.

Updated 2009-08-06