XSLT elements
Encyclopedia
XSLT
(Extensible Stylesheet Language Transformations) defines many elements to describe the transformations that should be applied to a document. This article lists some of these elements. For an introduction to XSLT, see the main article
.
Client-side
XSLT
can be implemented in a browser
by adding a line like the following to the source XML
file, right after the root XML tag.
This is described on the page http://www.xml.com/pub/a/2000/10/25/msie/index.html
XSL Transformations
XSLT is a declarative, XML-based language used for the transformation of XML documents. The original document is not changed; rather, a new document is created based on the content of an existing one. The new document may be serialized by the processor in standard XML syntax or in another format,...
(Extensible Stylesheet Language Transformations) defines many elements to describe the transformations that should be applied to a document. This article lists some of these elements. For an introduction to XSLT, see the main article
XSL Transformations
XSLT is a declarative, XML-based language used for the transformation of XML documents. The original document is not changed; rather, a new document is created based on the content of an existing one. The new document may be serialized by the processor in standard XML syntax or in another format,...
.
XSLT logic elements
Node | Description/ attributes | Container/ children | Example |
---|---|---|---|
xsl:apply-templates | Specifies that other matches may exist within that node Node (computer science) A node is a record consisting of one or more fields that are links to other nodes, and a data field. The link and data fields are often implemented by pointers or references although it is also quite common for the data to be embedded directly in the node. Nodes are used to build linked, often... ; if this is not specified any matches will be ignored If “select” is specified, only the templates that specify a “match” that fits the selected node or attribute type will be applied ,i.e. the matching elements by "select" attribute in apply-templates corresponding to the template that match the same elements . If “mode” is specified, only the templates that have the same “mode” and have an appropriate “match” will be applied |
Any parent Can contain any number of xsl:sort and xsl:with-param children |
|
xsl:choose |
Multiple choices No attributes |
Any parent Contains xsl:when blocks and up to one xsl:otherwise block |
… |
xsl:for-each |
Creates a loop which repeats for every match “select” designates the match criteria |
Any parent Can contain any XML |
… |
xsl:if |
Yes or No conditions “test” specifies criteria for entering the if |
Any parent Can contain any XML |
… |
xsl:otherwise |
The default choice if none of the “xsl:when” criteria are met | xsl:choose Can contain any XML |
… |
xsl:stylesheet |
Top-level element. Occurs only once in a stylesheet document. “version” specifies which XSLT version is being used “xmlns:xsl” specifies the URL Uniform Resource Locator In computing, a uniform resource locator or universal resource locator is a specific character string that constitutes a reference to an Internet resource.... of that standard |
Top-level element. Contains all XML | … |
xsl:template |
Specifies processing templates “match” is when the template should be used. “name” gives the template a name which xsl:call-templates etc. can use to call this template. |
xsl:stylesheet Can contain any XML |
… |
xsl:variable |
Allows a variable to be declared “name” is the variable name. It can be referred to later with “$name” “select” is the value of the variable |
Any parent no children |
|
xsl:when |
Yes or No conditions “test” specifies criteria for entering the if |
xsl:choose Can contain any XML |
… |
Example XSLT stylesheet using logic elements
XSLT file I/O elements
Node | Description/ attributes | Container/ children | Example |
---|---|---|---|
xsl:call-template | Calls the template whose name is specifed. name matches the name in xsl-template |
Any parent children are xsl:with-param |
|
xsl:import | Retrieves another XSLT file href is the URI of the file |
xsl:stylesheet No children |
|
xsl:output | Describes how data will be returned method designates what kind of data is returned omit-xml-declaration indicates if the initial xml tag should be included. encoding designates how the data is returned. |
xsl:stylesheet No children |
|
xsl:param | Designates a parameter which may be passed into the template with xsl:call-template. | xsl:template No children |
|
xsl:text | Outputs the tag content | Any parent No children |
|
xsl:value-of | Outputs a variable select specifies the variable |
Any parent No children |
|
xsl:with-param | Designates a parameter passed to xsl:call-template. It must be matched by an xsl:param in the template. name specifies the parameter name. select specifies the parameter Parameter Parameter from Ancient Greek παρά also “para” meaning “beside, subsidiary” and μέτρον also “metron” meaning “measure”, can be interpreted in mathematics, logic, linguistics, environmental science and other disciplines.... value |
xsl:call-template No children |
Client-side
Client-side
Client-side refers to operations that are performed by the client in a client–server relationship in a computer network.Typically, a client is a computer application, such as a web browser, that runs on a user's local computer or workstation and connects to a server as necessary...
XSLT
XSL Transformations
XSLT is a declarative, XML-based language used for the transformation of XML documents. The original document is not changed; rather, a new document is created based on the content of an existing one. The new document may be serialized by the processor in standard XML syntax or in another format,...
can be implemented in a browser
Web browser
A web browser is a software application for retrieving, presenting, and traversing information resources on the World Wide Web. An information resource is identified by a Uniform Resource Identifier and may be a web page, image, video, or other piece of content...
by adding a line like the following to the source XML
XML
Extensible Markup Language is a set of rules for encoding documents in machine-readable form. It is defined in the XML 1.0 Specification produced by the W3C, and several other related specifications, all gratis open standards....
file, right after the root XML tag.
This is described on the page http://www.xml.com/pub/a/2000/10/25/msie/index.html
Other XSLT semantics
symbol | meaning | where used |
---|---|---|
| | union operator. used to group nodesets in XPath expressions. | select attributes of elements such as xsl:when, xsl:if, xsl:for-each |
& | and | any conditional or match criterion, for example xsl:if.test, xsl:when.test, xsl:template.select and xsl:for-each.select |
<!-- | begin comment | anywhere not in a tag |
--> | end comment | anywhere not in a tag |
$ | start of a variable name | anywhere in a tag, for example xsl:value-of.select and xsl:variable.name |
name | the name of the tag being processed. Useful if the matching criteria contains |s (pipe symbols) | any conditional or match criterion, for example xsl:if.test, xsl:when.test, xsl:template.select and xsl:for-each.select |
@ | an attribute within the XML | any conditional or match criterion, for example xsl:if.test, xsl:when.test, xsl:template.select and xsl:for-each.select |
Functions defined by XSLT
The following functions can occur in many XSLT attributes, such as xsl:value-of.select and xsl:for-each.select.Function | Description/ Syntax | Example |
---|---|---|
ceiling | The ceiling function returns the smallest integer Integer The integers are formed by the natural numbers together with the negatives of the non-zero natural numbers .They are known as Positive and Negative Integers respectively... that is equal to or is larger than the numeric value of the number argument. |
ceiling(3.57) |
concat | Concatenates two or more strings, which are listed in the parentheses | concat($fname,’ ‘, $lname) |
count | The count function counts and returns the number of nodes in a node-set. | count(elements) |
floor | The floor function returns the largest integer that is equal to or is smaller than the numeric value of the number argument. | floor(3.57) |
normalize-space | Removes white-space from the beginning and end of the string | normalize-space($fname) |
position | The position function returns the position number in the current node list of the node that is currently being processed by an xsl:for-each or xsl:apply-templates element. There are no arguments. | position |
round | The round function rounds a number to its closest integer. | round(3.57) |
string | The string function converts the value argument to a string. | string |
string-length | The string-length function returns the number of characters in a string. The string argument is optional. If omitted, the default is to use the string value of the context node. | string-length(‘hello’) |
substring | A segment within a variable value. Substring takes three parameters: the input variable, the first character to be selected, and the length of the resulting string | substring($dob,4,2) |
substring-after | The substring-after function returns a portion out of the string specified in the string argument that occurs after the substring specified in the substring argument. | substring-after(‘In 1814 we took a little trip’, ‘we’) |
substring-before | The substring-before function returns a portion out of the string specified in the string argument that occurs before the substring specified in the substring argument. | substring-before(‘In 1814 we took a little trip’, ‘we’) |
sum | The sum function adds and returns the total value of a set of numeric values in a node-set or list of values. | sum(1,3,7,12) |
translate | Takes the string in the value argument, replaces all occurrences of a string specified in the string1 argument with substitute characters specified in string2 argument and returns the modified string. | translate(‘colored armor’, ‘or’, ‘our’) |
External links
- W3C XSLT 1.0 recommendation - Describes the whole syntax and semantics of XSLT 1.0
- W3C XSLT 2.0 recommendation
- XSLT Elements List - by W3Schools