xslt函数详解

current() 函数
 
--------------------------------------------------------------------------------
 
定义与用法
 
current() 函数返回一个仅包含当前节点的节点集。通常当前节点和上下文节点是一样的。
 
是一样的。
 
然而,有一点不同。看下面的 XPath 表达式: "catalog/cd" 。这个表达式选择 作为当前节点,然后选择 的子节点 。这意味着在赋值的每一步, "." 都有不同的意义。
 
下面这行代码:
将会处理所有 title 属性的值与当前节点的 ref 属性的值相等的所有 cd 元素。
 
这与下面有区别
下面这段代码将会处理所有 title 属性的值与 ref 属性的值相等的所有 cd 元素。
 
--------------------------------------------------------------------------------
 
语法
node-set current() 
 
例子 1
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
 
 
 
    Current node:
   
 
 
 
 
 
document() 函数
 
--------------------------------------------------------------------------------
 
定义与用法
document() 函数用来访问外部的 XML 文档。外部 XML 文档必须是正确可解析的。
 
 
 
--------------------------------------------------------------------------------
 
语法
node-set document(object,node-set?) 
 
参数
参数
说明
object
必须。定义 XML 文档的 URI
node-set
可选。用来处理相关的 URI
 
 
例子 1
Document.xml
 hrGroup.xml
 myGroup.xml
 
document.xsl
 
 
 
  
 
 
 
 
 
 
hrGroup.xml
 mo
 bo
 ko
 lo
 
myGroup.xml
 john
 jane
 jon
 jan
 
例子 2
下面这个例子,显示如何使用两个参数。
第二个参数必须是一个节点集,作为第一个参数的基准 URI ,当没有第二个参数时,第一个参数的基准 URI 就是 XSL URI ,如下,把 a.xml 放到 subdir 目录下,而另外两个在 ../ ,如果 document('a.xml', .) 的第二个参数不写,将以 ../ 作为 a.xml 的目录,就会报错,您可以实验一下。
document2.xsl
  
 
  
  
      One Argument
     
        
      
 
      Two Argument
     
        
     
  
  
 
Subdir/a.xml
 
b.xml
 
element-available() 函数
 
--------------------------------------------------------------------------------
 
定义与用法
 
element-available() 函数检查 XSLT 处理器是否能处理指定的元素。
 
这个函数只能用来检查在模板里出现的元素,这些元素是:
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 
 
--------------------------------------------------------------------------------
 
语法
boolean element-available(string) 
 
参数
参数
说明
string
必须。指定要检查元素。
 
 
例子 1
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

xsl:comment is supported.

xsl:comment is not supported.

xsl:delete is supported.

xsl:delete is not supported.

 
 
 
 
format-number() 函数
 
--------------------------------------------------------------------------------
 
定义与用法
 
format-number() 函数用来格式化一个数字字符串。
 
--------------------------------------------------------------------------------
 
语法
string format-number(number,format,[decimalformat]) 
 
参数
参数
说明
number
Required. Specifies the number to be formatted
必须。指定要格式化的数字
format
必须。指定格式化的模式。
&S226; # ( 指示一个数字。 比如: ####) 
&S226; 0 (Denotes leading and following zeros. Example: 0000.00) 
&S226; . ( 指定小数点的位置。比如 : ###.##) 
&S226; , (The group separator for thousands. Example: ###,###.##) 
&S226; % (Displays the number as a percentage. Example: ##%) 
&S226; ; (Pattern separator. The first pattern will be used for positive numbers and the second for negative numbers) 
 
decimalformat
可选。用来指定使用的 元素的名称。
 
 
例子 1
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">




 
 
 
 
 
function-available() 函数
 
--------------------------------------------------------------------------------
 
定义与用法
 
function-available() 函数检查指定的函数在 XSLT 处理器中是否支持。
You may test the XSLT functions and the inherited XPath functions.
您可以检查 XSLT 函数和 XPath 函数。
 
--------------------------------------------------------------------------------
 
语法
boolean function-available(string) 
 
参数
参数
说明
string
必须。指定要检查的函数。
 
 
例子 1
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

sum() is supported.

sum() is not supported.

current() is supported.

 
 
 
 
generate-id() 函数
 
--------------------------------------------------------------------------------
 
定义与用法
 
generate-id() 函数返回一个唯一标示指定节点的字符串。
 
如果指定的节点集是空的,将返回一个空字符串。如果您忽略了节点集的参数,默认是当前节点。
 
--------------------------------------------------------------------------------
 
语法
string generate-id(node-set?) 
 
参数
参数
说明
node-set
可选。指定要生成唯一 id 的节点集
 
 
例子 1
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

Artists:


  • Artist:

    Title:

    Price:

     
     
     
    key() 函数
     
    --------------------------------------------------------------------------------
     
    定义与用法
    key() 函数使用 元素指定的索引返回文档中的一个节点集。
     
    --------------------------------------------------------------------------------
     
    语法
    node-set key(string, object) 
     
    参数
    参数
    说明
    string
    必须。指定 xsl:key 元素的名称。
    object
    必须。要查找的字符串。
     
     
    例子 1
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
     
     

     Title:
     
     Artist:
     
     Price:
     

     
     
     
     
    system-property() 函数
     
    --------------------------------------------------------------------------------
     
    定义与用法
    The system-property() function returns the value of the system property specified by the name.
    system-property() 函数返回指定名称的系统属性。
    System properties in the XSLT namespace:
    XSLT 名称空间里的系统属性:
    xsl:version - 指出 XSLT 的版本
    xsl:vendor - 指出 XSLT 处理器 ( 比如 James Clark)
    xsl:vendor-url - 指出处理器的 URL( 比如 http://www.jclark.com/)
    (注:当用 XT 解析时 xsl:vendor James Clark xsl:vendor-url http://www.jclark.com/ ,用 IE 就为 Microsoft,http://www.microsoft.com
    --------------------------------------------------------------------------------
     
    语法
    object system-property(string) 
     
    参数
    参数
    说明
    string
    必须。指定返回的系统属性
     
     
    例子 1
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

    Version:

    Vendor:

    Vendor URL:

     
     
     
     
    unparsed-entity-uri() 函数
     
    --------------------------------------------------------------------------------
     
    定义与用法
     
    unparsed-entity-uri() 函数返回未解析的实体的 URI 。实体名称必须与传递的参数匹配。如果没有这样的实体,那么返回空串。
     
    如果 DTD 包含下面的声明:
     
    下面的表达式
    unparsed-entity-uri('pic')
     
    将会返回 "picture.jpg" URI
     
    --------------------------------------------------------------------------------
     
    语法
    string unparsed-entity-uri(string) 
     
    参数
    参数
    说明
    string
    必须。指定未解析实体
     
     
     
    例子 1
    XML 文件
     
     
     
     
     
    ]>
     
     XML Developer's Guide
     
     
     Midnight Rain
     
     
    XSL 文件
     
     
     
      
       

    unparsed-entity-uri()

       
        
  •       unparsed-entity-uri('pic')
                   
        
       
      
     
     
     
     
    运算符和特殊字符
    !=  不等于
    "" (literal) 文字
    '' (literal) 文字
    () (grouping) 分组
    * (all nodes) 所有节点
    * (multiplication) 通配符
    +
    -
    - (unary minus) 
    . (self axis short form) 当前元素
    .. (parent axis short form) 父元素
    / (step separator) 选择子元素
    // (descendant-or-self axis short form) 选择子元素,不论多深
    :: (axis specifier) (不知道怎么翻译合适,没用过)
    < 小于
    <= 小于等于
    = 等于
    > 大于
    >= 大于等于
    @ (attribute axis short form) 选择属性
    @* (all attributes) 选择所有属性
    [] (predicate) 断言,指定过滤样式
    And
    axis nodetest predicate (step) 
    div The div operator performs floating-point division according to IEEE 754. (原文放上来,不知道怎么翻译合适,没用过)
    func() (function call) 调用函数
    mod 取余
    name (node test) 
    or
    | (union) 集合
     
     
    附录  
      如果没有特殊说明,将使用下面的 XML 文件
    在这里引入您的 XSL 文件 -->
    cdcatalog_element.xsl"?>
     
     Empire Burlesque
     Bob Dylan
     USA
     Columbia
     10.90
     1985
     
     
     Hide your heart
     Bonnie Tyler
     UK
     CBS Records
     9.90
     1988
     
     
     Greatest Hits
     Dolly Parton
     USA
     RCA
     9.90
     1982
     
     
      Still got the blues
     Gary Moore
     UK
     Virgin records
     10.20
     1990
     
     
     Eros
     Eros Ramazzotti
     EU
     BMG
     9.90
     1997
     
     
     One night only
     Bee Gees
     UK
     Polydor
     10.90
     1998
     
     
     Sylvias Mother
     Dr.Hook
     UK
     CBS
     8.10
     1973
     
     
     Maggie May
     Rod Stewart
     UK
     Pickwick
     8.50
     1990
     
     
     Romanza
     Andrea Bocelli
     EU
     Polydor
     10.80
      1996
     
     
     When a man loves a woman
     Percy Sledge
     USA
     Atlantic
     8.70
     1987
     
     
     Black angel
     Savage Rose
     EU
     Mega
     10.90
     1995
     
     
     1999 Grammy Nominees
     Many
     USA
     Grammy
     10.20
     1999
     
     
     For the good times
     Kenny Rogers
     UK
     Mucik Master
     8.70
     1995
     
     
     Big Willie style
     Will Smith
     USA
     Columbia
     9.90
     1997
     
     
     Tupelo Honey
     Van Morrison
     UK
     Polydor
     8.20
     1971
     
     
     Soulsville
     Jorn Hoel
     Norway
     WEA
     7.90
     1996
     
     
     The very best of
     Cat Stevens
     UK
     Island
     8.90
     1990
     
     
     Stop
     Sam Brown
      UK
     A and M
     8.90
     1988
     
     
     Bridge of Spies
     T`Pau
     UK
     Siren
     7.90
     1987
     
     
     Private Dancer
     Tina Turner
     UK
     Capitol
     8.90
     1983
     
     
     Midt om natten
     Kim Larsen
     EU
     Medley
     7.80
     1983
     
     
     Pavarotti Gala Concert
     Luciano Pavarotti
     UK
     DECCA
     9.90
     1991
     
     
     The dock of the bay
     Otis Redding
     USA
     Atlantic
     7.90
     1987
     
     
     Picture book
     Simply Red
     EU
     Elektra
     7.20
     1985
     
     
     Red
     The Communards
     UK
     London
     7.80
     1987
     
     
     Unchain my heart
     Joe Cocker
     USA
     EMI
     8.20
     1987
     
     

    你可能感兴趣的:(xml)