XSLT 2.
0 Cheat Sheet Cheat Sheet
by Jin Lei (Univer) via cheatography.com/2588/cs/673/
About Elements (cont) Elements (cont)
XSL stands for EXtensible Stylesheet fallback Specifies an alternate code to run if otherwise Specifies a default action for the
Language, and is a style sheet language for the processor does not support an <choose> element
XML documents. XSLT element
output Defines the format of the output
XSLT stands for XSL Transformations. In this
for-each Loops through each node in a document
tutorial you will learn how to use XSLT to
specified node set
param Declares a local or global
transform XML documents into other formats,
if Contains a template that will be parameter
like XHTML.
applied only if a specified condition
preserve-s Defines the elements for which
is true
Elements pace white space should be preserved
import Imports the contents of one style processing Writes a processing instruction to
apply-im Applies a template rule from an sheet into another. Note: An
- the output
ports imported style sheet imported style sheet has lower
instruction
apply-te Applies a template rule to the precedence than the importing
sort Sorts the output
mplates current element or to the current style sheet
element's child nodes strip-space Defines the elements for which
include Includes the contents of one style
white space should be removed
attribute Adds an attribute sheet into another. Note: An
included style sheet has the same stylesheet Defines the root element of a
attribute- Defines a named set of attributes
precedence as the including style style sheet
set
sheet template Rules to apply when a specified
call- Calls a named template
key Declares a named key that can be node is matched
template
used in the style sheet with the text Writes literal text to the output
choose Used in conjunction with <when>
key() function
and <otherwise> to express transform Defines the root element of a
message Writes a message to the output style sheet
multiple conditional tests
(used to report errors)
comment Creates a comment node in the value-of Extracts the value of a selected
namespa Replaces a namespace in the style node
result tree
ce-alias sheet to a different namespace in
copy Creates a copy of the current node variable Declares a local or global variable
the output
(without child nodes and when Specifies an action for the
number Determines the integer position of
attributes) <choose> element
the current node and formats a
copy-of Creates a copy of the current node number with- Defines the value of a parameter
(with child nodes and attributes) param to be passed into a template
decimal- Defines the characters and symbols
format to be used when converting
numbers into strings, with the
format-number() function
element Creates an element node in the
output document
By Jin Lei (Univer) Published 21st November, 2012. Sponsored by CrosswordCheats.com
cheatography.com/univer/ Last updated 5th June, 2014. Learn to solve cryptic crosswords!
jinlei.me Page 1 of 3. http://crosswordcheats.com
XSLT 2.0 Cheat Sheet Cheat Sheet
by Jin Lei (Univer) via cheatography.com/2588/cs/673/
Selectors Accessor Functions Functions on Numeric Values
nodename node-name(node) number(arg Returns the numeric value of the
Selects all nodes with the name Returns the node-name of the argument ) argument. The argument could
be a boolean, string, or node-set
"nodename" node
abs(num) Returns the absolute value of the
/ nilled(node)
argument
Selects from the root node Returns a Boolean value indicating whether
ceiling(num Returns the smallest integer that
the argument node is nilled
// ) is greater than the number
data(item.item,...) argument
Selects nodes in the whole document
Takes a sequence of items and returns a floor(num) Returns the largest integer that
.
sequence of atomic values is not greater than the number
Selects the current node argument
base-uri() fn:base-uri(node)
.. round(num) Rounds the number argument to
Returns the value of the base-uri property of
Selects the parent of the current node the nearest integer
the current or specified node
@ document-uri(node) Aggregate Functions
Selects attributes Returns the value of the document-uri
count((item,item,...))
* property for the specified node
Returns the count of nodes
Matches any element node
Functions on Nodes avg((arg,arg,...))
@*
name() Returns the node-name of the Returns the average of the argument values
Matches any attribute node
argument node max((arg,arg,...))
//node[1]
local-nam Returns a Boolean value Returns the argument that is greater than
Selects the first element that is the child of e() indicating whether the argument the others
the element. node is nilled
min((arg,arg,...))
//node[@class and @id] namespac Takes a sequence of items and
e-uri() returns a sequence of atomic Returns the argument that is less than the
select the node with both "class" and "id"
values others
//node[count(child)=2]
lang(lang) Returns the value of the base-uri sum(arg,arg,...)
select the node with two "child" elements property of the current or specified Returns the sum of the numeric value of
node each node in the specified node-set
//node[contains(@title,"text")]
select the node with "text" in the title attribute root() Returns the value of the
document-uri property for the Context Functions
//node[child/child1] specified node
position() Returns the index position of the
select the node with "child/child1" child
node that is currently being
nodes
processed
//node[position() mode 2 ==0]
select the odd children elements
//node/text()[2]
return the second text element of node
//node[not(@class)]
the node without "class" attribute
By Jin Lei (Univer) Published 21st November, 2012. Sponsored by CrosswordCheats.com
cheatography.com/univer/ Last updated 5th June, 2014. Learn to solve cryptic crosswords!
jinlei.me Page 2 of 3. http://crosswordcheats.com
XSLT 2.0 Cheat Sheet Cheat Sheet
by Jin Lei (Univer) via cheatography.com/2588/cs/673/
Context Functions (cont) Functions on Strings (cont) Functions on Strings (cont)
last() Returns the number of items in the string-length(string) matches(string,pattern)
processed node list Returns the length of the specified string. If Returns true if the string argument matches
current- Returns the current dateTime there is no string argument it returns the the pattern, otherwise, it returns false
dateTime() (with timezone) length of the string value of the current node
replace(string,pattern,replace)
current- Returns the current date (with normalize-space(string) Returns a string that is created by replacing
date() timezone)
Removes leading and trailing spaces from the given pattern with the replace argument
current- Returns the current time (with the specified string, and replaces all internal
tokenize(string,pattern)
time() timezone) sequences of white space with one and
returns the result. If there is no string
Functions on Boolean Values
Functions on Strings argument it does the same on the current
node boolean Returns a boolean value for a
string(arg)
(arg) number, string, or node-set
normalize-unicode()
Returns the string value of the argument.
upper-case(string) not(arg) The argument is first reduced to a
The argument could be a number, boolean,
boolean value by applying the
or node-set Converts the string argument to upper-case
boolean() function. Returns true if
codepoints-to-string(int,int,...) lower-case(string) the boolean value is false, and false
Returns a string from a sequence of code if the boolean value is true
Converts the string argument to lower-case
points true() Returns the boolean value true
translate(string1,string2,string3)
string-to-codepoints(string) false() Returns the boolean value false
Converts string1 by replacing the characters
Returns a sequence of code points from a in string2 with the characters in string3
string
escape-uri(stringURI,esc-res)
codepoint-equal(comp1,comp2)
contains(string1,string2)
Returns true if the value of comp1 is equal to
Returns true if string1 contains string2,
the value of comp2, according to the
otherwise it returns false
Unicode code point collation, otherwise it
returns false starts-with(string1,string2)
compare(comp1,comp2) Returns true if string1 starts with string2,
otherwise it returns false
Returns -1 if comp1 is less than comp2, 0 if
comp1 is equal to comp2, or 1 if comp1 is ends-with(string1,string2)
greater than comp2 (according to the rules
Returns true if string1 ends with string2,
of the collation that is used)
otherwise it returns false
string-join((string,string,...),sep) substring-before(str1,str2)
Returns a string created by concatenating
Returns the start of string1 before string2
the string arguments and using the sep
occurs in it
argument as the separator
substring-after(str1,str2)
substring(string,start,len)
Returns the remainder of string1 after
Returns the substring from the start position
string2 occurs in it
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
By Jin Lei (Univer) Published 21st November, 2012. Sponsored by CrosswordCheats.com
cheatography.com/univer/ Last updated 5th June, 2014. Learn to solve cryptic crosswords!
jinlei.me Page 3 of 3. http://crosswordcheats.com