Show Menu
Cheatography

XSLT 2.0 Cheat Sheet Cheat Sheet by

XSLT 2.0 Cheat Sheet

About

XSL stands for EXtensible Stylesheet Language, and is a style sheet language for XML documents.

XSLT stands for XSL Transf­orm­ations. In this tutorial you will learn how to use XSLT to transform XML documents into other formats, like XHTML.

Elements

apply-­imports
Applies a template rule from an imported style sheet
apply-­tem­plates
Applies a template rule to the current element or to the current element's child nodes
attribute
Adds an attribute
attrib­ute-set
Defines a named set of attributes
call-t­emplate
Calls a named template
choose
Used in conjun­ction with <wh­en> and <ot­her­wis­e> to express multiple condit­ional tests
comment
Creates a comment node in the result tree
copy
Creates a copy of the current node (without child nodes and attrib­utes)
copy-of
Creates a copy of the current node (with child nodes and attrib­utes)
decima­l-f­ormat
Defines the characters and symbols to be used when converting numbers into strings, with the format­-nu­mber() function
element
Creates an element node in the output document
fallback
Specifies an alternate code to run if the processor does not support an XSLT element
for-each
Loops through each node in a specified node set
if
Contains a template that will be applied only if a specified condition is true
import
Imports the contents of one style sheet into another. Note: An imported style sheet has lower precedence than the importing style sheet
include
Includes the contents of one style sheet into another. Note: An included style sheet has the same precedence as the including style sheet
key
Declares a named key that can be used in the style sheet with the key() function
message
Writes a message to the output (used to report errors)
namesp­ace­-alias
Replaces a namespace in the style sheet to a different namespace in the output
number
Determines the integer position of the current node and formats a number
otherwise
Specifies a default action for the <ch­oos­e> element
output
Defines the format of the output document
param
Declares a local or global parameter
preser­ve-­space
Defines the elements for which white space should be preserved
proces­sin­g-i­nst­ruction
Writes a processing instru­ction to the output
sort
Sorts the output
strip-­space
Defines the elements for which white space should be removed
stylesheet
Defines the root element of a style sheet
template
Rules to apply when a specified node is matched
text
Writes literal text to the output
transform
Defines the root element of a style sheet
value-of
Extracts the value of a selected node
variable
Declares a local or global variable
when
Specifies an action for the <ch­oos­e> element
with-param
Defines the value of a parameter to be passed into a template
 

Selectors

nodename
Selects all nodes with the name "­nod­ena­me"
/
Selects from the root node
//
Selects nodes in the whole document
.
Selects the current node
..
Selects the parent of the current node
@
Selects attributes
*
Matches any element node
@*
Matches any attribute node
//node[1]
Selects the first element that is the child of the element.
//node­[@class and @id]
select the node with both "­cla­ss" and "­id"
//node­[co­unt­(ch­ild)=2]
select the node with two "­chi­ld" elements
//node­[co­nta­ins­(@t­itl­e,"t­ext­")]
select the node with "­tex­t" in the title attribute
//node­[ch­ild­/ch­ild1]
select the node with "­chi­ld/­chi­ld1­" child nodes
//node­[po­sit­ion() mode 2 ==0]
select the odd children elements
//node­/te­xt()[2]
return the second text element of node
//node­[no­t(@­class)]
the node without "­cla­ss" attribute

Accessor Functions

node-n­ame­(node)
Returns the node-name of the argument node
nilled­(node)
Returns a Boolean value indicating whether the argument node is nilled
data(i­tem.it­em,...)
Takes a sequence of items and returns a sequence of atomic values
base-uri() fn:bas­e-u­ri(­node)
Returns the value of the base-uri property of the current or specified node
docume­nt-­uri­(node)
Returns the value of the docume­nt-uri property for the specified node

Functions on Nodes

name()
Returns the node-name of the argument node
local-­name()
Returns a Boolean value indicating whether the argument node is nilled
namesp­ace­-uri()
Takes a sequence of items and returns a sequence of atomic values
lang(lang)
Returns the value of the base-uri property of the current or specified node
root()
Returns the value of the docume­nt-uri property for the specified node

Functions on Numeric Values

number­(arg)
Returns the numeric value of the argument. The argument could be a boolean, string, or node-set
abs(num)
Returns the absolute value of the argument
ceilin­g(num)
Returns the smallest integer that is greater than the number argument
floor(num)
Returns the largest integer that is not greater than the number argument
round(num)
Rounds the number argument to the nearest integer

Aggregate Functions

count(­(it­em,­ite­m,...))
Returns the count of nodes
avg((a­rg,­arg­,...))
Returns the average of the argument values
max((a­rg,­arg­,...))
Returns the argument that is greater than the others
min((a­rg,­arg­,...))
Returns the argument that is less than the others
sum(ar­g,a­rg,...)
Returns the sum of the numeric value of each node in the specified node-set
 

Context Functions

position()
Returns the index position of the node that is currently being processed
last()
Returns the number of items in the processed node list
curren­t-d­ate­Time()
Returns the current dateTime (with timezone)
curren­t-d­ate()
Returns the current date (with timezone)
curren­t-t­ime()
Returns the current time (with timezone)

Functions on Strings

string­(arg)
Returns the string value of the argument. The argument could be a number, boolean, or node-set
codepo­int­s-t­o-s­tri­ng(­int­,in­t,...)
Returns a string from a sequence of code points
string­-to­-co­dep­oin­ts(­string)
Returns a sequence of code points from a string
codepo­int­-eq­ual­(co­mp1­,comp2)
Returns true if the value of comp1 is equal to the value of comp2, according to the Unicode code point collation, otherwise it returns false
compar­e(c­omp­1,c­omp2)
Returns -1 if comp1 is less than comp2, 0 if comp1 is equal to comp2, or 1 if comp1 is greater than comp2 (according to the rules of the collation that is used)
string­-jo­in(­(st­rin­g,s­tri­ng,...)­,sep)
Returns a string created by concat­enating the string arguments and using the sep argument as the separator
substr­ing­(st­rin­g,s­tar­t,len)
Returns the substring from the start position to the specified length. Index of the first character is 1. If length is omitted it returns the substring from the start position to the end
string­-le­ngt­h(s­tring)
Returns the length of the specified string. If there is no string argument it returns the length of the string value of the current node
normal­ize­-sp­ace­(st­ring)
Removes leading and trailing spaces from the specified string, and replaces all internal sequences of white space with one and returns the result. If there is no string argument it does the same on the current node
normal­ize­-un­icode()
upper-­cas­e(s­tring)
Converts the string argument to upper-case
lower-­cas­e(s­tring)
Converts the string argument to lower-case
transl­ate­(st­rin­g1,­str­ing­2,s­tring3)
Converts string1 by replacing the characters in string2 with the characters in string3
escape­-ur­i(s­tri­ngU­RI,­esc­-res)
contai­ns(­str­ing­1,s­tring2)
Returns true if string1 contains string2, otherwise it returns false
starts­-wi­th(­str­ing­1,s­tring2)
Returns true if string1 starts with string2, otherwise it returns false
ends-w­ith­(st­rin­g1,­str­ing2)
Returns true if string1 ends with string2, otherwise it returns false
substr­ing­-be­for­e(s­tr1­,str2)
Returns the start of string1 before string2 occurs in it
substr­ing­-af­ter­(st­r1,­str2)
Returns the remainder of string1 after string2 occurs in it
matche­s(s­tri­ng,­pat­tern)
Returns true if the string argument matches the pattern, otherwise, it returns false
replac­e(s­tri­ng,­pat­ter­n,r­eplace)
Returns a string that is created by replacing the given pattern with the replace argument
tokeni­ze(­str­ing­,pa­ttern)

Functions on Boolean Values

boolea­n(arg)
Returns a boolean value for a number, string, or node-set
not(arg)
The argument is first reduced to a boolean value by applying the boolean() function. Returns true if the boolean value is false, and false if the boolean value is true
true()
Returns the boolean value true
false()
Returns the boolean value false
                   
 

Comments

No comments yet. Add yours below!

Add a Comment

Your Comment

Please enter your name.

    Please enter your email address

      Please enter your Comment.

          Related Cheat Sheets