xsl函数浏览
XSLT supplies a number of functions.
<!--<RuleTypeName>GIM.Rule.Common.CommonRule,GIM.Rule.Common</RuleTypeName>-->
--------------------------------------------------------------------------------
XSLT Functions
Name Description
current() Returns the current node
document() Used to access the nodes in an external XML document
element-available() Tests whether the element specified is supported by the XSLT processor
format-number() Converts a number into a string
function-available() Tests whether the function specified is supported by the XSLT processor
generate-id() Returns a string value that uniquely identifies a specified node
key() Returns a node-set using the index specified by an element
system-property() Returns the value of the system properties
unparsed-entity-uri() Returns the URI of an unparsed entity
--------------------------------------------------------------------------------
Inherited XPath Functions
Node Set Functions
Name Description Syntax
count() 返回结点个数 number=count(node-set)
id() Selects elements by their unique ID node-set=id(value)
last() 返回最后一个结点的需要 number=last()
local-name() Returns the local part of a node. A node usually consists of a prefix, a colon, followed by the local name string=local-name(node)
name() 返回一个结点的名称 string=name(node)
namespace-uri() 返回一个结点的名称空间 uri=namespace-uri(node)
position() 返回结点序号 number=position()
-------------------------------------------------------------------
String Functions
Name Description Syntax & Example
concat() 返回一个将N个字符串连接的值 string=concat(val1, val2, ..)
示例:
concat('The',' ','XML')
返回结果: 'The XML'
contains() 如果val包含substr则返回true bool=contains(val,substr)
示例:
contains('XML','X')
返回结果: true
normalize-space() 删除多余空格 string=normalize-space(string)
示例:
normalize-space(' The XML ')
返回结果: 'The XML'
starts-with() 如果String以substr开始则返回true bool=starts-with(string,substr)
示例:
starts-with('XML','X')
返回结果: true
string() 将数字转换为字符 string(value)
示例:
string(314)
返回结果: '314'
string-length() 返回一个字符串的长度 number=string-length(string)
示例:
string-length('Beatles')
返回结果: 7
substring() 将string从start开始一直截取到第length位 string=substring(string,start,length)
示例:
substring('Beatles',1,4)
返回结果: 'Beat'
substring-after() 将string以substr分割,选取最后一个 string=substring-after(string,substr)
示例:
substring-after('12/10','/')
返回结果: '10'
substring-before() 将string以substr分割,选取第一个 string=substring-before(string,substr)
示例:
substring-before('12/10','/')
返回结果: '12'
translate() 对字串进行替换操作 string=translate(value,string1,string2)
示例:
translate('12:30',':','!')
返回结果: '12!30'
晕死了,这个函数,如果替换多个字符的话,他会一个一个的判断。
Number Functions
Name Description Syntax & Example
ceiling() 返回一个整数 number=ceiling(number)
示例:
ceiling(3.14)
返回结果: 4
floor() 返回一个整数 number=floor(number)
示例:
floor(3.14)
返回结果: 3
number() 将字符型转为数字 number=number(value)
示例:
number('100')
返回结果: 100
round() 返回一个实数的四舍五入的整数值 integer=round(number)
示例:
round(3.14)
返回结果: 3
sum() 返回结点值的和 number=sum(nodeset)
示例:
sum(/cd/price)
----------------------------------------------------------------------------
Boolean Functions
Name Description Syntax & Example
boolean() Converts the value argument to Boolean and returns true or false bool=boolean(value)
false() 返回false false()
示例:
number(false())
返回结果: 0
lang() Returns true if the language argument matches the language of the the xsl:lang element, otherwise it returns false bool=lang(language)
not() Returns true if the condition argument is false, and false if the condition argument is true bool=not(condition)
示例:
not(false())
true() Returns true true()
示例:
number(true())
返回结果: 1
--------------------------------------------------------------------------------
The current() Function
--------------------------------------------------------------------------------
Definition and Usage
The current() function returns a node-set that contains only the current node. Usually the current node and the context node are the same.
is equal to
However, there is one difference. Look at the following XPath expression: 'catalog/cd'. This expression selects the child nodes of the current node, and then it selects the child nodes of the nodes. This means that on each step of evaluation, the '.' has a different meaning.
The following line:
will process all cd elements that have a title attribute with value equal to the value of the current node's ref attribute.
This is different from
that will process all cd elements that have a title attribute and a ref attribute with the same value.
--------------------------------------------------------------------------------
Syntax
node-set current()
Example 1
Current node:
If you have Netscape 6 or IE 5 or higher you can view: the XML file and the XSL file.
View the result in Netscape 6 or IE 6
The document() Function
--------------------------------------------------------------------------------
Definition and Usage
The document() function is used to access nodes in an external XML document. The external XML document must be valid and parsable.
One way to use this function is to look up data in an external document. For example we want to find the Celsius value from a Fahrenheit value and we refer to a document that contains some pre-computed results:
--------------------------------------------------------------------------------
Syntax
node-set document(object,node-set?)
Parameters
Parameter Description
object Required. Defines an URI to an external XML document
node-set Optional. Used to resolve relative URI
--------------------------------------------------------------------------------
The element-available() Function
--------------------------------------------------------------------------------
Definition and Usage
The element-available() function returns a Boolean value that indicates whether the element specified is supported by the XSLT processor.
This function can only be used to test elements that can occur in a template body. These elements are:
xsl:apply-imports
xsl:apply-templates
xsl:attributes
xsl:call-template
xsl:choose
xsl:comment
xsl:copy
xsl:copy-of
xsl:element
xsl:fallback
xsl:for-each
xsl:if
xsl:message
xsl:number
xsl:processing instruction
xsl:text
xsl:value-of
xsl:variable