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]

2. xsl:apply-templates

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

3. xsl:attribute

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

4. xsl:attribute-set

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

5. xsl:call-template

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

6. xsl:choose

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

7. xsl:comment

<!-- Category: instruction -->
  <!-- Content: template -->

8. xsl:copy

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

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 -->

12. xsl:fallback

<!-- Category: instruction -->
  <!-- Content: template -->

13. xsl:for-each

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

14. xsl:if

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

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 -->

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 -->
  <!-- Content: template -->

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 -->

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 -->

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) -->

29. xsl:template

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

30. xsl:text

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

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) -->

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 -->

34. xsl:when

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

35. xsl:with-param

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

36. Table of Syntax Vocabulary

Table 1: Syntax Vocabulary





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.


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.


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.


Category: instruction

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


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.



Optional or one time.



One or many times.



Optional or one or many times.



Alternative or choice.



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


Content: template

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



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}"/>.



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



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



"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.









HTTP address or path/filename.



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.


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.


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.


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


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


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.


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


xsl:key. All three attributes are required.


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.


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.


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.


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.


Note that xsl:sort is always an empty element.


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.


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


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.


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.


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


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


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

Updated 2009-08-06