`

xsl函数浏览

    博客分类:
  • XML
阅读更多
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 

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

Syntax
boolean element-available(string)
 

Parameters
Parameter Description 
string Required. Specifies the element to test 

Example 1




xsl:comment is supported.


xsl:comment is not supported.



xsl:delete is supported.


xsl:delete is not supported.




 

If you have Netscape 6 or IE 5 or higher you can view: the XSL file.

View the result in Netscape 6 or IE 6


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

The format-number() Function
 
--------------------------------------------------------------------------------

Definition and Usage
The format-number() function is used to convert a number into a string.


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

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

Parameters
Parameter Description 
number Required. Specifies the number to be formatted 
format Required. Specifies the format pattern. Here are some of the characters used in the formatting pattern: 
# (Denotes a digit. 示例: ####) 
0 (Denotes leading and following zeros. 示例: 0000.00) 
. (The position of the decimal point 示例: ###.##) 
, (The group separator for thousands. 示例: ###,###.##) 
% (Displays the number as a percentage. 示例: ##%) 
; (Pattern separator. The first pattern will be used for positive numbers and the second for negative numbers) 
 
decimalformat Optional. 

Example 1










 

If you have Netscape 6 or IE 5 or higher you can view: the XSL file.

View the result in Netscape 6 or IE 6


The function-available() Function
 


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

Definition and Usage
The function-available() function returns a Boolean value that indicates whether the function specified is supported by the XSLT processor.

You may test the XSLT functions and the inherited XPath functions.


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

Syntax
boolean function-available(string)
 


Parameters
Parameter Description 
string Required. Specifies the function to test 


Example 1




sum() is supported.


sum() is not supported.



current() is supported.


current() is not supported.




 


If you have Netscape 6 or IE 5 or higher you can view: the XSL file.

View the result in Netscape 6 or IE 6


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

The generate-id() Function
 
--------------------------------------------------------------------------------

Definition and Usage
The generate-id() function returns a string value that uniquely identifies a specified node.

If the node-set specified is empty, an empty string is returned. If you omit the node-set parameter, it defaults to the current node.


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

Syntax
string generate-id(node-set?)
 

Parameters
Parameter Description 
node-set Optional. Specifies on which node-set to generate a unique id  

Example 1



Artists:





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

Artist: 


Title: 

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



 

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 key() Function
 
--------------------------------------------------------------------------------

Definition and Usage
The key() function returns a node-set from the document, using the index specified by an element.


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

Syntax
node-set key(string, object)
 

Parameters
Parameter Description 
string Required. Specifies the name of an xsl:key element 
object Required. A string to search for 

Example 1





  
  Title: 
  
  Artist: 
  
  Price: 
  



 

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 system-property() Function
 
--------------------------------------------------------------------------------

Definition and Usage
The system-property() function returns the value of the system property specified by the name.

System properties in the XSLT namespace:

xsl:version - The version of XSLT implemented by the processor 
xsl:vendor - The vendor of the XSLT processor 
xsl:vendor-url - The URL identifying the vendor of the XSLT processor 

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

Syntax
object system-property(string)
 

Parameters
Parameter Description 
string Required. Specifies the system property to return the value of  

Example 1




Version:


Vendor:


Vendor URL:




 

If you have Netscape 6 or IE 5 or higher you can view: the XSL file.

View the result in Netscape 6 or IE 6


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

The unparsed-entity-uri() Function
 
--------------------------------------------------------------------------------

Definition and Usage
The unparsed-entity-uri() function returns the URI of an unparsed entity. The name of the entity must match the passed argument. If there is no such entity an empty string is returned.

If the DTD contains the following declaration:


the following expression:

unparsed-entity-uri('pic')

will return the URI for the file 'picture.jpg'.

  

分享到:
评论

相关推荐

    XSL转换XML为HTML树显示

    总的来说,XSL转换XML为HTML树显示是一项常见的数据展示技术,它结合了XML的结构化特性,XSLT的转换能力,以及HTML和JavaScript的交互性,为用户提供了一种直观且易于操作的方式来浏览和理解XML数据。在实际应用中,...

    xml转换xsl-绿色软件

    XSLT还支持条件语句、循环、函数调用等高级编程特性,使得转换过程可以非常灵活和复杂。 TransformXslt可能是这个绿色软件的主程序名称,可能包含以下功能: 1. **导入XML文件**:用户可以通过界面选择要转换的XML...

    XSL Transform Self-Documentation-开源

    在这个情况下,XSLT被用来将元数据转化为美观且用户友好的网页,这使得开发者可以在线查看和浏览XSL样式表的详细文档。 在压缩包文件“xslt_documentation_public”中,我们可以期待找到以下内容: 1. 自我注解的...

    简单的xml以及分层浏览

    SAX(Simple API for XML)是一种基于事件的解析方式,逐行读取XML文档,当遇到元素、属性等时触发相应的事件处理函数。 四、XML命名空间 XML命名空间用于解决元素和属性名称的冲突问题。通过`xmlns`属性指定命名...

    兼容IE、FireFox、Chrome等浏览器的xml处理函数js代码

    xml_transformNode:xsl转换。 xml_text:节点的文本。 selectSingleNode:根据XPath选择单个节点。 selectNodes:根据XPath选择多个节点。 全部代码(zyllibjs_xml.js)—— 代码如下: /* zyllibjs_xml XML处理 @...

    JavaScript编程总结

    在IE浏览器中,可以通过以下代码来加载XML和XSL文件,并进行转换: ```javascript var xml = new ActiveXObject("Microsoft.XMLDOM"); xml.async = false; xml.load("cdcatalog.xml"); var xsl = new ...

    无涯教程(LearnFk)-Xpath教程完整离线版.pdf

    XSL由几个主要部分组成:XSLT(用于转换XML文档到其他类型文档的样式表)、XPath(用于浏览XML文档)、XSL-FO(用于格式化XML文档)。而在这之中,XSLT使用XPath作为主要元素之一,XPath成为了XSLT规范中不可或缺的...

    XSLT学习资料代码资料上传

    分页功能通常用于显示大量数据时,让用户逐页浏览。在这个例子中,HTML页面可能展示了如何在网页上实现分页导航。 3. **paging.js**: JavaScript文件用于增加交互性,可能包含了分页功能的动态逻辑,如点击按钮切换...

    AJAX技术总结

    尽管早期版本的IE浏览器提供了对XSL的支持,但其他浏览器的兼容性较差。通过XSL,可以将XML数据转换成各种格式的输出,如HTML、PDF等。 综上所述,AJAX技术通过对现有Web技术的有效组合,实现了更加丰富的用户体验...

    javascript 树形控件xtree

    JavaScript中的树形控件XTree是一种常见的用于展示层次结构数据的UI组件,广泛应用于网站的导航菜单、文件系统浏览、组织结构展示等场景。XTree以其灵活的配置、丰富的交互功能以及良好的性能,深受开发者喜爱。 ...

    ajax开发利器

    2. **XSL函数**:提供了一系列内置函数,用于处理XML数据,如排序、选择节点等。 3. **XSLT与JavaScript的结合**:通过JavaScript解析XSLT,将转换后的HTML插入到DOM中。 **综合运用** 在实际开发中,Ajax开发...

    javascript 常用代码大全

    `initialize()`函数使用ActiveX对象`Microsoft.XMLDOM`加载XML和XSL文档,并将XML文档转换为HTML后插入到页面中的`folderTree`元素内。这展示了如何在客户端使用XML和XSLT进行数据展示。 ### 3. 数据验证 文件中...

    《Python入门经典以解决计算问题为导向的Python编程实践》.((美)William F).[PDF]@ckook.pdf

    《python入门经典:以解决计算问题为导向的python编程实践》不仅适合入门级的python程序员系统学习,也适合作为高等院校计算机和非...附录c绘图和数值工具:快速浏览 附录dpython 3.0 附录eascii码表 附录f优先级

    2021-2022计算机二级等级考试试题及答案No.10060.docx

    **解析**: Internet Explorer 是由微软开发的一款网页浏览器,可以用来浏览Internet上的网页。 ### 21. 访问控制符 - **知识点**: 在面向对象编程中,访问控制符用于控制类成员的可见性。 **解析**: 私有保护访问...

    IE中调试javascript

    - 在“浏览”部分取消勾选“禁用脚本调试(Internet Explorer)”和“禁用脚本调试(其他)”。 #### 四、调试方法 ##### 1. 被动调试 被动调试也称为自动调试,即当IE遇到JavaScript语法错误或运行时错误时自动弹出...

    2021-2022计算机二级等级考试试题及答案No.3.docx

    16. 在浏览窗口中,逻辑删除记录通常不会立即影响界面显示,因此通过按Delete键直接删除记录的操作通常不会实现逻辑删除。 17. JSP内置对象**response**的`getOutputStream()`方法用于获取到客户端的输出流,服务器...

    特殊字符Unicode

    这些语言都有特定的库和函数来支持Unicode,例如Java中的`java.lang.String`类提供了多种处理Unicode的方法,Python的内置字符串类型默认就是Unicode支持的。 另一个标签“工具”可能是指用于查看和操作Unicode字符...

    XML高级编程pdf

    15.8 “以编号浏览”XSL样式表 15.9 “以名字浏览”XSL样式表 15.10 激活XSL样式表 15.11 问题:保持树的同步 15.12 小结 第16章 实例研究2—XML和分布式 应用程序 16.1 目前的弱点 16.2 构建网络应用程序的...

    AJAX基础概念、核心技术与典型案例(内涵动态实例)

    程序描述:本章将使用Ajax技术实现无刷新即可浏览RSS的阅读器。添加一个RSS地址时,自动保存到数据库。打开阅读RSS时,自动获取最新的RSS内容,而无需刷新页面。 /RSSReader.jsp RSS阅读器 /rss.js ...

    XML高级编程 (Extensible Markup Language)

    15.8 “以编号浏览”XSL样式表 15.9 “以名字浏览”XSL样式表 15.10 激活XSL样式表 15.11 问题:保持树的同步 15.12 小结 第16章 实例研究2—XML和分布式 应用程序 16.1 目前的弱点 16.2 构建网络应用程序的...

Global site tag (gtag.js) - Google Analytics