Wednesday, February 18, 2026

XSLT Elements

 

XSLT Elements

XSLT elements are the building blocks for the transformation that occurs in your XSL file. These elements define the pattern in which the XML elements of the source documents are transformed.



<xsl:apply-imports>

The <xsl:apply-imports> element applies a template rule from an imported style sheet. This element is used within the <xsl:template> element. The <xsl:apply-imports> element contains either a null value or the <xsl:with-param> element. The syntax for this element is:

<xsl:apply-imports> <!-- Content: xsl:with-param* --> </xsl:apply-imports>

<xsl:apply-templates>

The <xsl:apply-templates> element selects a set of nodes from the source document on whom the template is applied, depending on the rule specified for each node in the template element. The syntax for this element is:

<xsl:apply-templates select="expression" mode="name"> <!-- Content: (xsl:sort | xsl:with-param)* --> </xsl:apply-templates>

In the above syntax, the attributes select and mode are optional. The select attribute specifies a node-set for processing whereas the mode attribute defines the processing pattern when multiple processing ways are specifies for a node-set.

<xsl:analyze-string>

The <xsl:analyse-string> element analyzes the string passed to the select attribute with a substring that matches a regular expression specified by the regex attribute. The syntax for this element is:

<xsl:analyze-string Attribute-list> <!-- Content: (xsl:matching-substring?, xsl:non-matching-substring?, xsl:fallback*) --> </xsl:analyze-string>

In the above syntax, the Attribute-list consists of the select and regex attributes. In a given string, if the <xsl:analyze-string> element finds the substring that matches the expression. These substrings are processed by the <xsl:matching-substring> element whereas the substrings that do not match are processed by the statements in the <xsl:non-matching-substring> element.

<xsl:attribute>

The <xsl:attribute> element generates attributes in the resultant document for elements of the source document. The syntax for this element is:

<xsl:attribute Attribute-list> <!-- Content: sequence-constructor --> </xsl:attribute>

In the above syntax, the Attribute-list consists of the following attributes:

  • name = { qname }

  • namespace = { uri-reference }

  • validation = "strict" | "lax" | "preserve" | "strip"

  • type = qname

  • disable-output-escaping = "yes" | "no"

The <xsl:attribute> element also controls the type of the attributes in the document.

<xsl:attribute-set>

The <xsl:attribute-set> is used to generate a set of attributes for the elements in the resultant document. The syntax is:

<xsl:attribute-set Attribute-list <!-- Content: xsl:attribute* --> </xsl:attribute-set>

In the above syntax, the Attribute-list contains the attributes:

  • xsl:call-template name = templatename

  • name = qname

  • use-attribute-sets = qnames

You can apply an attribute-set to multiple elements in a tree. In addition, you can include more than one attribute-set within a single <xsl:attribute-set> element, using the use-attribute-sets attribute.

<xsl:call-template>

If a template is defined by the name attribute within a document, you can access or invoke this template using the <xsl:call-template> element. This element accepts the template name as the attribute. The syntax for this element is:

<xsl:call-template name="templatename"> <!-- Content: xsl:with-param* --> </xsl:call-template>

<xsl:character-map>

The <xsl:character-map> element replaces a set of characters appearing in the text or attribute nodes of the source document with a given set of values when generating the output. The syntax for this element is:

<xsl:character-map Attribute-list> <!-- Content: (xsl:output-character*) --> </xsl:character-map>

In the above syntax, the Attribute-list contains the attributes:

  • name = qname

  • use-character-maps = qnames

<xsl:choose>

The <xsl:choose> element selects an option from a set of available options, depending on the evaluation of the condition provided with the element. The syntax for this element is:

<xsl:choose> <!-- Content: (xsl:when+, xsl:otherwise?) --> </xsl:choose>

The options are specified within the <xsl:choose> element using the <xsl:when> element. Depending on the option selected, the nodes in the source tree are selected and displayed in the resultant document.

<xsl:comment>

This element creates a comment node in the resultant document. The syntax for this element is:

<xsl:comment> <!-- Content: sequence-constructor --> </xsl:comment>

<xsl:copy>

The <xsl:copy> element copies nodes in the source document to the resultant document. The syntax for this element is:

<xsl:copy Attribute-list> <!-- Content: sequence-constructor --> </xsl:copy>

In the above syntax, the Attribute-list contains the attributes:

  • copy-namespaces = "yes" | "no"

  • use-attribute-sets = qnames

  • validation = "strict" | "lax" | "preserve" | "strip"

  • type = qname

This element does copies only the current node, and not the descendant nodes. This type of copy is called a shallow copy.


<xsl:copy-of>

The <xsl:copy-of> element copies all the descendant nodes and namespaces from the current node to the resultant document. The syntax for this element is:

<xsl:copy-of Attribute-list />

In the above syntax, the Attribute-list contains the attributes:

  • select = expression

  • copy-namespaces = "yes" | "no"

  • validation = "strict" | "lax" | "preserve" | "strip"

  • type = qname


<xsl:date-format>

The <xsl:date-format> element defines the format of a date to be used in the date formatting functions. The syntax for this element is:

<xsl:date-format Attribute-list />

In the above syntax, the Attribute-list contains the attributes:

  • name = qname

  • language = nmtoken

  • calendar = qname

<xsl:decimal-format>

The <xsl:decimal-format> element represents symbols and characters used in the format-number() function. The syntax for this element is:

<xsl:decimal-format Attribute-list />

In the above syntax, the Attribute-list contains the attributes:

  • 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

<xsl:document>

The <xsl:document> element generates multiple output documents during transformation. The syntax for this element is:

<xsl:document Attribute-list> template-body </xsl:document>

In the above syntax, the Attribute-list can contain the attributes:

  • href = { uri }

  • method = { "xml" | "html" | "text" | QName }

  • version = { Nmtoken }

  • encoding = { string }

  • omit-xml-declarations = { "yes" | "no" }

  • standalone = { "yes" | "no" }

  • doctype-public = { string }

  • doctype-system = { string }

  • cdata-section-elements = { list-of-Qnames }

  • indent = { "yes" | "no" }

  • media-type = { string }

The resultant is an XML, an HTML, or a text document.


<xsl:element>

The <xsl:element> element generates an element node in the result tree. The syntax for this element is:

<xsl:element Attribute-list> <!-- Content: sequence-constructor --> </xsl:element>

In the above syntax, the Attribute-list contains the attributes:

  • name = { qname }

  • namespace = { uri-reference }

  • use-attribute-sets = qnames

  • validation = "strict" | "lax" | "preserve" | "strip"

  • type = qname

Using the validation attribute, you can control the type annotation of the element in the document.

<xsl:fallback>

While transforming the source document into resultant document, the XSL processor may not process some elements or functions. To process the elements that are not recognized by the XSL processor, the <xsl:fallback> element contains processing instructions. The syntax for this element is:

<xsl:fallback> <!-- Content: sequence-constructor --> </xsl:fallback>

<xsl:for-each>

The <xsl:for-each> element performs iterative processing of the source document till the condition provided is evaluated as true. The syntax for this element is:

<xsl:for-each Attribute-list> <!-- Content: (xsl:sort*, sequence-constructor) --> </xsl:for-each>

In the above syntax, the Attribute-list contains the select attribute. This attribute holds a sequence-expression. This element repeatedly processes the contents of the element until the expression specified in the select attribute is met.

<xsl:for-each-group>

The <xsl:for-each-group> element repeatedly processes the sequence constructor for each group of items. The syntax for this element is:

<xsl:for-each-group Attribute-list> <!-- Content: (xsl:sort*, sequence-constructor) --> </xsl:for-each-group>

In the above syntax, the Attribute-list contains the attributes:

  • select = expression

  • group-by = expression

  • group-adjacent = expression

  • group-starting-with = pattern

  • group-ending-with = pattern

  • collation = { uri }>

<xsl:function>

The <xsl:function> element defines a function. The syntax for this element is:

<xsl:function Attribute-list> <!-- Content: (xsl:param*, sequence-constructor) --> </xsl:function>

In the above syntax, the Attribute-list contains the attributes:

  • name = qname

  • as = sequence-type

  • override = "yes" | "no"

If the function already exists with the same name, you need to specify a value yes to the override attribute.

<xsl:if>

The <xsl:if> element checks whether the given expression is true or false. The syntax for this element is:

<xsl:if Attribute-list> <!-- Content: sequence-constructor --> </xsl:if>

In the above syntax, the Attribute-list contains the test attribute that contains the expression to be checked. If the expression returns the Boolean value true, the instructions specified within this element are processed and displayed in the resultant document.

<xsl:import>

The <xsl:import> element combines one or more stylesheet modules to a single stylesheet. The syntax for this element is:

<xsl:import Attribute-list />

In the above syntax, the Attribute-list contains the href attribute that contains the URI of the imported stylesheet.


<xsl:import-schema>

A schema document contains the elements, attributes, and type definitions imported within the <xsl:import-schema> element. The syntax for this element is:

<xsl:import-schema Attribute-list/>

In the above syntax, the Attribute-list contains the attributes:

  • namespace = uri-reference

  • schema-location = uri-reference

<xsl:include>

The <xsl:include> element includes one stylesheet within another stylesheet. The syntax for this element is:

<xsl:include Attribute-list />

In the above syntax, the Attribute-list contains the href attribute that refers to the URI of the stylesheet to be included.

When you use the <xsl:import> element, the importing stylesheet contains higher precedence than the rules and declarations specified in the imported stylesheet. If you use the <xsl:include> element, the included stylesheet is assigned the same precedence as the including stylesheet.

<xsl:key>

The <xsl:key> element declares a key for a particular node in the document. This key is accessed by the key() function. The syntax for this element is:

<xsl:key Attribute-list />

In the above syntax, the Attribute-list contains the attributes:

  • name = qname

  • match = pattern

  • use = expression

  • as = qname

  • collation = uri

This element simplifies the task of searching for a node within the document. The <xsl:key> element indexes nodes, particularly the namespace nodes.

<xsl:message>

The <xsl:message> element generates a message in the resultant document. The syntax for this element is:

<xsl:message Attribute-list> <!-- Content: sequence-constructor --> </xsl:message>

In the above syntax, the Attribute-list contains the terminate attribute, which has the value, yes, or, no. If the value of the terminate attribute is yes, this element stops processing the stylesheet.

<xsl:namespace>

The <xsl:namespace> element creates a new namespace node in the resultant document. The syntax for this element is:

<xsl:namespace Attribute-list> <!-- Content: sequence-constructor --> </xsl:namespace>

In the above syntax, the Attribute-list contains the name attribute, which is the namespace name.

<xsl:namespace-alias>

The <xsl:namespace-alias> element creates an alternate namespace prefix for the namespace prefix specified in the source document. The alternate namespace prefix appears only in the resultant document. The syntax for this element is:

<xsl:namespace-alias Attribute-list />

In the above syntax, the Attribute-list contains the attributes:

  • stylesheet-prefix = prefix | "#default"

  • result-prefix = prefix | "#default"

<xsl:number>

The <xsl:number> element formats a number and places the formatted value as a string in the text node of the resultant document. The syntax for this element is:

<xsl:number Attribute-list/>

In the above syntax, the Attribute-list contains the attributes:

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

This element is used within the template element.


<xsl:next-match>

The <xsl:next-match> element accesses the template rule to override the rules defined by another template in the stylesheet. The syntax for this element is:

<xsl:next-match> <!-- Content: (xsl:with-param | xsl:fallback)* --> </xsl:next-match>

<xsl:otherwise>

The <xsl:otherwise> element is used in conjunction with the <xsl:when> element to process a document depending on the condition. The syntax for this element is:

<xsl:otherwise> <!-- Content: sequence-constructor --> </xsl:otherwise>

If the condition specified in the <xsl:when> element is not met, the instructions within the <xsl:otherwise> element are processed and returned to the <xsl:choose> element.


<xsl:output>

The <xsl:output> element generates various output formats for the resultant document. The syntax for this element is:

<xsl:output Attribute-list />

In the above syntax, the Attribute-list contains the attributes:

  • name = qname

  • method = "xml" | "html" | "xhtml" | "text" | qname-but-not-ncname

  • cdata-section-elements = qnames

  • doctype-public = string

  • doctype-system = string

  • encoding = string

  • escape-uri-attributes = "yes" | "no"

  • include-content-type = "yes" | "no"

  • indent = "yes" | "no"

  • media-type = string

  • normalize-unicode = "yes" | "no"

  • omit-xml-declaration = "yes" | "no"

  • standalone = "yes" | "no"

  • undeclare-namespaces = "yes" | "no"

  • use-character-maps = qnames

  • version = nmtoken

This element can be used to generate multiple documents of different formats from a single source document.


<xsl:param>

The <xsl:param> elements can be used to create parameters in a stylesheet. When this element is used within the <xsl:stylesheet> or the <xsl:transform> elements, the parameters created are global. If you create the parameters within the template body, the parameters are local. The syntax for this element is:

<xsl:param Attribute-list > <!-- Content: sequence-constructor --> </xsl:param>

In the above syntax, the Attribute-list contains the attributes:

  • name = qname

  • select = expression

  • as = sequence-type

  • required = "yes" | "no"

<xsl:preserve-space>

The <xsl:preserve-space> element retains the white spaces in the source documents when creating the resultant document. The syntax for this element is:

<xsl:preserve-space Attribute-list />

In the above syntax, the Attribute-list contains the attribute elements that maps to a list of element names separated by a white space.

<xsl:processing-instruction>

The <xsl:processing-instruction> element generates a processing instruction node in the resultant document. The syntax for this element is:

<xsl:processing-instruction Attribute-list > <!-- Content: sequence-constructor --> </xsl:processing-instruction>

In the above syntax, the Attribute-list contains the ncname of the node.

<xsl:result-document>

The <xsl:result-document> element generates multiple resultant documents. The syntax for this element is:

<xsl:result-document Attribute-list > <!-- Content: sequence-constructor --> </xsl:result-document>

In the above syntax, the Attribute-list contains the attributes:

  • format = qname

  • href = { uri-reference }

  • validation = "strict" | "lax" | "preserve" | "strip"

  • as = sequence-type

<xsl:script>

The <xsl:script> element defines and identifies extension functions in the stylesheet during processing. The syntax for this element is:

<xsl:script Attribute-list> text </xsl:script>

In the above syntax, the Attribute-list contains the attributes:

  • implements-prefix = NCName

  • language = "ecmascript" | "javascript" | "java" | Qname

  • src = URI

  • archive = list of URIs

<xsl:sequence>

The <xsl:sequence> element returns a sequence, constructed using the sequence specified in the select attribute. The syntax for this element is:

<xsl:sequence Attribute-list <!-- Content: sequence-constructor --> </xsl:sequence>

In the above syntax, the Attribute-list contains the attributes:

  • select = expression

  • as = sequence-type

This element adds a sequence to the existing node by constructing a new node.

<xsl:sort>

The <xsl:sort> element sorts the nodes in the source document. The syntax for this element is:

<xsl:sort Attribute-list/>

In the above syntax, the Attribute-list contains the attributes:

  • select = expression

  • lang = { nmtoken }

  • order = { "ascending" | "descending" }

  • collation = { uri }

  • case-order = { "upper-first" | "lower-first" }

  • data-type = { "text" | "number" | qname-but-not-ncname }

The <xsl:sort> element is always used as a child element of the <xsl:apply-templates> or the <xsl:for-each> elements. The nodes selected by the <xsl:apply-templates> or the <xsl:for-each> element are processed in the order specified by the <xsl:sort> element.

<xsl:sort-key>

The <xsl:sort-key> element defines the named sort specification used in the sort() function. The syntax for this element is:

<xsl:sort-key Attribute-list> <!-- Content: (xsl:sort+) --> </xsl:sort-key>

In the above syntax, the Attribute-list contains a qualified name of the sort specification. You can define multiple <xsl:sort> elements within the <xsl:sort-key> element.

<xsl:strip-space>

The <xsl:strip-space> element removes all the white space nodes in the source document when transforming to the resultant document. The syntax for this element is:

<xsl:strip-space Attribute-list />

In the above syntax, the Attribute-list contains a list of white space separated element names.

<xsl:stylesheet>

The <xsl:stylesheet> element is the root element of the XSLT stylesheet document. The syntax for this element is:

<xsl:stylesheet Attribute-list> <!-- Content: (xsl:import*, other-declarations) --> </xsl:stylesheet>

In the above syntax, the Attribute-list contains the attributes:

  • id = id

  • extension-element-prefixes = tokens

  • exclude-result-prefixes = tokens

  • version = number

  • xpath-default-namespace = uri

  • default-validation = "strict" | "lax" | "preserve" | "strip"

This element specifies the namespace URI of the document and the version of XSLT.

<xsl:template>

The <xsl:template> element contains the set of rules and matching patterns to generate a node in the resultant document. This element is used within the <xsl:stylesheet> element. The syntax for this element is:

<xsl:template Attribute-list> <!-- Content: (xsl:param*, sequence-constructor) --> </xsl:template>

In the above syntax, the Attribute-list contains the attributes:

  • match = pattern

  • name = qname

  • priority = number

  • mode = tokens

  • as = sequence-type

<xsl:transform>

The <xsl:transform> element is an alternative element for the <xsl:stylesheet> element, and is used to transform documents. The syntax for this element is:

<xsl:transform Attribute-list> <!-- Content: (xsl:import*, other-declarations) --> </xsl:transform>

In the above syntax, the Attribute-list contains the attributes:

  • id = id

  • extension-element-prefixes = tokens

  • exclude-result-prefixes = tokens

  • version = number

  • xpath-default-namespace = uri

  • default-validation = "strict" | "lax" | "preserve" | "strip"

Depending on the role of XSLT as a transformation language or as a stylesheet language, you can use the <xsl:transform> and <xsl:stylesheet> elements, respectively.

<xsl:value-of>

The <xsl:value-of>element reads and copies the value of an element or attribute in the source document to the resultant document. The syntax for this element is:

<xsl:value-of Attribute-list/>

In the above syntax, the Attribute-list contains the attributes:

  • select = expression

  • separator = { string }

  • disable-output-escaping = "yes" | "no"

<xsl:variable>

The <xsl:variable> element declares variables within the stylesheet. The syntax for this element is:

<xsl:variable Attribute-list> <!-- Content: sequence-constructor --> </xsl:variable>

In the above syntax, the Attribute-list contains the attributes:

  • name = qname

  • select = expression

  • as = sequence-type

<xsl:when>

The <xsl:when> element is always used within the <xsl:choose> element. The syntax for this element is:

<xsl:when Attribute-list> <!-- Content: sequence-constructor --> </xsl:when>

In the above syntax, the Attribute-list contains the test attribute that refers to an expression. Within the <xsl:choose> element, multiple <xsl:when> elements can be used. If the condition specified in any of the <xsl:when> element is satisfied, the expression is evaluated and returned to the <xsl:choose> element. When all the conditions specified in the <xsl:when> elements are not met, the statements of the <xsl:otherwise> element are executed.

<xsl:with-param>

The <xsl:with-param> element passes a parameter to the template element. The syntax for this element is:

<xsl:with-param Attribute-list> <!-- Content: sequence-constructor --> </xsl:with-param>

In the above syntax, the Attribute-list contains the attributes:

  • name = qname

  • select = expression





sads

No comments:

Post a Comment

SOA Overview Part-1

  Middleware It provides a mechanism for the process to interact with other processes running on multiple network machines. Advantages...