XSL Transformations (XSLT) Version 2.0

TransWiki - an Open Translation Project(OTP)

Table of contents

1.1 W3C Working Draft 12 November 2003
1.2 Abstract摘要
1.3 Status of this Document
1.4 本文档状态
1.5 Table of Contents

1.6 1 Introduction

1.7 2 Concepts

1.8 3 Stylesheet Structure

1.9 4 Data Model

1.10 5 Syntactic Constructs

1.11 6 模板规则(Template Rules)

1.12 7 Repetition
1.13 8 Conditional Processing

1.14 9 Variables and Parameters

1.15 10 Callable Components

1.16 11 Creating Nodes and Sequences

1.17 12 Numbering

1.18 13 Sorting

1.19 14 Grouping

1.20 15 Regular Expressions

1.21 16 Additional Functions

1.22 17 Messages
1.23 18 Extensibility and Fallback

1.24 19 Result Trees

1.25 20 Serialization

1.26 E Summary of Error Conditions (Non-Normative)
1.27 F Checklist of Implementation-Defined Features (Non-Normative)
1.28 G Schema for XSLT Stylesheets (Non-Normative)
1.29 H Acknowledgements (Non-Normative)
1.30 I Checklist of Requirements (Non-Normative)
1.31 J Summary of Issues (Non-Normative)

1.32 K Changes from XSLT 1.0 (Non-Normative)

XSL Transformations (XSLT) Version 2.0


W3C Working Draft 12 November 2003



This version:
http://www.w3.org/TR/2003/WD-xslt20-20031112/ (http://www.w3.org/TR/2003/WD-xslt20-20031112/)
Latest version:
http://www.w3.org/TR/xslt20/ (http://www.w3.org/TR/xslt20/)
Previous versions:
http://www.w3.org/TR/2003/WD-xslt20-20030502/ (http://www.w3.org/TR/2003/WD-xslt20-20030502/) http://www.w3.org/TR/2002/WD-xslt20-20021115/ (http://www.w3.org/TR/2002/WD-xslt20-20021115/) http://www.w3.org/TR/2002/WD-xslt20-20020816/ (http://www.w3.org/TR/2002/WD-xslt20-20020816/) http://www.w3.org/TR/2002/WD-xslt20-20020430/ (http://www.w3.org/TR/2002/WD-xslt20-20020430/) http://www.w3.org/TR/2001/WD-xslt20-20011220/ (http://www.w3.org/TR/2001/WD-xslt20-20011220/)
Editor:
Michael Kay, Software AG <Michael.Kay@softwareag.com> (mailto:Michael.Kay@softwareag.com)
This document is also available in these non-normative formats: HTML without revision markings (http://www.w3.org/TR/2003/WD-xslt20-20031112/Overview.html) and HTML with revision markings (http://www.w3.org/TR/2003/WD-xslt20-20031112/Overview-diff.html).


Copyright (http://www.w3.org/Consortium/Legal/ipr-notice#Copyright) © 2003 W3C® (MIT, ERCIM, Keio (http://www.keio.ac.jp/)), All Rights Reserved. W3C liability (http://www.w3.org/Consortium/Legal/ipr-notice#Legal_Disclaimer), trademark (http://www.w3.org/Consortium/Legal/ipr-notice#W3C_Trademarks), document use (http://www.w3.org/Consortium/Legal/copyright-documents) and software licensing (http://www.w3.org/Consortium/Legal/copyright-software) rules apply.






Abstract
摘要


本文档定义了XSLT 2.0的语法与语义。XSLT是一种文档转换语言,它用于将XML文档转换为另一种XML文档。


XSLT 2.0 is designed to be used in conjunction with XPath 2.0, which is defined in [XPath 2.0 (http://www.w3.org/TR/xslt20/#XPATH20)]. XSLT shares the same data model as XPath 2.0, which is defined in [Data Model (http://www.w3.org/TR/xslt20/#DATAMODEL)], and it uses the library of functions and operators defined in [Functions and Operators (http://www.w3.org/TR/xslt20/#FANDO)].


XSLT 2.0是用来与XPath 2.0协同工作的,XPath 2.0的定义在[XPath 2.0 (http://www.w3.org/TR/xslt20/#XPATH20)]中。XSLT与XPath 2.0具有相同的数据模型(该数据模型定义在[Data Model (http://www.w3.org/TR/xslt20/#DATAMODEL)]中)。并且,XSLT使用[Functions and Operators (http://www.w3.org/TR/xslt20/#FANDO)]中所定义的函数库和操作符。


XSLT 2.0 also includes optional facilities to serialize the results of a transformation, by means of an interface to the serialization component described in [XSLT and XQuery Serialization (http://www.w3.org/TR/xslt20/#serialization-spec)].


借助于在[XSLT and XQuery Serialization (http://www.w3.org/TR/xslt20/#serialization-spec)]中所描述的序列化组件接口,XSLT 2.0还包含了一些对文档的转换结果进行序列化的选项工具。


This document contains hyperlinks to specific sections or definitions within other documents in this family of specifications. These links are indicated visually by a superscript identifying the target specification: for example XP for XPath, DM for the Data Model, FO for Functions and Operators.


本文档中含有一些指向其它文档(这些文档与XSLT在同一规范族)中的某些章节或定义的超链接。这些链接用一个标识目标规范的上标文字来指示。例如,XP表示XPath、DM表示Data Model(数据模型)、FO表示Functions and Operators(函数与操作符)



Status of this Document

本文档状态


This section describes the status of this document at the time of its publication. Other documents may supersede this document. A list of current W3C publications and the latest revision of this technical report can be found in the W3C technical reports index (http://www.w3.org/TR/) at http://www.w3.org/TR/.
本章描述了在本文档出版时的情况。其他文档可能跟随本文档。当前W3C出版的清单和本技术报告的最新修订可以在后面的网站中找到 W3C technical reports index (http://www.w3.org/TR/) at http://www.w3.org/TR/.


This specification is a Last Call Working Draft of XSLT 2.0. This is a signal that:

  • the XSL Working Group believes that it has satisfied its relevant technical requirements;
  • the Working Group believes that it has satisfied significant dependencies with other groups;
  • other groups are invited to review the document to confirm that these dependencies have been satisfied;
  • the Working Group is planning to advance the specification to become a Candidate Recommendation.

The final date for comments on this draft is 15 February 2004. Comments should be sent to public-qt-comments@w3.org (mailto:public-qt-comments@w3.org). Because the same mailing list is also used for comments on XPath 2.0 and XQuery 1.0, it is helpful to include the string [XSLT2.0] in the subject line, together with an originator's reference number that can be used to track progress in dealing with the comment. If possible, please send each comment as a separate email. Archives (http://lists.w3.org/Archives/Public/public-qt-comments/) of the comments and responses are available.
本规范是关于XSLT 2.0 的最后工作草案。这表示本规范已经:

  • XSL 工作小组相信,本文档已经满足了相关的技术要求;
  • 工作组相信,本文档也满足了其他组的的重要依赖关系的技术要求;
  • 其他相关工作组已被邀请参加评审本文档并确认这些重大的依赖关系已经得到满足;
  • 工作组计划提升本规范为一候选的解决方案。

关于本草案建议的最后是 2004年2月15日。相关建议应该发送到public-qt-comments@w3.org (mailto:public-qt-comments@w3.org)。由于这个邮件列表同时用于XP蓰2.0 和 XQuery 1.0,所以在主题中注明[XSLT2.0]将大有 帮助,同时加上创始人相关号将能被用于跟踪处理建议的进展情况。 如果可能,请将每个建议以不同的邮件形式发送。 Archives (http://lists.w3.org/Archives/Public/public-qt-comments/)上关于建议和相关的回复现在可以 使用。


The document is published in two versions: one that highlights changes (http://www.w3.org/TR/xslt20/Overview-diff.html) since the previous published Working Draft, and one without change highlighting (http://www.w3.org/TR/xslt20/Overview.html).
本文档已出版2个版本: [http://www.w3.org/TR/xslt20/Overview-diff.html 强调了自从前一个发布 的工作草案变更的版本,和没有强调变更的版本 (http://www.w3.org/TR/xslt20/Overview.html).


As predicted in the previous (May 2003) draft, there are relatively few technical innovations in this draft, but a substantial amount of editorial revision and clarification. The technical changes of note are the ability of many XSLT instructions (for example, xsl:attribute and xsl:value-of) to use a select attribute or a contained sequence constructor (http://www.w3.org/TR/xslt20/#dt-sequence-constructor) interchangeably, and the introduction of tunnel parameters (http://www.w3.org/TR/xslt20/#dt-tunnel-parameter) which allow parameter values to be passed from a high-level template rule to a low-level rule without being declared in all the intermediate templates. Named sort keys and the sort function have been replaced with a new xsl:perform-sort instruction. There have been revisions to the date formatting functions, aligning them with the xsl:number instruction and transferring some of the functionality into xsl:number to make it more widely applicable.


A detailed summary of the changes is included at K.2.4 Changes since the May 2003 draft


一份关于变更的详细摘要包含在 K.2.4 Changes since the May 2003 draft 中。 A detailed summary of the changes is included at K.2.4 Changes since the May 2003 draft


The Working Group has commenced, but has not yet completed, a review of the classification of all error conditions described in this draft. It is likely that this review will cause the classification of some errors to change, for example some errors currently classified as recoverable may change to being non-recoverable, or vice versa. Comments on the classification, or on the general approach to handling of dynamic errors, are welcomed.


The statements in this draft concerning dependencies on other specifications that are not yet Recommendations (notably XML 1.1 and XML Namespaces 1.1) must be regarded as provisional, pending final acceptance of those specifications.


Publication as a Working Draft does not imply endorsement by the W3C Membership. This is a draft document and may be updated, replaced or obsoleted by other documents at any time. It is inappropriate to cite this document as other than work in progress.


XSLT 2.0 is a revised version of the XSLT 1.0 Recommendation [XSLT 1.0 (http://www.w3.org/TR/xslt20/#XSLT10)] published on 16 November 1999. The changes made in this document are intended to meet the requirements for XSLT 2.0 described in [XSLT 2.0 Requirements (http://www.w3.org/TR/xslt20/#XSLT20REQ)] and to incorporate fixes for errors (http://www.w3.org/1999/11/REC-xslt-19991116-errata/) that have been detected in XSLT 1.0. A summary of the changes since XSLT 1.0 is included in K Changes from XSLT 1.0.


XSLT 2.0 is designed to be used together with XPath 2.0, which has been developed by the W3C XSL Working Group in collaboration with the XML Query Working Group. The current specification of XPath 2.0 can be found in [XPath 2.0 (http://www.w3.org/TR/xslt20/#XPATH20)].


Public discussion of XSL, including XSL Transformations, takes place on the XSL-List (http://www.mulberrytech.com/xsl/xsl-list/index.html) mailing list.


The English version of this specification is the only normative version. However, for translations of this document, see http://www.w3.org/Style/XSL/translations.html (http://www.w3.org/Style/XSL/translations.html).


The development of XSLT is undertaken by the XSL Working Group which is now part of the W3C XML Activity (http://www.w3.org/XML/Activity).


Patent disclosures relevant to this specification may be found on the XSL Working Group's patent disclosure page at http://www.w3.org/Style/XSL/Disclosures.html (http://www.w3.org/Style/XSL/Disclosures.html).



Table of Contents

目录
1 Introduction (http://www.w3.org/TR/xslt20/#introduction) 介绍

    1.1 What is XSLT? (http://www.w3.org/TR/xslt20/#what-is-xslt) 什么是XSLT?
    1.2 What's new in XSLT 2.0? (http://www.w3.org/TR/xslt20/#whats-new-in-xslt2) XSLT 2.0 的新特性

2 Concepts (http://www.w3.org/TR/xslt20/#concepts) 基本概念

    2.1 Terminology (http://www.w3.org/TR/xslt20/#terminology) 术语
    2.2 Notation (http://www.w3.org/TR/xslt20/#notation) 符号
    2.3 Initiating a Transformation (http://www.w3.org/TR/xslt20/#initiating) 转换初始化
    2.4 Executing a Transformation (http://www.w3.org/TR/xslt20/#executing-a-transformation) 执行转换
    2.5 The Stylesheet Evaluation Context (http://www.w3.org/TR/xslt20/#context) 样式评估
        2.5.1 Maintaining Position: the Focus (http://www.w3.org/TR/xslt20/#focus) 位置维护:关注点
        2.5.2 Additional Context Variables (http://www.w3.org/TR/xslt20/#additional-context-variables) 附加上下文变量
    2.6 Parsing and Serialization (http://www.w3.org/TR/xslt20/#parsing-and-serialization) 解析和实例化
    2.7 Extensibility (http://www.w3.org/TR/xslt20/#extensibility) 扩展性
    2.8 Stylesheets and Schemas (http://www.w3.org/TR/xslt20/#stylesheets-and-schemas) 样式和模式
    2.9 Error Handling (http://www.w3.org/TR/xslt20/#errors) 错误处理

3 Stylesheet Structure (http://www.w3.org/TR/xslt20/#stylesheet-structure) 样式结构

    3.1 XSLT Namespace (http://www.w3.org/TR/xslt20/#xslt-namespace) XSLT 名字空间
    3.2 Reserved Namespaces (http://www.w3.org/TR/xslt20/#reserved-namespaces) 保留名字空间
    3.3 Extension Attributes (http://www.w3.org/TR/xslt20/#extension-attributes) 扩展属性
    3.4 XSLT Media Type (http://www.w3.org/TR/xslt20/#xslt-media-type) XSLT 类型
    3.5 Standard Attributes (http://www.w3.org/TR/xslt20/#standard-attributes) 标准属性
    3.6 Stylesheet Element (http://www.w3.org/TR/xslt20/#stylesheet-element) 样式元素
        3.6.1 User-defined Data Elements (http://www.w3.org/TR/xslt20/#user-defined-top-level) 用户定义数据元素
    3.7 Simplified Stylesheet Modules (http://www.w3.org/TR/xslt20/#simplified-stylesheet) 简单样式模块
    3.8 Backwards-Compatible Processing (http://www.w3.org/TR/xslt20/#backwards) 向后兼容
    3.9 Forwards-Compatible Processing (http://www.w3.org/TR/xslt20/#forwards) 前兼容性
    3.10 Combining Stylesheet Modules (http://www.w3.org/TR/xslt20/#combining-modules) 合并样式模块
        3.10.1 Locating Stylesheet Modules (http://www.w3.org/TR/xslt20/#locating-modules)查找样式模块
        3.10.2 Stylesheet Inclusion (http://www.w3.org/TR/xslt20/#include)包含样式
        3.10.3 Stylesheet Import (http://www.w3.org/TR/xslt20/#import) 样式倒入
    3.11 Embedded Stylesheet Modules (http://www.w3.org/TR/xslt20/#embedded)内嵌样式模块
    3.12 Built-in Types (http://www.w3.org/TR/xslt20/#built-in-types) 内置类型
    3.13 Importing Schema Components (http://www.w3.org/TR/xslt20/#import-schema) 倒入模式组件

4 Data Model (http://www.w3.org/TR/xslt20/#data-model) 数据模型

    4.1 XML Versions (http://www.w3.org/TR/xslt20/#xml-versions) XML 版本
    4.2 Stripping Whitespace from the Stylesheet (http://www.w3.org/TR/xslt20/#stylesheet-stripping) 去除样式中的空格
    4.3 Stripping Whitespace from a Source Tree (http://www.w3.org/TR/xslt20/#strip) 从源树中去除空格
    4.4 Attributes Types and DTD Validation (http://www.w3.org/TR/xslt20/#id-in-data-model) 属性类型昨DTD校验
    4.5 Disable Output Escaping (http://www.w3.org/TR/xslt20/#d-o-e-in-data-model) 禁止输出??

5 Syntactic Constructs (http://www.w3.org/TR/xslt20/#constructs)句法结构

    5.1 Qualified Names (http://www.w3.org/TR/xslt20/#qname) 保留字
    5.2 Unprefixed QNames in Expressions and Patterns (http://www.w3.org/TR/xslt20/#unprefixed-qnames) 表达式和类型中的无前缀的保留字
    5.3 Expressions (http://www.w3.org/TR/xslt20/#expressions) 表达式
        5.3.1 Initializing the Static Context (http://www.w3.org/TR/xslt20/#static-context)静态上下文初始化
        5.3.2 Initializing the Dynamic Context (http://www.w3.org/TR/xslt20/#evaluation-context)动态上下文初始化
    5.4 Patterns (http://www.w3.org/TR/xslt20/#patterns) 模式
    5.5 Attribute Value Templates (http://www.w3.org/TR/xslt20/#attribute-value-templates) 属性 值模版
    5.6 Sequence Constructors (http://www.w3.org/TR/xslt20/#sequence-constructors) 序列号创建
        5.6.1 Constructing Complex Content (http://www.w3.org/TR/xslt20/#constructing-complex-content) 复杂内容创建
        5.6.2 Constructing Simple Content (http://www.w3.org/TR/xslt20/#constructing-simple-content) 简单内容创建
        5.6.3 Namespace Fixup (http://www.w3.org/TR/xslt20/#namespace-fixup)名字空间修正

6 Template Rules (http://www.w3.org/TR/xslt20/#rules) 模版规则

    6.1 Defining Templates (http://www.w3.org/TR/xslt20/#defining-templates)定义模版
    6.2 Defining Template Rules (http://www.w3.org/TR/xslt20/#defining-template-rules) 定义模版规则
    6.3 Applying Template Rules (http://www.w3.org/TR/xslt20/#applying-templates)应用模版规则
    6.4 Conflict Resolution for Template Rules (http://www.w3.org/TR/xslt20/#conflict)模版规则冲突处理
    6.5 Modes (http://www.w3.org/TR/xslt20/#modes) 方法
    6.6 Built-in Template Rules (http://www.w3.org/TR/xslt20/#built-in-rule)内置模版规则
    6.7 Overriding Template Rules (http://www.w3.org/TR/xslt20/#apply-imports)重写模版规则

7 Repetition (http://www.w3.org/TR/xslt20/#for-each)复制 8 Conditional Processing (http://www.w3.org/TR/xslt20/#conditionals) 有条件执行

    8.1 Conditional Processing with xsl:if (http://www.w3.org/TR/xslt20/#xsl-if) 用xsl:if有条件执行
    8.2 Conditional Processing with xsl:choose (http://www.w3.org/TR/xslt20/#xsl-choose)用xsl:choose有条件执行

9 Variables and Parameters (http://www.w3.org/TR/xslt20/#variables-and-parameters) 变量和参数

    9.1 Variables (http://www.w3.org/TR/xslt20/#variables)变量
    9.2 Parameters (http://www.w3.org/TR/xslt20/#parameters)参数
    9.3 Values of Variables and Parameters (http://www.w3.org/TR/xslt20/#variable-values)变量和参数的值
    9.4 Temporary Trees (http://www.w3.org/TR/xslt20/#temporary-trees)临时树
    9.5 Global Variables and Parameters (http://www.w3.org/TR/xslt20/#global-variables)全局变量和参数
    9.6 Local Variables and Parameters (http://www.w3.org/TR/xslt20/#local-variables)局部变量和参数
    9.7 Scope of Variables (http://www.w3.org/TR/xslt20/#scope-of-variables) 变量作用域
    9.8 Circular Definitions (http://www.w3.org/TR/xslt20/#circularity) 循环定义

10 Callable Components (http://www.w3.org/TR/xslt20/#callable-components)可调用组件

    10.1 Named Templates (http://www.w3.org/TR/xslt20/#named-templates) 已命名模版
        10.1.1 Passing Parameters to Templates (http://www.w3.org/TR/xslt20/#with-param) 模版参数传递
        10.1.2 Tunnel Parameters (http://www.w3.org/TR/xslt20/#tunnel-params) 
    10.2 Named Attribute Sets (http://www.w3.org/TR/xslt20/#attribute-sets)
    10.3 Stylesheet Functions (http://www.w3.org/TR/xslt20/#stylesheet-functions)

11 Creating Nodes and Sequences (http://www.w3.org/TR/xslt20/#creating-new-nodes)

    11.1 Literal Result Elements (http://www.w3.org/TR/xslt20/#literal-result-element)
        11.1.1 Setting the Type Annotation for Literal Result Elements (http://www.w3.org/TR/xslt20/#setting-annotation-for-lre)
        11.1.2 Attribute Nodes for Literal Result Elements (http://www.w3.org/TR/xslt20/#attributes-for-lres)
        11.1.3 Namespace Nodes for Literal Result Elements (http://www.w3.org/TR/xslt20/#lre-namespaces)
        11.1.4 Namespace Aliasing (http://www.w3.org/TR/xslt20/#namespace-aliasing)
    11.2 Creating Element Nodes using xsl:element (http://www.w3.org/TR/xslt20/#xsl-element)
        11.2.1 Setting the Type Annotation for a Constructed Element Node (http://www.w3.org/TR/xslt20/#annotation-for-constructed-element)
    11.3 Creating Attribute Nodes using xsl:attribute (http://www.w3.org/TR/xslt20/#creating-attributes)
        11.3.1 Setting the Type Annotation for a Constructed Attribute Node (http://www.w3.org/TR/xslt20/#annotation-for-constructed-attribute)
    11.4 Creating Text Nodes (http://www.w3.org/TR/xslt20/#creating-text-nodes)
        11.4.1 Literal Text Nodes (http://www.w3.org/TR/xslt20/#literal-text-nodes)
        11.4.2 Creating Text Nodes using xsl:text (http://www.w3.org/TR/xslt20/#xsl-text)
        11.4.3 Generating Text with xsl:value-of (http://www.w3.org/TR/xslt20/#value-of)
    11.5 Creating Processing Instructions (http://www.w3.org/TR/xslt20/#creating-processing-instructions)
    11.6 Creating Namespace Nodes (http://www.w3.org/TR/xslt20/#creating-namespace-nodes)
    11.7 Creating Comments (http://www.w3.org/TR/xslt20/#creating-comments)
    11.8 Copying Nodes from a Source Tree to a Result Tree (http://www.w3.org/TR/xslt20/#copying)
        11.8.1 Shallow Copy (http://www.w3.org/TR/xslt20/#shallow-copy)
        11.8.2 Deep Copy (http://www.w3.org/TR/xslt20/#copy-of)
    11.9 Constructing Sequences (http://www.w3.org/TR/xslt20/#constructing-sequences)

12 Numbering (http://www.w3.org/TR/xslt20/#number)

    12.1 Formatting a Supplied Number (http://www.w3.org/TR/xslt20/#formatting-supplied-number)
    12.2 Numbering based on Position in a Document (http://www.w3.org/TR/xslt20/#numbering-based-on-position)
    12.3 Number to String Conversion Attributes (http://www.w3.org/TR/xslt20/#convert)

13 Sorting (http://www.w3.org/TR/xslt20/#sorting)

    13.1 The xsl:sort Element (http://www.w3.org/TR/xslt20/#xsl-sort)
        13.1.1 The Sorting Process (http://www.w3.org/TR/xslt20/#d0e16967)
        13.1.2 Comparing Sort Key Values (http://www.w3.org/TR/xslt20/#comparing-sort-keys)
        13.1.3 Sorting using Collations (http://www.w3.org/TR/xslt20/#collating-sequences)
    13.2 Creating a Sorted Sequence (http://www.w3.org/TR/xslt20/#creating-sorted-sequence)
    13.3 Processing a Sequence in Sorted Order (http://www.w3.org/TR/xslt20/#sorted-iteration)

14 Grouping (http://www.w3.org/TR/xslt20/#grouping)

    14.1 The Current Group (http://www.w3.org/TR/xslt20/#current-group)
    14.2 The Current Grouping Key (http://www.w3.org/TR/xslt20/#current-grouping-key)
    14.3 The xsl:for-each-group Element (http://www.w3.org/TR/xslt20/#xsl-for-each-group)
    14.4 Examples of Grouping (http://www.w3.org/TR/xslt20/#grouping-examples)

15 Regular Expressions (http://www.w3.org/TR/xslt20/#regular-expressions)

    15.1 The xsl:analyze-string instruction (http://www.w3.org/TR/xslt20/#analyze-string)
    15.2 Captured Substrings (http://www.w3.org/TR/xslt20/#regex-group)
    15.3 Examples of Regular Expression Matching (http://www.w3.org/TR/xslt20/#regex-examples)

16 Additional Functions (http://www.w3.org/TR/xslt20/#add-func)

    16.1 Multiple Source Documents (http://www.w3.org/TR/xslt20/#document)
    16.2 Reading Text Files (http://www.w3.org/TR/xslt20/#unparsed-text)
    16.3 Keys (http://www.w3.org/TR/xslt20/#key)
        16.3.1 The xsl:key Declaration (http://www.w3.org/TR/xslt20/#xsl-key)
        16.3.2 The key Function (http://www.w3.org/TR/xslt20/#keys)
    16.4 Number Formatting (http://www.w3.org/TR/xslt20/#format-number)
        16.4.1 Defining a Decimal Format (http://www.w3.org/TR/xslt20/#defining-decimal-format)
        16.4.2 Processing the Picture String (http://www.w3.org/TR/xslt20/#processing-picture-string)
        16.4.3 Analysing the Picture String (http://www.w3.org/TR/xslt20/#analysing-picture-string)
        16.4.4 Formatting the Number (http://www.w3.org/TR/xslt20/#formatting-the-number)
    16.5 Formatting Dates and Times (http://www.w3.org/TR/xslt20/#format-date)
        16.5.1 The Picture String (http://www.w3.org/TR/xslt20/#date-picture-string)
        16.5.2 The language, calendar, and country arguments (http://www.w3.org/TR/xslt20/#lang-cal-country)
        16.5.3 Examples of date and time formatting (http://www.w3.org/TR/xslt20/#date-time-examples)
    16.6 Miscellaneous Additional Functions (http://www.w3.org/TR/xslt20/#misc-func)
        16.6.1 current (http://www.w3.org/TR/xslt20/#current-function)
        16.6.2 unparsed-entity-uri (http://www.w3.org/TR/xslt20/#unparsed-entity-uri)
        16.6.3 unparsed-entity-public-id (http://www.w3.org/TR/xslt20/#unparsed-entity-public-id)
        16.6.4 generate-id (http://www.w3.org/TR/xslt20/#generate-id)
        16.6.5 system-property (http://www.w3.org/TR/xslt20/#system-property)

17 Messages (http://www.w3.org/TR/xslt20/#message) 18 Extensibility and Fallback (http://www.w3.org/TR/xslt20/#extension)

    18.1 Extension Functions (http://www.w3.org/TR/xslt20/#extension-functions)
        18.1.1 Testing Availability of Functions (http://www.w3.org/TR/xslt20/#testing-function-availability)
        18.1.2 Calling Extension Functions (http://www.w3.org/TR/xslt20/#calling-exension-functions)
        18.1.3 External Objects (http://www.w3.org/TR/xslt20/#external-objects)
    18.2 Extension Instructions (http://www.w3.org/TR/xslt20/#extension-instruction)
        18.2.1 Designating an Extension Namespace (http://www.w3.org/TR/xslt20/#designating-extension-namespace)
        18.2.2 Testing Availability of Instructions (http://www.w3.org/TR/xslt20/#testing-instruction-available)
        18.2.3 Fallback (http://www.w3.org/TR/xslt20/#fallback)

19 Result Trees (http://www.w3.org/TR/xslt20/#result-trees)

    19.1 Creating Result Trees (http://www.w3.org/TR/xslt20/#creating-result-trees)
    19.2 Validation (http://www.w3.org/TR/xslt20/#validation)
        19.2.1 Validating Constructed Elements and Attributes (http://www.w3.org/TR/xslt20/#validating-constructed-nodes)
        19.2.2 Validating Document Nodes (http://www.w3.org/TR/xslt20/#validating-document-nodes)

20 Serialization (http://www.w3.org/TR/xslt20/#serialization)

    20.1 Character Maps (http://www.w3.org/TR/xslt20/#character-maps)
    20.2 Disabling Output Escaping (http://www.w3.org/TR/xslt20/#disable-output-escaping)

21 Conformance (http://www.w3.org/TR/xslt20/#conformance)

    21.1 Basic XSLT Processor (http://www.w3.org/TR/xslt20/#basic-conformance)
    21.2 Schema-Aware XSLT Processor (http://www.w3.org/TR/xslt20/#schema-aware-conformance)
    21.3 Serialization Feature (http://www.w3.org/TR/xslt20/#serialization-feature)
    21.4 Backwards Compatibility Feature (http://www.w3.org/TR/xslt20/#backwards-compatibility-feature)


Appendices


A References (http://www.w3.org/TR/xslt20/#references)

    A.1 Normative References (http://www.w3.org/TR/xslt20/#normative-references)
    A.2 Other References (http://www.w3.org/TR/xslt20/#other-references)

B The XSLT Media Type (http://www.w3.org/TR/xslt20/#xslt-mime-definition)

    B.1 Registration of MIME media type application/xslt+xml (http://www.w3.org/TR/xslt20/#media-type-registration)
    B.2 Fragment Identifiers (http://www.w3.org/TR/xslt20/#media-type-fragid)

C Glossary (http://www.w3.org/TR/xslt20/#glossary) (Non-Normative) D Element Syntax Summary (http://www.w3.org/TR/xslt20/#element-syntax-summary) (Non-Normative) E Summary of Error Conditions (http://www.w3.org/TR/xslt20/#error-summary) (Non-Normative) F Checklist of Implementation-Defined Features (http://www.w3.org/TR/xslt20/#implementation-defined-features) (Non-Normative) G Schema for XSLT Stylesheets (http://www.w3.org/TR/xslt20/#schema-for-xslt) (Non-Normative) H Acknowledgements (http://www.w3.org/TR/xslt20/#d0e27004) (Non-Normative) I Checklist of Requirements (http://www.w3.org/TR/xslt20/#d0e27131) (Non-Normative) J Summary of Issues (http://www.w3.org/TR/xslt20/#issues-list) (Non-Normative)

    J.1 Open Issues (http://www.w3.org/TR/xslt20/#open-issues)
    J.2 Decided Issues (http://www.w3.org/TR/xslt20/#decided-issues)
    J.3 Closed Issues (http://www.w3.org/TR/xslt20/#closed-issues)

K Changes from XSLT 1.0 (http://www.w3.org/TR/xslt20/#changes) (Non-Normative)

    K.1 Incompatible Changes (http://www.w3.org/TR/xslt20/#incompatibilities)
        K.1.1 Backwards Compatibility Behavior (http://www.w3.org/TR/xslt20/#backwards-compatibility-behavior)
        K.1.2 Incompatibility in the Absence of a Schema (http://www.w3.org/TR/xslt20/#incompatility-without-schema)
        K.1.3 Compatibility in the Presence of a Schema (http://www.w3.org/TR/xslt20/#compatibility-with-schema)
        K.1.4 XPath 2.0 Backwards Compatibility (http://www.w3.org/TR/xslt20/#xpath-compatibility)
    K.2 New Functionality (http://www.w3.org/TR/xslt20/#changes-since-1.0)
        K.2.1 Pervasive changes (http://www.w3.org/TR/xslt20/#pervasive-changes)
        K.2.2 Major Features (http://www.w3.org/TR/xslt20/#major-features)
        K.2.3 Minor Changes (http://www.w3.org/TR/xslt20/#minor-changes)
        K.2.4 Changes since the May 2003 draft (http://www.w3.org/TR/xslt20/#changes-in-this-draft)






1 Introduction



1.1 What is XSLT?


This specification defines the syntax and semantics of the XSLT 2.0 language.


[Definition: A transformation in the XSLT language is expressed in the form of a stylesheet, whose syntax is well-formed XML [XML 1.0 (http://www.w3.org/TR/xslt20/#XML)] conforming to the Namespaces in XML Recommendation [XML Namespaces 1.0 (http://www.w3.org/TR/xslt20/#XMLNAMES)].]


A stylesheet generally includes elements that are defined by XSLT as well as elements that are not defined by XSLT. XSLT-defined elements are distinguished by use of the namespace http://www.w3.org/1999/XSL/Transform (see 3.1 XSLT Namespace), which is referred to in this specification as the XSLT namespace (http://www.w3.org/TR/xslt20/#dt-xslt-namespace). Thus this specification is a definition of the syntax and semantics of the XSLT namespace.


The term stylesheet (http://www.w3.org/TR/xslt20/#dt-stylesheet) reflects the fact that one of the important roles of XSLT is to add styling information to an XML source document, by transforming it into a document consisting of XSL formatting objects (see [XSL (http://www.w3.org/TR/xslt20/#XSLFO)]), or into another presentation-oriented format such as HTML, XHTML, or SVG. However, XSLT is used for a wide range of XML-to-XML transformation tasks, not exclusively for formatting and presentation applications.


A transformation expressed in XSLT describes rules for transforming one or more source trees into one or more result trees. The structure of these trees is described in [Data Model (http://www.w3.org/TR/xslt20/#DATAMODEL)]. The transformation is achieved by a set of template rules (http://www.w3.org/TR/xslt20/#dt-template-rule). A template rule associates a pattern (http://www.w3.org/TR/xslt20/#dt-pattern), which matches nodes in the source document, with a sequence constructor (http://www.w3.org/TR/xslt20/#dt-sequence-constructor), which can be evaluated to produce part of a result tree. The structure of the result trees can be completely different from the structure of the source trees. In constructing a result tree, nodes from the source trees can be filtered and reordered, and arbitrary structure can be added. This mechanism allows a stylesheet (http://www.w3.org/TR/xslt20/#dt-stylesheet) to be applicable to a wide class of documents that have similar source tree structures.


[Definition: A stylesheet (http://www.w3.org/TR/xslt20/#dt-stylesheet) may consist of several stylesheet modules (http://www.w3.org/TR/xslt20/#dt-stylesheet-module), contained in different XML documents. For a given transformation, one of these functions as the principal stylesheet module. The complete stylesheet (http://www.w3.org/TR/xslt20/#dt-stylesheet) is assembled by finding the stylesheet modules (http://www.w3.org/TR/xslt20/#dt-stylesheet-module) referenced directly or indirectly from the principal stylesheet module using xsl:include and xsl:import elements: see 3.10.2 Stylesheet Inclusion and 3.10.3 Stylesheet Import.]



1.2 What's new in XSLT 2.0?


XSLT 1.0是1999年11月发布的,2.0在语言性能上有了重要的提高。变化的详细列表可以在在J Changes from XSLT 1.0找到。XSLT2.0是与XPath2.0(see [XPath 2.0])并行发展的,因此,XPath的变化和XSLT的变化必须同时考虑。



2 Concepts



2.1 Terminology


For a full glossary of terms, see C Glossary.


[Definition: The software responsible for transforming source trees into result trees is referred to as the processor. This is sometimes expanded to XSLT processor to avoid any confusion with other processors, for example an XML processor.]


[Definition: A specific product that performs the functions of an XSLT processor (http://www.w3.org/TR/xslt20/#dt-processor) is referred to as an implementation ].



Note:


The precise meanings of the terms source tree and result tree, as used in this specification, depend on the context. In the context of the stylesheet (http://www.w3.org/TR/xslt20/#dt-stylesheet) as a whole, the source trees are the trees provided as the initial input to the transformation, together with any trees supplied as stylesheet parameters and any trees accessed using the document, doc FO or collection FO functions; while the result trees are the trees created by an explicit xsl:result-document instruction as well as the implicit result tree created in the absence of an xsl:result-document instruction. In the context of an individual instruction in the stylesheet (http://www.w3.org/TR/xslt20/#dt-stylesheet), the term source tree also includes any temporary tree (http://www.w3.org/TR/xslt20/#dt-temporary-tree) that the instruction is using for input, and the term result tree includes any temporary tree (http://www.w3.org/TR/xslt20/#dt-temporary-tree) that the instruction is using for output.


In this specification the words must, must not, should, should not, may, required, and recommended are to be interpreted as described in [RFC2119 (http://www.w3.org/TR/xslt20/#RFC2119)]. Where the word must relates to the behavior of the XSLT processor (http://www.w3.org/TR/xslt20/#dt-processor), then an implementation is not conformant unless it behaves as specified, subject to the more detailed rules in 21 Conformance. Where the word must relates to a stylesheet (http://www.w3.org/TR/xslt20/#dt-stylesheet), then the processor must enforce this constraint on stylesheets.


[Definition: In this specification, the term implementation-defined refers to a feature where the implementation is allowed some flexibility, and where the choices made by the implementation should be described in the vendor's documentation.]


[Definition: The term implementation-dependent refers to a feature where the behavior may vary from one implementation to another, and where the vendor is not expected to provide a full specification of the behavior.] (This might apply, for example, to limits on the size of source documents that can be transformed.)


In all cases where this specification leaves the behavior implementation-defined or implementation-dependent, the implementation has the option of providing mechanisms that allow the user to influence the behavior.


A paragraph labeled as a Note or described as an example is non-normative.


Many terms used in this document are defined in the XPath specification [XPath 2.0 (http://www.w3.org/TR/xslt20/#XPATH20)] or the Data Model specification [Data Model (http://www.w3.org/TR/xslt20/#DATAMODEL)]. Particular attention is drawn to the following:



[Definition: The term atomization is defined in Section 2.3.2 Atomization (http://www.w3.org/TR/xpath20/#id-atomization)XP. It is a process that takes as input a sequence of nodes and atomic values, and returns a sequence of atomic values, in which the nodes are replaced by their typed values as defined in [Data Model (http://www.w3.org/TR/xslt20/#DATAMODEL)].] For some nodes (for example, elements with element-only content), atomization generates a dynamic error (http://www.w3.org/TR/xslt20/#dt-dynamic-error).


[Definition: The term typed value is defined in Section 5.6 typed-value Accessor (http://www.w3.org/TR/xpath-datamodel/#dm-typed-value)DM. Every node except an element defined in the schema with element-only content has a typed value (http://www.w3.org/TR/xslt20/#dt-string-value). For example, the typed value (http://www.w3.org/TR/xslt20/#dt-typed-value) of an attribute of type xs:IDREFS is a sequence of zero or more xs:IDREF values.]


[Definition: The term string value is defined in Section 5.5 string-value Accessor (http://www.w3.org/TR/xpath-datamodel/#dm-string-value)DM. Every node has a string value (http://www.w3.org/TR/xslt20/#dt-string-value). For example, the string value (http://www.w3.org/TR/xslt20/#dt-string-value) of an element is the concatenation of the string values (http://www.w3.org/TR/xslt20/#dt-string-value) of all its descendant text nodes.]


[Definition: The term XPath 1.0 compatibility mode is defined in Section 2.1.1 Static Context (http://www.w3.org/TR/xpath20/#static_context)XP. This is a setting in the static context of an XPath expression; it has two values, true and false. When the value is set to true, the semantics of function calls and certain other operations are adjusted to give a greater degree of backwards compatibility between XPath 2.0 and XPath 1.0.]



2.2 Notation


In this document the specification of each XSLT-defined element type is preceded by a summary of its syntax in the form of a model for elements of that element type. A full list of all these specifications can be found in D Element Syntax Summary. The meaning of syntax summary notation is as follows:



An attribute that is required is shown with its name in bold. An attribute that may be omitted is shown with a question mark following its name.


The string that occurs in the place of an attribute value specifies the allowed values of the attribute. If this is surrounded by curly brackets ({...}), then the attribute value is treated as an attribute value template (http://www.w3.org/TR/xslt20/#dt-attribute-value-template), and the string occurring within curly brackets specifies the allowed values of the result of evaluating the attribute value template. Alternative allowed values are separated by |. A quoted string indicates a value equal to that specific string. An unquoted, italicized name specifies a particular type of value.


In all cases where this specification states that the value of an attribute must be one of a limited set of values, leading and trailing whitespace in the attribute value is ignored. In the case of an attribute value template (http://www.w3.org/TR/xslt20/#dt-attribute-value-template), this applies to the effective value (http://www.w3.org/TR/xslt20/#dt-effective-value) obtained when the attribute value template is expanded.


Unless the element is required to be empty, the model element contains a comment specifying the allowed content. The allowed content is specified in a similar way to an element type declaration in XML; sequence constructor means that any mixture of text nodes, literal result elements (http://www.w3.org/TR/xslt20/#dt-literal-result-element), extension instructions (http://www.w3.org/TR/xslt20/#dt-extension-instruction), and XSLT elements from the instruction (http://www.w3.org/TR/xslt20/#dt-instruction) category is allowed; other-declarations means that any mixture of XSLT elements from the declaration (http://www.w3.org/TR/xslt20/#dt-declaration) category, other than xsl:import, is allowed, together with user-defined data elements (http://www.w3.org/TR/xslt20/#dt-data-element).


The element is prefaced by comments indicating if it belongs to the instruction category or declaration category or both. The category of an element only affects whether it is allowed in the content of elements that allow a sequence constructor (http://www.w3.org/TR/xslt20/#dt-sequence-constructor) or other-declarations.



Example: Syntax Notation
This example illustrates the notation used to describe XSLT elements.


<xsl:example-element

  select = expression
  debug? = { "yes" | "no" }>

</xsl:example-element>


This example defines a (non-existent) element xsl:example-element. The element is classified as an instruction. It takes a mandatory select attribute, whose value is an XPath expression (http://www.w3.org/TR/xslt20/#dt-expression), and an optional debug attribute, whose value must be either yes or no; the curly brackets indicate that the value can be defined as an attribute value template (http://www.w3.org/TR/xslt20/#dt-attribute-value-template), allowing a value such as debug="{$debug}", where the variable (http://www.w3.org/TR/xslt20/#dt-variable) debug is evaluated to yield "yes" or "no" at run-time.


The content of an xsl:example-element instruction is defined to be a sequence of zero or more xsl:variable and xsl:param elements, followed by an xsl:sequence element.


[ERR XT0010] A static error (http://www.w3.org/TR/xslt20/#dt-static-error) is signaled if an XSLT-defined element is used in a context where it is not permitted, if a required attribute is omitted, or if the content of the element does not correspond to the content that is allowed for the element.


Attributes are validated as follows. These rules apply to the value of the attribute after removing leading and trailing whitespace.



[ERR XT0020] It is a static error (http://www.w3.org/TR/xslt20/#dt-static-error) if an attribute (other than an attribute written using curly brackets in a position where an attribute value template (http://www.w3.org/TR/xslt20/#dt-attribute-value-template) is permitted) contains a value that is not one of the permitted values for that attribute.


[ERR XT0030] It is a non-recoverable dynamic error (http://www.w3.org/TR/xslt20/#dt-nonrec-dynamic-error) if the effective value (http://www.w3.org/TR/xslt20/#dt-effective-value) of an attribute written using curly brackets, in a position where an attribute value template (http://www.w3.org/TR/xslt20/#dt-attribute-value-template) is permitted, is a value that is not one of the permitted values for that attribute.


Special rules apply if the construct appears in part of the stylesheet (http://www.w3.org/TR/xslt20/#dt-stylesheet) that is processed with forwards-compatible behavior (http://www.w3.org/TR/xslt20/#dt-forwards-compatible-behavior): see 3.9 Forwards-Compatible Processing.



Note:


This working draft includes a non-normative XML Schema for XSLT stylesheet modules (http://www.w3.org/TR/xslt20/#dt-stylesheet-module) (see G Schema for XSLT Stylesheets). The syntax summaries described in this section are normative.


XSLT defines a set of standard functions which are additional to those defined in [Functions and Operators (http://www.w3.org/TR/xslt20/#FANDO)]. The signatures of these functions are described using the same notation as used in [Functions and Operators (http://www.w3.org/TR/xslt20/#FANDO)]. The names of these functions are all in the standard function namespace (http://www.w3.org/TR/xslt20/#dt-standard-function-namespace).



2.3 Initiating a Transformation


This document does not specify any application programming interfaces or other interfaces for initiating a transformation. This section, however, describes the information that must be supplied when a transformation is initiated.


Implementations may allow a transformation to run as two or more phases, for example parsing, compilation and execution. Such a distinction is outside the scope of this specification, which treats transformation as a single process controlled using a set of stylesheet modules (http://www.w3.org/TR/xslt20/#dt-stylesheet-module), supplied in the form of XML documents.


The following information is supplied to execute a transformation:



The stylesheet module (http://www.w3.org/TR/xslt20/#dt-stylesheet-module) that is to act as the principal stylesheet module (http://www.w3.org/TR/xslt20/#dt-principal-stylesheet-module) for the transformation. The complete stylesheet (http://www.w3.org/TR/xslt20/#dt-stylesheet) is assembled by recursively expanding the xsl:import and xsl:include declarations in the principal stylesheet module, as described in 3.10.2 Stylesheet Inclusion and 3.10.3 Stylesheet Import.


A set (possibly empty) of values for stylesheet parameters (http://www.w3.org/TR/xslt20/#dt-stylesheet-parameter) (see 9.5 Global Variables and Parameters). These values are available for use within expressions (http://www.w3.org/TR/xslt20/#dt-expression) in the stylesheet (http://www.w3.org/TR/xslt20/#dt-stylesheet).


[Definition: A node that acts as the initial context node for the transformation. This node is accessible within the stylesheet (http://www.w3.org/TR/xslt20/#dt-stylesheet) as the initial value of the XPath expressions (http://www.w3.org/TR/xslt20/#dt-expression) . (dot) and self::node(), as described in 2.5.1 Maintaining Position: the Focus].


If no initial context node is supplied, then the context item (http://www.w3.org/TR/xslt20/#dt-context-item), context position (http://www.w3.org/TR/xslt20/#dt-context-position), and context size (http://www.w3.org/TR/xslt20/#dt-context-size) will initially be unset, and the evaluation of any expression that references these values will result in a dynamic error. (Note that the initial context size and context position will always be 1 (one) when an initial context node is supplied, and will be undefined if no initial context node is supplied).


Optionally, the name of a named template (http://www.w3.org/TR/xslt20/#dt-named-template) which is to be executed as the entry point to the transformation. This template must exist within the stylesheet (http://www.w3.org/TR/xslt20/#dt-stylesheet). If no named template is supplied, then the transformation starts with the template rule (http://www.w3.org/TR/xslt20/#dt-template-rule) that best matches the initial context node (http://www.w3.org/TR/xslt20/#dt-initial-context-node), according to the rules defined in 6.4 Conflict Resolution for Template Rules. Either a named template, or an initial context node, or both, must be supplied.


Optionally, an initial mode (http://www.w3.org/TR/xslt20/#dt-mode). If an initial mode is supplied, then in searching for the template rule (http://www.w3.org/TR/xslt20/#dt-template-rule) that best matches the initial context node (http://www.w3.org/TR/xslt20/#dt-initial-context-node), the processor considers only those rules that apply to the initial mode. If no initial mode is supplied, the default mode is used.


[Definition: A base output URI, that is, a URI to be used as the base URI when resolving a relative URI allocated to a result tree. If the transformation generates multiple result trees, then typically each one will be allocated a URI relative to this base URI.]


[ERR XT0040] It is a non-recoverable dynamic error (http://www.w3.org/TR/xslt20/#dt-nonrec-dynamic-error) if the invocation of the stylesheet (http://www.w3.org/TR/xslt20/#dt-stylesheet) specifies a template name that does not match the expanded-QName (http://www.w3.org/TR/xslt20/#dt-expanded-qname) of a named template defined in the stylesheet (http://www.w3.org/TR/xslt20/#dt-stylesheet).


[ERR XT0050] It is a non-recoverable dynamic error (http://www.w3.org/TR/xslt20/#dt-nonrec-dynamic-error) if the stylesheet that is invoked declares a visible stylesheet parameter (http://www.w3.org/TR/xslt20/#dt-stylesheet-parameter) with required="yes" and no value for this parameter is supplied during the invocation of the stylesheet. A stylesheet parameter is visible if it is not masked by another global variable or parameter with the same name and higher import precedence (http://www.w3.org/TR/xslt20/#dt-import-precedence).


[Definition: The transformation is performed by evaluating an initial template; if a named template (http://www.w3.org/TR/xslt20/#dt-named-template) is supplied when the transformation is initiated, then this is the initial template; otherwise, the initial template is the template rule (http://www.w3.org/TR/xslt20/#dt-template-rule) selected according to the rules of the xsl:apply-templates instruction for processing the initial context node (http://www.w3.org/TR/xslt20/#dt-initial-context-node) in the initial mode (http://www.w3.org/TR/xslt20/#dt-mode).]


Parameters passed to the transformation by the client application are matched against