Sponsored

XSLT Reference

xsl:transform

XSLT 1.0 element

Synonym for xsl:stylesheet — the root element of an XSLT stylesheet, interchangeable in every respect.

Syntax
<xsl:transform version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

Description

xsl:transform is a direct synonym for xsl:stylesheet. The XSLT 1.0 specification allows either name as the document element of a stylesheet, and conforming processors must accept both. All attributes, allowed child elements, and semantics are identical.

In practice, xsl:stylesheet is used by the vast majority of published stylesheets because it was the name used in early drafts and became the de-facto convention. xsl:transform occasionally appears in generated or tool-produced stylesheets, and some authors prefer it because the word “transform” more directly describes what the document does.

There is no technical reason to choose one over the other. If a project or team has adopted a consistent convention, follow it; otherwise, xsl:stylesheet is the safer choice for readability and tooling compatibility.

Attributes

AttributeTypeRequiredDescription
version"1.0" / "2.0" / "3.0"YesXSLT version governing this stylesheet.
idIDNoUnique identifier for the element.
extension-element-prefixeswhitespace-separated prefixesNoPrefixes treated as extension element namespaces.
exclude-result-prefixeswhitespace-separated prefixesNoPrefixes excluded from the result tree.

Examples

Using xsl:transform as root element

Input XML:

<?xml version="1.0" encoding="UTF-8"?>
<book>
  <title>XSLT Patterns</title>
  <author>Jane Doe</author>
</book>

Stylesheet:

<?xml version="1.0" encoding="UTF-8"?>
<xsl:transform version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
  <xsl:output method="text"/>

  <xsl:template match="/book">
    <xsl:value-of select="title"/>
    <xsl:text> by </xsl:text>
    <xsl:value-of select="author"/>
  </xsl:template>
</xsl:transform>

Output:

XSLT Patterns by Jane Doe

Equivalent xsl:stylesheet version

Stylesheet (identical result, different root name):

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
  <xsl:output method="text"/>

  <xsl:template match="/book">
    <xsl:value-of select="title"/>
    <xsl:text> by </xsl:text>
    <xsl:value-of select="author"/>
  </xsl:template>
</xsl:stylesheet>

Output:

XSLT Patterns by Jane Doe

Notes

  • The two names are specified as synonyms in the XSLT 1.0 Recommendation, section 2.2. No processor may accept one but reject the other.
  • Mixing them — e.g., opening with <xsl:transform> and closing with </xsl:stylesheet> — is a well-formedness error in XML, not an XSLT issue.
  • Schema validators for XSLT documents (such as the official XSLT schema) list both names in the content model.

See also