xsl 函数大全

XSLTsuppliesanumberoffunctions.


--------------------------------------------------------------------------------

XSLTFunctions
NameDescription
current()Returnsthecurrentnode
document()UsedtoaccessthenodesinanexternalXMLdocument
element-available()TestswhethertheelementspecifiedissupportedbytheXSLTprocessor
format-number()Convertsanumberintoastring
function-available()TestswhetherthefunctionspecifiedissupportedbytheXSLTprocessor
generate-id()Returnsastringvaluethatuniquelyidentifiesaspecifiednode
key()Returnsanode-setusingtheindexspecifiedbyanelement
system-property()Returnsthevalueofthesystemproperties
unparsed-entity-uri()ReturnstheURIofanunparsedentity


--------------------------------------------------------------------------------

InheritedXPathFunctions
NodeSetFunctions
NameDescriptionSyntax
count()返回结点个数number=count(node-set)
id()SelectselementsbytheiruniqueIDnode-set=id(value)
last()返回最后一个结点的需要number=last()
local-name()Returnsthelocalpartofanode.Anodeusuallyconsistsofaprefix,acolon,followedbythelocalnamestring=local-name(node)
name()返回一个结点的名称string=name(node)
namespace-uri()返回一个结点的名称空间uri=namespace-uri(node)
position()返回结点序号number=position()

StringFunctions
NameDescriptionSyntax&Example
concat()返回一个将N个字符串连接的值string=concat(val1,val2,..)
示例:
concat('The','','XML')
返回结果:'TheXML'

contains()如果val包含substr则返回truebool=contains(val,substr)

示例:
contains('XML','X')
返回结果:true

normalize-space()删除多余空格string=normalize-space(string)
示例:
normalize-space('TheXML')
返回结果:'TheXML'

starts-with()如果String以substr开始则返回truebool=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'

NumberFunctions
NameDescriptionSyntax&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)

BooleanFunctions
NameDescriptionSyntax&Example
boolean()ConvertsthevalueargumenttoBooleanandreturnstrueorfalsebool=boolean(value)
false()返回falsefalse()
示例:
number(false())
返回结果:0

lang()Returnstrueifthelanguageargumentmatchesthelanguageofthethexsl:langelement,otherwiseitreturnsfalsebool=lang(language)
not()Returnstrueiftheconditionargumentisfalse,andfalseiftheconditionargumentistruebool=not(condition)
示例:
not(false())

true()Returnstruetrue()
示例:
number(true())
返回结果:1


--------------------------------------------------------------------------------

Thecurrent()Function

--------------------------------------------------------------------------------

DefinitionandUsage
Thecurrent()functionreturnsanode-setthatcontainsonlythecurrentnode.Usuallythecurrentnodeandthecontextnodearethesame.


isequalto


However,thereisonedifference.LookatthefollowingXPathexpression:'catalog/cd'.Thisexpressionselectsthechildnodesofthecurrentnode,andthenitselectsthechildnodesofthenodes.Thismeansthatoneachstepofevaluation,the'.'hasadifferentmeaning.

Thefollowingline:


willprocessallcdelementsthathaveatitleattributewithvalueequaltothevalueofthecurrentnode'srefattribute.

Thisisdifferentfrom


thatwillprocessallcdelementsthathaveatitleattributeandarefattributewiththesamevalue.


--------------------------------------------------------------------------------

Syntax
node-setcurrent()

Example1




Currentnode:




IfyouhaveNetscape6orIE5orhigheryoucanview:theXMLfileandtheXSLfile.

ViewtheresultinNetscape6orIE6

Thedocument()Function


--------------------------------------------------------------------------------

DefinitionandUsage
Thedocument()functionisusedtoaccessnodesinanexternalXMLdocument.TheexternalXMLdocumentmustbevalidandparsable.

Onewaytousethisfunctionistolookupdatainanexternaldocument.ForexamplewewanttofindtheCelsiusvaluefromaFahrenheitvalueandwerefertoadocumentthatcontainssomepre-computedresults:

--------------------------------------------------------------------------------

Syntax
node-setdocument(object,node-set?)


Parameters
ParameterDescription
objectRequired.DefinesanURItoanexternalXMLdocument
node-setOptional.UsedtoresolverelativeURI


--------------------------------------------------------------------------------

Theelement-available()Function

--------------------------------------------------------------------------------

DefinitionandUsage
Theelement-available()functionreturnsaBooleanvaluethatindicateswhethertheelementspecifiedissupportedbytheXSLTprocessor.

Thisfunctioncanonlybeusedtotestelementsthatcanoccurinatemplatebody.Theseelementsare:

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:processinginstruction
xsl:text
xsl:value-of
xsl:variable

--------------------------------------------------------------------------------

Syntax
booleanelement-available(string)

Parameters
ParameterDescription
stringRequired.Specifiestheelementtotest

Example1

xsl:commentissupported.


xsl:commentisnotsupported.


xsl:deleteissupported.


xsl:deleteisnotsupported.


IfyouhaveNetscape6orIE5orhigheryoucanview:theXSLfile.

ViewtheresultinNetscape6orIE6

--------------------------------------------------------------------------------

Theformat-number()Function

--------------------------------------------------------------------------------

DefinitionandUsage
Theformat-number()functionisusedtoconvertanumberintoastring.


--------------------------------------------------------------------------------

Syntax
stringformat-number(number,format,[decimalformat])

Parameters
ParameterDescription
numberRequired.Specifiesthenumbertobeformatted
formatRequired.Specifiestheformatpattern.Herearesomeofthecharactersusedintheformattingpattern:
#(Denotesadigit.示例:####)
0(Denotesleadingandfollowingzeros.示例:0000.00)
.(Thepositionofthedecimalpoint示例:###.##)
,(Thegroupseparatorforthousands.示例:###,###.##)
%(Displaysthenumberasapercentage.示例:##%)
;(Patternseparator.Thefirstpatternwillbeusedforpositivenumbersandthesecondfornegativenumbers)

decimalformatOptional.

Example1

IfyouhaveNetscape6orIE5orhigheryoucanview:theXSLfile.

ViewtheresultinNetscape6orIE6


Thefunction-available()Function


--------------------------------------------------------------------------------

DefinitionandUsage
Thefunction-available()functionreturnsaBooleanvaluethatindicateswhetherthefunctionspecifiedissupportedbytheXSLTprocessor.

YoumaytesttheXSLTfunctionsandtheinheritedXPathfunctions.


--------------------------------------------------------------------------------

Syntax
booleanfunction-available(string)


Parameters
ParameterDescription
stringRequired.Specifiesthefunctiontotest


Example1

sum()issupported.


sum()isnotsupported.


current()issupported.


current()isnotsupported.



IfyouhaveNetscape6orIE5orhigheryoucanview:theXSLfile.

ViewtheresultinNetscape6orIE6

--------------------------------------------------------------------------------

Thegenerate-id()Function

--------------------------------------------------------------------------------

DefinitionandUsage
Thegenerate-id()functionreturnsastringvaluethatuniquelyidentifiesaspecifiednode.

Ifthenode-setspecifiedisempty,anemptystringisreturned.Ifyouomitthenode-setparameter,itdefaultstothecurrentnode.


--------------------------------------------------------------------------------

Syntax
stringgenerate-id(node-set?)

Parameters
ParameterDescription
node-setOptional.Specifiesonwhichnode-settogenerateauniqueid

Example1

Artists:


--------------------------------------------------------------------------------

Artist:


Title:

Price:
--------------------------------------------------------------------------------

IfyouhaveNetscape6orIE5orhigheryoucanview:theXMLfileandtheXSLfile.

ViewtheresultinNetscape6orIE6

--------------------------------------------------------------------------------

Thekey()Function

--------------------------------------------------------------------------------

DefinitionandUsage
Thekey()functionreturnsanode-setfromthedocument,usingtheindexspecifiedbyanelement.


--------------------------------------------------------------------------------

Syntax
node-setkey(string,object)

Parameters
ParameterDescription
stringRequired.Specifiesthenameofanxsl:keyelement
objectRequired.Astringtosearchfor

Example1



Title:

Artist:

Price:

IfyouhaveNetscape6orIE5orhigheryoucanview:theXMLfileandtheXSLfile.

ViewtheresultinNetscape6orIE6

--------------------------------------------------------------------------------

Thesystem-property()Function

--------------------------------------------------------------------------------

DefinitionandUsage
Thesystem-property()functionreturnsthevalueofthesystempropertyspecifiedbythename.

SystempropertiesintheXSLTnamespace:

xsl:version-TheversionofXSLTimplementedbytheprocessor
xsl:vendor-ThevendoroftheXSLTprocessor
xsl:vendor-url-TheURLidentifyingthevendoroftheXSLTprocessor

--------------------------------------------------------------------------------

Syntax
objectsystem-property(string)

Parameters
ParameterDescription
stringRequired.Specifiesthesystempropertytoreturnthevalueof

Example1


Version:


Vendor:


VendorURL:


IfyouhaveNetscape6orIE5orhigheryoucanview:theXSLfile.

ViewtheresultinNetscape6orIE6

--------------------------------------------------------------------------------

Theunparsed-entity-uri()Function

--------------------------------------------------------------------------------

DefinitionandUsage
Theunparsed-entity-uri()functionreturnstheURIofanunparsedentity.Thenameoftheentitymustmatchthepassedargument.Ifthereisnosuchentityanemptystringisreturned.

IftheDTDcontainsthefollowingdeclaration:


thefollowingexpression:

unparsed-entity-uri('pic')

willreturntheURIforthefile'picture.jpg'.


--------------------------------------------------------------------------------

Syntax
stringunparsed-entity-uri(string)

Parameters
ParameterDescription
stringRequired.Specifiesthenameofanunparsedentity

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值