目次へ飛ぶ   原文表示:
W3C Home

XSL 変換 (XSLT) 1.0

W3C 勧告 1999年 11 月 16 日付

この版:
http://www.w3.org/TR/1999/REC-xslt-19991116 XML 版 HTML 版
最新版:
http://www.w3.org/TR/xslt
以前の版
編集:
James Clark <jjc@jclark.com>
Copyright © 1999 W3C ® ( MIT, INRIA, Keio ), All Rights Reserved. W3C liability, trademark, document use and software licensing rules apply.

要約

この仕様は XSLT の構文と意味内容を定義する。 XSLT とは、 XML 文書を別の XML 文書に変換するための言語である。 This specification defines the syntax and semantics of XSLT, which is a language for transforming XML documents into other XML documents.

XSLT は、 XML 用のスタイルシート言語 XSL の一部として利用するために設計されている。 XSL には XSLT の他に、フォーマットを指定するための XML 語彙も含まれる。 XSLT は XML 文書に対し、フォーマット語彙を利用する別の XML 文書へどのように変換するかを記述する。 XSL はこの XSLT の機能を利用して XML 文書のスタイル付けを指定する。 XSLT is designed for use as part of XSL, which is a stylesheet language for XML. In addition to XSLT, XSL includes an XML vocabulary for specifying formatting. XSL specifies the styling of an XML document by using XSLT to describe how the document is transformed into another XML document that uses the formatting vocabulary.

XSLT は XSL から独立に利用できるようにも設計されている。 しかしながら、 XSLT は 完全に汎用的な XML 変換用言語としての利用が意図されたものではない。 むしろ設計の主眼は XSL の一部として XSLT を利用する際に必要となる変換処理を行う所に置かれている。 XSLT is also designed to be used independently of XSL. However, XSLT is not intended as a completely general-purpose XML transformation language. Rather it is designed primarily for the kinds of transformations that are needed when XSLT is used as part of XSL.

この文書の位置付け

この文書は、 W3C メンバおよび他の関係団体から審査された上で、 W3C 勧告 として担当の責任者が承認したものである。 今後変更される可能性はなく、他の文書において参照文献として利用したり、他の文書から正式な参照文献として引用することができる。 勧告の策定にあたって W3C が担う役割は、この仕様を広く普及させることにある。 これによりウェブの機能性と相互運用性を向上させられるようになる。 This document has been reviewed by W3C Members and other interested parties and has been endorsed by the Director as a W3C Recommendation. It is a stable document and may be used as reference material or cited as a normative reference from other documents. W3C's role in making the Recommendation is to draw attention to the specification and to promote its widespread deployment. This enhances the functionality and interoperability of the Web.

この仕様に関する正誤表は http://www.w3.org/1999/11/REC-xslt-19991116-errata から参照できる。 【当訳にはこのページ更新日までの修正が取り込まれています】 The list of known errors in this specification is available at http://www.w3.org/1999/11/REC-xslt-19991116-errata.

この仕様に関するコメントの宛先は xsl-editors@w3.org である。 なお、コメントの archives も利用できる。 XSL Transformations を含む XSL に関する公開討論は、 XSL-List メーリングリストで行われている。 Comments on this specification may be sent to xsl-editors@w3.org; archives of the comments are available. Public discussion of XSL, including XSL Transformations, takes place on the XSL-List mailing list.

英語版のみがこの仕様の正式なバージョンになる。 翻訳版を http://www.w3.org/Style/XSL/translations.html から参照できる。 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.

W3C 勧告の一覧、およびその他の技術文書は http://www.w3.org/TR. から入手できる。 A list of current W3C Recommendations and other technical documents can be found at http://www.w3.org/TR.

この仕様は W3C Style activity の一環として作成されたものである。 This specification has been produced as part of the W3C Style activity.


1 概要

この仕様は XSLT 言語の構文と意味内容を定義する。 XSLT 言語による変換は XML 名前空間勧告 [XML Names] または [XML Names 1.1] に適合する整形式の XML 文書 [XML] または [XML 1.1] として表記される。 その内容は XSLT で定義される要素と XSLT で定義されない要素のいずれも含み得る。 便宜上、通常は XML 1.0 と XML Names 1.0 への参照が用いられる。 従って、 IRI もサポートされているが, URI 参照の方が用いられる。 一部の場合では XML 1.0 と XML 1.1 の定義は完全に一致し得る。 XSLT で定義される要素は、特定の XML 名前空間への所属により他から区別される( [ 2.1 XSLT 名前空間 ] を見よ)。 この仕様では、この特定の XML 名前空間を XSLT 名前空間と呼ぶ。 すなわち、この仕様は XSLT 名前空間の構文と意味内容を定義するものである。 This specification defines the syntax and semantics of the XSLT language. A transformation in the XSLT language is expressed as a well-formed XML document [XML] or [XML 1.1] conforming to the Namespaces in XML Recommendation [XML Names] or [XML Names 1.1], which may include both elements that are defined by XSLT and elements that are not defined by XSLT. For convenience, XML 1.0 and XML Names 1.0 references are usually used. Thus, URI references are also used though IRI may also be supported. In some cases, the XML 1.0 and XML 1.1 definitions may be exactly the same. XSLT-defined elements are distinguished by belonging to a specific XML namespace (see [2.1 XSLT Namespace]), which is referred to in this specification as the XSLT namespace. Thus this specification is a definition of the syntax and semantics of the XSLT namespace.

XSLT が表現する変換は、ソースツリーから結果ツリーへの変換を行う処理規則で記述される。 変換はパターンとテンプレートとの関連付けにより得られる。 ソースツリー内の要素がパターンと照合され、パターンに関連付けられたテンプレートがインスタンス化されて結果ツリーの部品を生成する。 結果ツリーはソースツリーから独立であり、その構造はソースツリーの構造からまったく別物にもなり得る。 結果ツリーの構築においては、ソースツリーの要素をふるいにかけたり, 要素の順序を変更したり, 任意の構造を追加することが可能である。 A transformation expressed in XSLT describes rules for transforming a source tree into a result tree. The transformation is achieved by associating patterns with templates. A pattern is matched against elements in the source tree. A template is instantiated to create part of the result tree. The result tree is separate from the source tree. The structure of the result tree can be completely different from the structure of the source tree. In constructing the result tree, elements from the source tree can be filtered and reordered, and arbitrary structure can be added.

XSLT が表現する変換をスタイルシートと呼ぶ。 その理由は、 XSLT が XSL のフォーマット語彙への変換に利用される局面においては、この変換がスタイルシートとして機能するからである。 A transformation expressed in XSLT is called a stylesheet. This is because, in the case when XSLT is transforming into the XSL formatting vocabulary, the transformation functions as a stylesheet.

この文書では XSLT スタイルシートを XML 文書に関連付ける方法は規定しない。 XSL プロセッサには [XML Stylesheet] で述べられる仕組みのサポートが推奨される。 その仕組みまたは他の仕組みにより、1つの XML 文書に複数の XSLT スタイルシートが(一定の順序により)同時に適用される場合、それらを順にインポートした1個のスタイルシートが適用されたときと同じ結果が得られるべきである( [2.6.2 スタイルシートのインポート] を見よ)。 This document does not specify how an XSLT stylesheet is associated with an XML document. It is recommended that XSL processors support the mechanism described in [XML Stylesheet]. When this or any other mechanism yields a sequence of more than one XSLT stylesheet to be applied simultaneously to a XML document, then the effect should be the same as applying a single stylesheet that imports each member of the sequence in order (see [2.6.2 Stylesheet Import]).

スタイルシートはテンプレートルールの集合を含む。 テンプレートルールは2つの部分からなる。 一つはソースツリーのノードと照合されるパターンであり, もう一つは結果ツリーの一部を構築するためにインスタンス化されるテンプレートである。 この構成により、1個のスタイルシートを類似するソースツリー構造を持つ多様な文書に適用できるようになる。 A stylesheet contains a set of template rules. A template rule has two parts: a pattern which is matched against nodes in the source tree and a template which can be instantiated to form part of the result tree. This allows a stylesheet to be applicable to a wide class of documents that have similar source tree structures.

テンプレートはソースの特定の要素に対してインスタンス化され、結果ツリーの一部を生成する。 テンプレートはリテラルの結果要素構造を指定する要素も含み得る。 テンプレートは結果ツリーの素片を生成するための命令を与える XSLT 名前空間の要素も含み得る。 各命令は、テンプレートのインスタンス化に際し、命令の実行により生成される結果ツリー素片に置換される。 命令はソースの子孫要素を選択して処理することも可能である。 子孫要素の処理においては、適用可能なテンプレートルールが検索され、そのテンプレートのインスタンス化により、結果ツリー素片が生成される。 ソースツリーの要素は、命令の実行により選択されなければ処理されないことに注意すべきである。 結果ツリーは、ルートノードに適用し得るテンプレートルールの検索とそのテンプレートのインスタンス化により構築される。 A template is instantiated for a particular source element to create part of the result tree. A template can contain elements that specify literal result element structure. A template can also contain elements from the XSLT namespace that are instructions for creating result tree fragments. When a template is instantiated, each instruction is executed and replaced by the result tree fragment that it creates. Instructions can select and process descendant source elements. Processing a descendant element creates a result tree fragment by finding the applicable template rule and instantiating its template. Note that elements are only processed when they have been selected by the execution of an instruction. The result tree is constructed by finding the template rule for the root node and instantiating its template.

テンプレートルールの検索に際し、対象の要素に合致するパターンを持つテンプレートルールが複数見つかる場合がある。 このような場合でも、適用されるテンプレートルールは一つだけになる。 どのテンプレートルールを適用するかの決定方法については [5.5 テンプレートルールの競合解決] にて述べる。 In the process of finding the applicable template rule, more than one template rule may have a pattern that matches a given element. However, only one template rule will be applied. The method for deciding which template rule to apply is described in [5.5 Conflict Resolution for Template Rules].

テンプレートは1個だけでも強力な処理機能を備えている。 望むだけ複雑な構造の生成, ソースツリー内の任意の場所からの文字列値の取得, ソースツリー内の要素の出現回数に応じた繰り返し構造の生成なども可能である。 結果ツリーの構造がソースツリーの構造から独立しているような単純な変換であれば、スタイルシートを完全な結果ツリーが得られるテンプレートとして機能する1個のテンプレートのみから構成することも大抵は可能である。 データを表現する XML 文書に対する変換の多くはこの種のものになる( [D.2 データ例] を見よ)。 XSLT では、このようなスタイルシートのための簡略構文も認められている( [2.3 スタイルシートとしてのリテラル結果要素] を見よ)。 A single template by itself has considerable power: it can create structures of arbitrary complexity; it can pull string values out of arbitrary locations in the source tree; it can generate structures that are repeated according to the occurrence of elements in the source tree. For simple transformations where the structure of the result tree is independent of the structure of the source tree, a stylesheet can often consist of only a single template, which functions as a template for the complete result tree. Transformations on XML documents that represent data are often of this kind (see [D.2 Data Example]). XSLT allows a simplified syntax for such stylesheets (see [2.3 Literal Result Element as Stylesheet]).

テンプレートのインスタンス化においては、常に 現在のノード現在のノードリスト が対象になる。 現在のノードは、常に現在のノードリストのメンバである。 XSLT の操作の多くは、現在のノードと関連する。 現在のノードリストや現在のノードを変更する命令は数種類しか存在しない( [5 テンプレートルール] および [8 繰り返し] を見よ)。 これらの命令のいずれかのインスタンス化においては、現在のノードリストは新しいノードのリストに変更され、新しいリストの各メンバが順に現在のノードになる。 命令のインスタンス化が完了すると、現在のノードと現在のノードリストの内容は 命令がインスタンス化される前の状態に戻る。 When a template is instantiated, it is always instantiated with respect to a current node and a current node list. The current node is always a member of the current node list. Many operations in XSLT are relative to the current node. Only a few instructions change the current node list or the current node (see [5 Template Rules] and [8 Repetition]); during the instantiation of one of these instructions, the current node list changes to a new list of nodes and each member of this new list becomes the current node in turn; after the instantiation of the instruction is complete, the current node and current node list revert to what they were before the instruction was instantiated.

XSLT は [XPath] で定義される式言語を利用して 処理対象要素の選択, 条件分岐処理, テキストの生成 を行う。 XSLT makes use of the expression language defined by [XPath] for selecting elements for processing, for conditional processing and for generating text.

XSLT は言語の拡張用に2つの「フック」を備えている。 一つはテンプレートで用いる命令要素の集合を拡張するフックであり、もう一つは XPath 式で用いる関数の集合を拡張するフックである。 これらのフックはいずれも XML 名前空間を基にする。 このバージョンの XSLT では、フックの実装についての仕組みは定義しない。 [14 拡張] を見よ。 XSLT provides two "hooks" for extending the language, one hook for extending the set of instruction elements used in templates and one hook for extending the set of functions used in XPath expressions. These hooks are both based on XML namespaces. This version of XSLT does not define a mechanism for implementing the hooks. See [14 Extensions].

注記: XSL 作業グループは、この仕様の将来版または別個の仕様において、この仕組みを定義することを企図している。 NOTE:The XSL WG intends to define such a mechanism in a future version of this specification or in a separate specification.

[18 表記法] にて、 XSLT で定義する要素の構文の記述に用いられる, 要素構文の要約表記法を述べる。 The element syntax summary notation used to describe the syntax of XSLT-defined elements is described in [18 Notation].

XSLT スタイルシートの MIME メディア型には text/xmlapplication/xml [RFC2376] が用いられるべきである。 将来的には XSLT スタイルシート固有のメディア型が明示的に登録され得る。 そのときは登録されたメディア型も利用できることになる。 The MIME media types text/xml and application/xml[RFC2376] should be used for XSLT stylesheets. It is possible that a media type will be registered specifically for XSLT stylesheets; if and when it is, that media type may also be used.

2 スタイルシートの構造

2.1 XSLT 名前空間

XSLT 名前空間の URI は http://www.w3.org/1999/XSL/Transform である。 The XSLT namespace has the URI http://www.w3.org/1999/XSL/Transform.

注記: URI 内の 1999 は W3C がこの URI を割り当てた年度を示している。 この数字は利用する XSLT のバージョンを指示するものではない。 バージョンは属性により指定される( [2.2 スタイルシートの要素], [2.3 スタイルシートとしてのリテラル結果要素] を見よ)。 NOTE:The 1999 in the URI indicates the year in which the URI was allocated by the W3C. It does not indicate the version of XSLT being used, which is specified by attributes (see [2.2 Stylesheet Element] and [2.3 Literal Result Element as Stylesheet]).

XSLT プロセッサは XML 名前空間の要素と属性の認識に際し, XML 名前空間の仕組み [XML Names] を利用しなければならない。 XSLT 名前空間の要素はスタイルシート内でのみ認識され、ソース文書内では認識されない。 XSLT で定義する要素の全一覧は [B 要素の構文の要約] で指定される。 ベンダは要素や属性を追加して XSLT 名前空間を拡張してはならない。 拡張を行う場所は XSLT 名前空間ではなく、別の名前空間内でなければならない。 命令用要素を追加する際に利用する名前空間は [14.1 拡張要素] で規定する拡張要素の仕組みにより識別できなければならない。 XSLT processors must use the XML namespaces mechanism [XML Names] to recognize elements and attributes from this namespace. Elements from the XSLT namespace are recognized only in the stylesheet and not in the source document. The complete list of XSLT-defined elements is specified in [B Element Syntax Summary]. Vendors must not extend the XSLT namespace with additional elements or attributes. Instead, any extension must be in a separate namespace. Any namespace that is used for additional instruction elements must be identified by means of the extension element mechanism specified in [14.1 Extension Elements].

この仕様においては XSLT 名前空間の要素を指す接頭辞に xsl: を用いることにする。 しかしながら, XSLT スタイルシートにおいては、名前空間宣言により XSLT 名前空間の URI に結びつけられているならば, どのような接頭辞が用いられてもよい。 This specification uses a prefix of xsl: for referring to elements in the XSLT namespace. However, XSLT stylesheets are free to use any prefix, provided that there is a namespace declaration that binds the prefix to the URI of the XSLT namespace.

XSLT 名前空間に属する要素は、 XSLT 名前空間に属さない任意の属性を, その 展開名 (expanded-name) の名前空間 URI が null でない限り, 持つことができる。 ただし、このような属性の存在から XSLT 要素やこの文書で定義する関数のふるまいが変更されてはならない。 従って, XSLT プロセッサはこのような属性をいつでも無視してよく、その名前空間 URI を認識できない場合は, エラーを生成せずにこれらの属性を無視しなければならない。 このような属性は、例えば 一意的な識別子, 最適化のヒント, 添付情報 などを供し得る。 An element from the XSLT namespace may have any attribute not from the XSLT namespace, provided that the expanded-name of the attribute has a non-null namespace URI. The presence of such attributes must not change the behavior of XSLT elements and functions defined in this document. Thus, an XSLT processor is always free to ignore such attributes, and must ignore such attributes without giving an error if it does not recognize the namespace URI. Such attributes can provide, for example, unique identifiers, optimization hints, or documentation.

XSLT 名前空間の要素に、この文書で要素に定義する属性以外の, 展開名の名前空間 URI が null になる属性(名前に接頭辞が無い属性)が含まれる場合、エラーとする。 It is an error for an element from the XSLT namespace to have attributes with expanded-names that have null namespace URIs (i.e. attributes with unprefixed names) other than attributes defined for the element in this document.

注記: XSLT の要素名, 属性名, 関数名 に関する表記慣行は、小文字のみ, 単語はハイフン区切り, 略語の利用は XML や HTML などの関連言語の構文内ですでに現れている場合のみ、とされている。 NOTE:The conventions used for the names of XSLT elements, attributes and functions are that names are all lower-case, use hyphens to separate words, and use abbreviations only if they already appear in the syntax of a related language such as XML or HTML.

2.2 スタイルシート要素

<xsl:stylesheet
  id = id 
  extension-element-prefixes = tokens 
  exclude-result-prefixes = tokens
         version = number>
  <!-- 内容:(xsl:import*, top-level-elements) -->
</xsl:stylesheet>
<xsl:transform
  id = id 
  extension-element-prefixes = tokens 
  exclude-result-prefixes = tokens
         version = number>
  <!-- 内容:(xsl:import*, top-level-elements) -->
</xsl:transform>

スタイルシートは XML 文書内の xsl:stylesheet 要素で表現される。 xsl:transformxsl:stylesheet の同義語として許容される。 A stylesheet is represented by an xsl:stylesheet element in an XML document. xsl:transform is allowed as a synonym for xsl:stylesheet.

xsl:stylesheet 要素には、スタイルシートが要求する XSLT のバージョンを指示する version 属性が与えられていなければならない。 このバージョンの XSLT においては、属性値は 1.0 とすべきである。 この値が 1.0 以外の場合、前方互換処理モードが有効になる ( [2.5 前方互換処理] を見よ)。 An xsl:stylesheet element must have a version attribute, indicating the version of XSLT that the stylesheet requires. For this version of XSLT, the value should be 1.0. When the value is not equal to 1.0, forwards-compatible processing mode is enabled (see [2.5 Forwards-Compatible Processing]).

xsl:stylesheet 要素は、次の型の要素を含み得る。 The xsl:stylesheet element may contain the following types of elements:

xsl:stylesheet 要素の子として現れる要素は トップレベル ( top-level )要素と呼ばれる。 An element occurring as a child of an xsl:stylesheet element is called a top-level element.

次の例にスタイルシートの構造を示す。 省略記号( ... )は、属性値あるいは内容が省略されていることを表す。 この例では、利用可能な要素型をそれぞれ1個ずつ記述しているが、スタイルシートはこれらの要素それぞれについて、0個以上, いくつでも含み得る。 This example shows the structure of a stylesheet. Ellipses (...) indicate where attribute values or content have been omitted. Although this example shows one of each type of allowed element, stylesheets may contain zero or more of each of these elements.

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

  <xsl:import href="..."/>

  <xsl:include href="..."/>

  <xsl:strip-space elements="..."/>
  
  <xsl:preserve-space elements="..."/>

  <xsl:output method="..."/>

  <xsl:key name="..." match="..." use="..."/>

  <xsl:decimal-format name="..."/>

  <xsl:namespace-alias stylesheet-prefix="..." result-prefix="..."/>

  <xsl:attribute-set name="...">...</xsl:attribute-set>

  <xsl:variable name="...">...</xsl:variable>

  <xsl:param name="...">...</xsl:param>

  <xsl:template match="...">...</xsl:template>

  <xsl:template name="...">...</xsl:template>

</xsl:stylesheet>

xsl:stylesheet 要素の子の出現順序は、xsl:import 要素とエラー回復を除いて重要ではない。 スタイルシート作成者は要素を好みに合わせて自由に並べられる。 また、スタイルシート生成ツールも要素の出現順序の制御機能を提供する必要はない。 The order in which the children of the xsl:stylesheet element occur is not significant except for xsl:import elements and for error recovery. Users are free to order the elements as they prefer, and stylesheet creation tools need not provide control over the order in which the elements occur.

加えて, xsl:stylesheet 要素には、 XSLT 名前空間に属さない任意の要素も, その展開名が非 null の名前空間 URI を持つならば, 含められる。 このようなトップレベル要素が存在しても、この文書で定義された XSLT 要素と関数のふるまいが変更されてはならない。 例えば、競合解決のために異なるルールを利用する目的でトップレベル要素に xsl:apply-templates を指定することは許されない。 従って, XSLT プロセッサは、このようなトップレベル要素をいつでも無視してよく, その名前空間 URI を認識できない場合は、エラーを生成せずにこれらのトップレベル要素を無視しなければならない。 これらの要素は 例えば以下に挙げるデータを提供し得る。 In addition, the xsl:stylesheet element may contain any element not from the XSLT namespace, provided that the expanded-name of the element has a non-null namespace URI. The presence of such top-level elements must not change the behavior of XSLT elements and functions defined in this document; for example, it would not be permitted for such a top-level element to specify that xsl:apply-templates was to use different rules to resolve conflicts. Thus, an XSLT processor is always free to ignore such top-level elements, and must ignore a top-level element without giving an error if it does not recognize the namespace URI. Such elements can provide, for example,

2.3 スタイルシートとしてのリテラル結果要素

ルートノード用のテンプレート1個だけから構成されるスタイルシートのために、簡略化された構文が用意されている。 このスタイルシートは、リテラル結果要素のみから構成されていてもよい ( [7.1.1 リテラル結果要素] を見よ)。 このようなスタイルシートは、そのリテラル結果要素を含む、照合パターンが / のテンプレートルール1個だけからなる xsl:stylesheet 要素を含むスタイルシートと等価になる。 例を示す: A simplified syntax is allowed for stylesheets that consist of only a single template for the root node. The stylesheet may consist of just a literal result element (see [7.1.1 Literal Result Elements]). Such a stylesheet is equivalent to a stylesheet with an xsl:stylesheet element containing a template rule containing the literal result element; the template rule has a match pattern of /. For example

<html xsl:version="1.0"
      xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
      xmlns="http://www.w3.org/TR/xhtml1/strict">
  <head>
    <title>Expense Report Summary</title>
  </head>
  <body>
    <p>Total Amount: <xsl:value-of select="expense-report/total"/></p>
  </body>
</html>

これは次と同じ意味になる。 has the same meaning as

<xsl:stylesheet version="1.0"
      xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
      xmlns="http://www.w3.org/TR/xhtml1/strict">
<xsl:template match="/">
<html>
  <head>
    <title>Expense Report Summary</title>
  </head>
  <body>
    <p>Total Amount: <xsl:value-of select="expense-report/total"/></p>
  </body>
</html>
</xsl:template>
</xsl:stylesheet>

スタイルシートの文書要素になるリテラル結果要素には、スタイルシートに要求される XSLT のバージョンを指示する xsl:version 属性が指定されなければならない。 このバージョンの XSLT では、属性値は 1.0 にすべきである。 この値は Number でなければならない。 他のリテラル結果要素にも xsl:version 属性を指定できる。 xsl:version 属性の値が 1.0 以外の場合、前方互換 (forwards-compatible) 処理モードが有効になる( [2.5 前方互換処理] を見よ)。 A literal result element that is the document element of a stylesheet must have an xsl:version attribute, which indicates the version of XSLT that the stylesheet requires. For this version of XSLT, the value should be 1.0; the value must be a Number. Other literal result elements may also have an xsl:version attribute. When the xsl:version attribute is not equal to 1.0, forwards-compatible processing mode is enabled (see [2.5 Forwards-Compatible Processing]).

スタイルシートとして用いるリテラル結果要素に許される内容は、リテラル結果要素をスタイルシート内で用いる場合と同様である。 従って、スタイルシートとして用いるリテラル結果要素の内容に トップレベル 要素を含めることはできない。 The allowed content of a literal result element when used as a stylesheet is no different from when it occurs within a stylesheet. Thus, a literal result element used as a stylesheet cannot contain top-level elements.

システム側が XML 文書を XSLT スタイルシートとして XSLT プロセッサに渡して処理させる必要があるかどうかを知る方法が XML 文書自体を調査するより無い状況もある。 簡略構文を用いた場合、この処理はより難しくなる。 In some situations, the only way that a system can recognize that an XML document needs to be processed by an XSLT processor as an XSLT stylesheet is by examining the XML document itself. Using the simplified syntax makes this harder.

注記: 例えば、別の XML 言語( AXL とする)が、ある XML 文書に対し AXL プロセッサに処理させる必要がある AXL 文書であることを指示するために文書要素上に axl:version を与えている可能性がある。 同じ文書に axl:version 属性と xsl:version 属性の両者が含まれている場合、その文書を XSLT プロセッサと AXL プロセッサのどちらに処理させるべきか自明でなくなる。 NOTE:For example, another XML language (AXL) might also use an axl:version on the document element to indicate that an XML document was an AXL document that required processing by an AXL processor; if a document had both an axl:version attribute and an xsl:version attribute, it would be unclear whether the document should be processed by an XSLT processor or an AXL processor.

そのため、このような状況で利用され得る XSLT スタイルシートに簡略構文を用いるべきではない。 このような状況は、例えば XSLT スタイルシートが text/xml または application/xml の MIME メディア型を伴うメッセージとして、 MIME メディア型に基づいてメッセージの処理方法を決定する受信者側へ送信される際に生じる。 Therefore, the simplified syntax should not be used for XSLT stylesheets that may be used in such a situation. This situation can, for example, arise when an XSLT stylesheet is transmitted as a message with a MIME media type of text/xml or application/xml to a recipient that will use the MIME media type to determine how the message is processed.

2.4 修飾名

内部 XSLT オブジェクトの名前:特に、名前付きテンプレート( [6 名前付きテンプレート] を見よ), モード( [5.7 モード] を見よ), 属性集合( [7.1.4 名前付き属性の集合] を見よ), キー( [12.2 キー] を見よ), 十進フォーマット( [12.3 数値のフォーマット] を見よ), 変数, パラメタ( [11 変数とパラメタ] )の名前は、 QName 【"Qualified Name" - 修飾名】 により指定される。 名前に接頭辞がある場合、接頭辞はその名前が現れた属性に対し有効な名前空間宣言を用いて URI 参照に展開される。 名前の局所部と URI 参照( null もあり得る)から構成される 展開名 ( expanded-name )が、オブジェクトの名前として用いられる。 既定の名前空間は、接頭辞のない名前に用いられない The name of an internal XSLT object, specifically a named template (see [6 Named Templates]), a mode (see [5.7 Modes]), an attribute set (see [7.1.4 Named Attribute Sets]), a key (see [12.2 Keys]), a decimal-format (see [12.3 Number Formatting]), a variable or a parameter (see [11 Variables and Parameters]) is specified as a QName. If it has a prefix, then the prefix is expanded into a URI reference using the namespace declarations in effect on the attribute in which the name occurs. The expanded-name consisting of the local part of the name and the possibly null URI reference is used as the name of the object. The default namespace is not used for unprefixed names.

2.5 前方互換処理

xsl:stylesheet 要素の version 属性の値が 1.0 以外の場合、それ自身とその属性、およびすべての子孫とその属性に対し前方互換処理モードが有効になる。 ただし、リテラル結果要素が xsl:version 属性を持ち、その値が 1.0 の場合、それ自身とその属性、およびすべての子孫とその属性に対する前方互換処理モードは無効になる。 An element enables forwards-compatible mode for itself, its attributes, its descendants and their attributes if either it is an xsl:stylesheet element whose version attribute is not equal to 1.0 , or it is a literal result element that has an xsl:version attribute whose value is not equal to 1.0, or it is a literal result element that does not have an xsl:version attribute and that is the document element of a stylesheet using the simplified syntax (see [2.3 Literal Result Element as Stylesheet]). A literal result element that has an xsl:version attribute whose value is equal to 1.0 disables forwards-compatible mode for itself, its attributes, its descendants and their attributes.

前方互換処理モードによる要素の処理においては: If an element is processed in forwards-compatible mode, then:

従って, 次のスタイルシートには, この仕様で定義していない XSLT 名前空間の要素が含まれているが、 XSLT 1.0 プロセッサは、このスタイルシートをエラーを生じさせずに処理できなければならない。 Thus, any XSLT 1.0 processor must be able to process the following stylesheet without error, although the stylesheet includes elements from the XSLT namespace that are not defined in this specification:

<xsl:stylesheet version="1.1"
                xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
  <xsl:template match="/">
    <xsl:choose>
      <xsl:when test="system-property('xsl:version') >= 1.1">
        <xsl:exciting-new-1.1-feature/>
      </xsl:when>
      <xsl:otherwise>
        <html>
        <head>
          <title>XSLT 1.1 required</title>
        </head>
        <body>
          <p>Sorry, this stylesheet requires XSLT 1.1.</p>
        </body>
        </html>
      </xsl:otherwise>
    </xsl:choose>
  </xsl:template>
</xsl:stylesheet>

注記: スタイルシートが、 1.0 より後のバージョンの XSLT に導入されたトップレベル要素に決定的に依存するような場合、そのスタイルシートに terminate="yes" を伴う xsl:message 要素を用いることにより( [13 メッセージ] を見よ), 前のバージョンの XSLT を実装する XSLT プロセッサがそのトップレベル要素を黙って無視しないようにさせられる。 例を示す: NOTE:If a stylesheet depends crucially on a top-level element introduced by a version of XSLT after 1.0, then the stylesheet can use an xsl:message element with terminate="yes" (see [13 Messages]) to ensure that XSLT processors implementing earlier versions of XSLT will not silently ignore the top-level element. For example,

<xsl:stylesheet version="1.5"
                xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

  <xsl:important-new-1.1-declaration/>

  <xsl:template match="/">
    <xsl:choose>
      <xsl:when test="system-property('xsl:version') &lt; 1.1">
        <xsl:message terminate="yes">
          <xsl:text>Sorry, this stylesheet requires XSLT 1.1.</xsl:text>
        </xsl:message>
      </xsl:when>
      <xsl:otherwise>
        ...
      </xsl:otherwise>
    </xsl:choose>
  </xsl:template>
  ...
</xsl:stylesheet>

前方互換モードで処理される属性に現れる からエラーが生じた場合、 XSLT プロセッサは次のようにエラーを回復しなければならない: If an expression occurs in an attribute that is processed in forwards-compatible mode, then an XSLT processor must recover from errors in the expression as follows:

2.6 スタイルシートの結合

XSLT には、スタイルシートを結合する2種類の仕組みがある。 XSLT provides two mechanisms to combine stylesheets:

2.6.1 スタイルシートのインクルード

<!-- 分類:top-level-element -->
<xsl:include
  href = uri-reference />

xsl:include 要素を用いることにより XSLT スタイルシートに別の XSLT スタイルシートを取り込むことができる。 xsl:include 要素はインクルードするスタイルシートへの URI 参照を値にとる href 属性を持つ。 相対 URI は xsl:include 要素の基底 URIを基準に解決される( [3.2 基底 URI] を見よ)。 An XSLT stylesheet may include another XSLT stylesheet using an xsl:include element. The xsl:include element has an href attribute whose value is a URI reference identifying the stylesheet to be included. A relative URI is resolved relative to the base URI of the xsl:include element (see [3.2 Base URI]).

xsl:include 要素は トップレベル 要素としてのみ利用できる。 The xsl:include element is only allowed as a top-level element.

このインクルード処理は XML のツリーレベルで働く。 href 属性の値から位置が特定されたリソースは、 XML 文書として構文解析され、インクルードする側の xsl:include 要素は, その XML 文書の xsl:stylesheet 要素の子たちに置換される。 テンプレートルールや定義が取り込まれても、この処理のされ方には影響しない。 The inclusion works at the XML tree level. The resource located by the href attribute value is parsed as an XML document, and the children of the xsl:stylesheet element in this document replace the xsl:include element in the including document. The fact that template rules or definitions are included does not affect the way they are processed.

インクルードされるスタイルシートに [2.3 スタイルシートとしてのリテラル結果要素] で述べた簡略構文が用いられていてもよい。 この場合、等価な xsl:stylesheet 要素として扱われる。 The included stylesheet may use the simplified syntax described in [2.3 Literal Result Element as Stylesheet]. The included stylesheet is treated the same as the equivalent xsl:stylesheet element.

スタイルシートが自身を直接的に, または間接的にインクルードしている場合、エラーとする。 It is an error if a stylesheet directly or indirectly includes itself.

注記: 同じスタイルシートが複数回インクルードされる場合、定義の重複によりエラーが生じる可能性がある。 インクルードが間接的だった場合、このような重複は見分け難くなる。 例えば、2つのスタイルシート B, C が同じスタイルシート A をインクルードしているとき、スタイルシート DB, C の両方をインクルードすると、 AD から間接的に二重にインクルードされることになる。 この場合、 B, C, D のいずれも独立にスタイルシートとして利用されている状況であれば、 A のインクルードを除くすべての B の内容を別のスタイルシート B' に分離し、 B については B'A をインクルードする形に変更し、 C についても同様に C' に分離し、 DA, B', C' をインクルードする形に変更することで、エラーを回避できる。 NOTE:Including a stylesheet multiple times can cause errors because of duplicate definitions. Such multiple inclusions are less obvious when they are indirect. For example, if stylesheet B includes stylesheet A, stylesheet C includes stylesheet A, and stylesheet D includes both stylesheet B and stylesheet C, then A will be included indirectly by D twice. If all of B, C and D are used as independent stylesheets, then the error can be avoided by separating everything in B other than the inclusion of A into a separate stylesheet B' and changing B to contain just inclusions of B' and A, similarly for C, and then changing D to include A, B', C'.

2.6.2 スタイルシートのインポート

<xsl:import
  href = uri-reference />

xsl:import 要素を用いて別の XSLT スタイルシートを XSLT スタイルシートにインポートすることができる。 スタイルシートのインポートはスタイルシートのインクルード( [2.6.1 スタイルシートのインクルード] を見よ)と似ているが、インポートする側のスタイルシートに含まれる定義とテンプレートルールが、インポートされる側のスタイルシートに含まれる定義とテンプレートルールより優先される点が異なる。 下でより詳細に述べる。 xsl:import 要素はインポートするスタイルシートへの URI 参照を値にとる href 属性を持つ。 相対 URI は xsl:import 要素の基底 URIを基準に解決される( [3.2 基底 URI] を見よ)。 An XSLT stylesheet may import another XSLT stylesheet using an xsl:import element. Importing a stylesheet is the same as including it (see [2.6.1 Stylesheet Inclusion]) except that definitions and template rules in the importing stylesheet take precedence over template rules and definitions in the imported stylesheet; this is described in more detail below. The xsl:import element has an href attribute whose value is a URI reference identifying the stylesheet to be imported. A relative URI is resolved relative to the base URI of the xsl:import element (see [3.2 Base URI]).

xsl:import 要素は トップレベル 要素としてのみ利用できる。 xsl:import 要素は、 xsl:include 要素も含め、 xsl:stylesheet 要素のすべての子よりも前に置かれなければならない。 xsl:include でスタイルシートをインクルードした場合、インクルードされる文書内の xsl:import 要素はすべて、インクルードする側の文書内に既存のすべての xsl:import 要素の後方に移動される。 The xsl:import element is only allowed as a top-level element. The xsl:import element children must precede all other element children of an xsl:stylesheet element, including any xsl:include element children. When xsl:include is used to include a stylesheet, any xsl:import elements in the included document are moved up in the including document to after any existing xsl:import elements in the including document.

例えば: For example,

<xsl:stylesheet version="1.0"
          xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
  <xsl:import href="article.xsl"/>
  <xsl:import href="bigfont.xsl"/>
  <xsl:attribute-set name="note-style">
    <xsl:attribute name="font-style">italic</xsl:attribute>
  </xsl:attribute-set>
</xsl:stylesheet>

インポート優先順位 は次の様にして決定される:まず、 xsl:import 要素を含むスタイルシートの処理に出現したすべての xsl:stylesheet 要素が、1個の インポートツリー をなすものとして扱われる。 インポートツリーにおいては、各 xsl:stylesheet 要素が、それに含まれる xsl:import 要素ごとに1個のインポートを子に持つものとする。 ここで xsl:include 要素はすべて、このインポートツリーの構築前に解決される。 インポートツリー内の xsl:stylesheet 要素 A が、インポートツリーの後順走査( postorder - すなわち、ツリーの親はその子より後に訪れられる)において、別の xsl:stylesheet 要素 B よりも先に訪れられるならば、 A は B より優先順位が低いものと定義する。 インポートにおけるそれぞれの定義とテンプレートルールの優先順位は、それらを含む xsl:stylesheet 要素の順位により決定されるものとする。 The xsl:stylesheet elements encountered during processing of a stylesheet that contains xsl:import elements are treated as forming an import tree. In the import tree, each xsl:stylesheet element has one import child for each xsl:import element that it contains. Any xsl:include elements are resolved before constructing the import tree. An xsl:stylesheet element in the import tree is defined to have lower import precedence than another xsl:stylesheet element in the import tree if it would be visited before that xsl:stylesheet element in a post-order traversal of the import tree (i.e. a traversal of the import tree in which an xsl:stylesheet element is visited after its import children). Each definition and template rule has import precedence determined by the xsl:stylesheet element that contains it.

次のような場合を想定する: For example, suppose

  • スタイルシート A がスタイルシート BC をこの順序でインポートし、 stylesheet A imports stylesheets B and C in that order;

  • スタイルシート B がスタイルシート D をインポートし、 stylesheet B imports stylesheet D;

  • スタイルシート C がスタイルシート E をインポートする。 stylesheet C imports stylesheet E.

この場合、インポート優先順位は、低い側から D, B, E, C, A になる。 Then the order of import precedence (lowest first) is D, B, E, C, A.

注記: xsl:import 要素は、すべての定義とテンプレートより前に現れなくてはならないため、 xsl:import 要素に遭遇した時点でインポートされるスタイルシートを処理する実装は、インポート優先順位が低い方から先に、定義とテンプレートに遭遇することになる。 NOTE:Since xsl:import elements are required to occur before any definitions or template rules, an implementation that processes imported stylesheets at the point at which it encounters the xsl:import element will encounter definitions and template rules in increasing order of import precedence.

一般に、インポート優先順位が高い定義やテンプレートルールがインポート優先順位の低い定義やテンプレートルールよりも優先される。 より詳細は各種定義と各種テンプレートルールの項で定義される。 In general, a definition or template rule with higher import precedence takes precedence over a definition or template rule with lower import precedence. This is defined in detail for each kind of definition and for template rules.

スタイルシートが自身を直接的に, または間接的にインポートしている場合、エラーとする。 他の場合、同じ URI のスタイルシートが複数の場所からインポートされても特別に扱われない。 インポートツリー は、スタイルシートがインポートされた場所ごとに, 別々の xsl:stylesheet を持つ。 It is an error if a stylesheet directly or indirectly imports itself. Apart from this, the case where a stylesheet with a particular URI is imported in multiple places is not treated specially. The import tree will have a separate xsl:stylesheet for each place that it is imported.

注記: xsl:apply-imports が用いられた場合( [5.6 テンプレートルールの上書き] を見よ)、そのふるまいは、スタイルシートが インポート優先順位 が最高になる場所のみからインポートされた場合のふるまいと異なり得る。 NOTE:If xsl:apply-imports is used (see [5.6 Overriding Template Rules]), the behavior may be different from the behavior if the stylesheet had been imported only at the place with the highest import precedence.

2.7 スタイルシートの埋め込み

通常, XSLT スタイルシートは、 xsl:stylesheet 要素を文書要素として持つ完全な XML 文書である。 しかしながら、他のリソースに XSLT スタイルシートを埋め込むこともできる。 スタイルシートの埋め込みには次の2つの形式がある: Normally an XSLT stylesheet is a complete XML document with the xsl:stylesheet element as the document element. However, an XSLT stylesheet may also be embedded in another resource. Two forms of embedding are possible:

2つ目の形式による埋め込みを容易にするため、 xsl:stylesheet 要素には、一意的な識別子を指定する ID 型の属性が許容されている。 To facilitate the second form of embedding, the xsl:stylesheet element is allowed to have an ID attribute that specifies a unique identifier.

注記: このような ID 型の属性を XPath の id 関数と伴に利用できるようにするためには、この属性が ID 型として DTD 内で実際に宣言されていなければならない。 NOTE:In order for such an attribute to be used with the XPath id function, it must actually be declared in the DTD as being an ID.

下に、文書に独自のスタイルシートを含められるようにする処理命令 xml-stylesheet [XML Stylesheet] の用例を示す。 URI 参照には xsl:stylesheet 要素の位置を特定する素片識別子が付加された相対 URI が用いられる。 The following example shows how the xml-stylesheet processing instruction [XML Stylesheet] can be used to allow a document to contain its own stylesheet. The URI reference uses a relative URI with a fragment identifier to locate the xsl:stylesheet element:

<?xml-stylesheet type="text/xml" href="#style1"?>
<!DOCTYPE doc SYSTEM "doc.dtd">
<doc>
<head>
<xsl:stylesheet id="style1"
        version="1.0"
        xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
        xmlns:fo="http://www.w3.org/1999/XSL/Format">
<xsl:import href="doc.xsl"/>
<xsl:template match="id('foo')">
  <fo:block font-weight="bold"><xsl:apply-templates/></fo:block>
</xsl:template>
<xsl:template match="xsl:stylesheet">
  <!-- ignore -->
</xsl:template>
</xsl:stylesheet>
</head>
<body>
<para id="foo">
...
</para>
</body>
</doc>

注記: 文書に文書自身を適用対象にするスタイルシートを埋め込む場合、またはそのようなスタイルシートからインクルードあるいはインポートされ得るスタイルシートには、通常, xsl:stylesheet 要素が無視されるようなテンプレートルールを含めておく必要がある。 NOTE:A stylesheet that is embedded in the document to which it is to be applied or that may be included or imported into a stylesheet that is so embedded typically needs to contain a template rule that specifies that xsl:stylesheet elements are to be ignored.

3 データモデル

XSLT で利用されるデータモデルは、 XPath で利用されるデータモデルと同じデータモデルに, この節で述べるデータモデルを追加したものになる。 XSLT は、ソース文書, 結果文書, スタイルシート文書 に対し、同一のデータモデルを用いて処理を行う。 同じツリーを持つ2つの XML 文書は XSLT からは同等に扱われることになる。 The data model used by XSLT is the same as that used by XPath with the additions described in this section. XSLT operates on source, result and stylesheet documents using the same data model. Any two XML documents that have the same tree will be treated the same by XSLT.

スタイルシート内の処理命令とコメントは無視される:処理命令ノードとコメントノードのいずれもスタイルシートを表現するツリー内に含まれなかったかのように扱われる。 Processing instructions and comments in the stylesheet are ignored: the stylesheet is treated as if neither processing instruction nodes nor comment nodes were included in the tree that represents the stylesheet.

3.1 ルートノードの子

ルートノードの子に関する通常時の制約は、結果ツリーにおいては緩和される。 結果ツリーは、要素ノードに可能な任意のノードの並びを子として持ち得る。 特に、結果ツリーには任意の子テキストノードや任意個数の子要素ノードを含められる。 XML 出力メソッド( [16 出力] を見よ)を用いて書き出される場合、結果ツリーが整形式 XML 文書にならない可能性もあるが、その場合でも, 結果ツリーは常に整形式の外部一般解析対象実体になる。 The normal restrictions on the children of the root node are relaxed for the result tree. The result tree may have any sequence of nodes as children that would be possible for an element node. In particular, it may have text node children, and any number of element node children. When written out using the XML output method (see [16 Output]), it is possible that a result tree will not be a well-formed XML document; however, it will always be a well-formed external general parsed entity.

整形式 XML 文書の構文解析により生成される, ソースツリーのルートノードは、子テキストノードを持たず, 子要素を1個だけ持つ という通常時の制約を自動的に満たす。 DOM の利用など、ソースツリーが他の方法から生成される場合、結果ツリーの場合と同様に, ソースツリーに対しても通常時の制約が緩和される。 When the source tree is created by parsing a well-formed XML document, the root node of the source tree will automatically satisfy the normal restrictions of having no text node children and exactly one element child. When the source tree is created in some other way, for example by using the DOM, the usual restrictions are relaxed for the source tree as for the result tree.

3.2 基底 URI

各ノードには基底 URI と呼ばれる URI が結びつけられる。 基底 URI は属性値の相対 URI を絶対 URI に解決するために利用される。 要素または処理命令が外部実体に現れた場合、その要素や処理命令の基底 URI は、その外部実体の URI になる。 他の場合、文書の基底 URI が基底 URI になる。 文書ノードの基底 URI は文書実体の URI になる。 テキストノード, コメントノード, 属性ノード, 名前空間ノードの基底 URI は、各ノードの親の基底 URI になる。 Every node also has an associated URI called its base URI, which is used for resolving attribute values that represent relative URIs into absolute URIs. If an element or processing instruction occurs in an external entity, the base URI of that element or processing instruction is the URI of the external entity; otherwise, the base URI is the base URI of the document. The base URI of the document node is the URI of the document entity. The base URI for a text node, a comment node, an attribute node or a namespace node is the base URI of the parent of the node.

3.3 解析対象外実体

ルートノードは、文書の DTD で宣言された解析対象外実体のそれぞれを URI に対応付ける情報を持つ。 URI は実体宣言内で指定されたシステム識別子および公開識別子から生成される。 XSLT プロセッサは、システム識別子に指定された URI の代わりに、公開識別子を用いて実体の URI を生成してもよい。 XSLT プロセッサは、 URI 生成に公開識別子を利用しない場合、システム識別子を利用しなければならない。 システム識別子が相対 URI だった場合、実体宣言を含むリソースの URI を基底 URI [RFC2396] として、相対 URI を絶対 URI に解決しなければならない。 The root node has a mapping that gives the URI for each unparsed entity declared in the document's DTD. The URI is generated from the system identifier and public identifier specified in the entity declaration. The XSLT processor may use the public identifier to generate a URI for the entity instead of the URI specified in the system identifier. If the XSLT processor does not use the public identifier to generate the URI, it must use the system identifier; if the system identifier is a relative URI, it must be resolved into an absolute URI using the URI of the resource containing the entity declaration as the base URI [RFC2396].

3.4 空白の削除

ソース文書やスタイルシート文書のツリーが構築された後、 XSLT により他の処理が行われる前に、一部のテキストノードは削除される。 削除され得るテキストノードは空白文字のみからなるものに限られる。 削除されるテキストノードはツリーから取り除かれる。 削除処理においては、空白が保持されなければならない要素名の集合(以下、「空白保持要素名の集合」)が入力に与えられる。 削除処理はスタイルシートとソース文書の両方に適用されるが、空白保持要素名の集合は、スタイルシートとソース文書のそれぞれについて別々に決定される。 After the tree for a source document or stylesheet document has been constructed, but before it is otherwise processed by XSLT, some text nodes are stripped. A text node is never stripped unless it contains only whitespace characters. Stripping the text node removes the text node from the tree. The stripping process takes as input a set of element names for which whitespace must be preserved. The stripping process is applied to both stylesheets and source documents, but the set of whitespace-preserving element names is determined differently for stylesheets and for source documents.

下記のいずれかに該当するテキストノードのみが保持される。 A text node is preserved if any of the following apply:

これら以外のテキストノードは削除される。 Otherwise, the text node is stripped.

xml:space 属性はツリーから削除されない。 The xml:space attributes are not stripped from the tree.

注記: これにより、リテラル結果要素に指定された xml:space 属性は結果にも含まれることになる。 NOTE:This implies that if an xml:space attribute is specified on a literal result element, it will be included in the result.

スタイルシートに対する空白保持要素名の集合は xsl:text のみからなる。 For stylesheets, the set of whitespace-preserving element names consists of just xsl:text.

<!-- 分類:top-level-element -->
<xsl:strip-space
  elements = tokens />
<!-- 分類:top-level-element -->
<xsl:preserve-space
  elements = tokens />

ソース文書に対する空白保持要素名の集合は トップレベル 要素の xsl:strip-spacexsl:preserve-space により指定される。 要素名が空白保持要素名の集合に入るかどうかは xsl:strip-space 要素または xsl:preserve-space 要素の中で「最適に合致」するものから定まる: 合致するものが存在しない, または xsl:preserve-space 要素の中で最適に合致するときに限り、要素名は空白保持要素名の集合に入るものとする。 これらの xsl:strip-space 要素と xsl:preserve-space 要素はそれぞれ、空白区切りの NameTest のリストを値にとる elements 属性を持つ。 要素名はいずれかの NameTest に合致するときに限り、 xsl:strip-space または xsl:preserve-space 要素に合致するものとする。 要素は XPath のノードテスト により NameTest が真と評価されるときに限り、 NameTest に合致するものとする。 複数の xsl:strip-spacexsl:preserve-space 要素に合致する場合、最適な合致は NameTest に最適に合致するものから決定されるものとする。 この決定はテンプレートルールの場合と同じ方法で解決される: For source documents, the set of whitespace-preserving element names is specified by xsl:strip-space and xsl:preserve-spacetop-level elements. These elements each have an elements attribute whose value is a whitespace-separated list of NameTests. Initially, the set of whitespace-preserving element names contains all element names. If an element name matches a NameTest in an xsl:strip-space element, then it is removed from the set of whitespace-preserving element names. If an element name matches a NameTest in an xsl:preserve-space element, then it is added to the set of whitespace-preserving element names. An element matches a NameTest if and only if the NameTest would be true for the element as an XPath node test. Conflicts between matches to xsl:strip-space and xsl:preserve-space elements are resolved the same way as conflicts between template rules (see [5.5 Conflict Resolution for Template Rules]). Thus, the applicable match for a particular element name is determined as follows: Whether an element name is included in the set of whitespace-preserving names is determined by the best match amongst xsl:strip-space or xsl:preserve-space elements: it is included if and only if there is no match or the best match is an xsl:preserve-space element. These The xsl:strip-space and xsl:preserve-space elements each have an elements attribute whose value is a whitespace-separated list of NameTests; an element name matches an xsl:strip-space or xsl:preserve-space element if it matches one of the NameTests. An element matches a NameTest if and only if the NameTest would be true for the element as an XPath node test. When more than one xsl:strip-space and xsl:preserve-space element matches, the best matching element is determined by the best matching NameTest. This is determined in the same way as with template rules:

この判定後にも複数の合致が残る場合、エラーとする。 XSLT プロセッサはエラーを通知してもよい。 エラーを通知しない場合、判定後に残った合致からスタイルシートの最後方に現れるものを選択し, エラーから回復しなければならない。 It is an error if this leaves more than one match. An XSLT processor may signal the error; if it does not signal the error, it must recover by choosing, from amongst the matches that are left, the one that occurs last in the stylesheet.

3.5

データモデルは( [XML][XML Names] に適合する) XML 1.0 文書または( [XML 1.1][XML Names 1.1] に適合する)XML 1.1 文書のいずれも表現し得るものであり、この2つに対する区別は付けない。 従って、原理的には XSLT 1.0 はこれらの XML バージョンのいずれにも利用できる。 唯一、相違が生じ得るのは変換の本質から離れた部分からになる: テキストの XML からデータモデルを作成する際(構文解析)、あるいはデータモデルからテキストの XML を生成する際(直列化)。 The data model is capable of representing either an XML 1.0 document (conforming to [XML] and [XML Names]) or an XML 1.1 document (conforming to [XML 1.1] and [XML Names 1.1]), and it makes no distinction between the two. In principle, therefore, XSLT 1.0 can be used with either of these XML versions; the only differences arise outside the boundary of the transformation proper, either while creating the data model from textual XML (parsing), or while producing textual XML from the data model (serialization).

データモデルの構築はこの仕様の範囲外であり、 XSLT 1.0 においては XSLT プロセッサに対し、 XML 1.0 文書か XML 1.1 文書のいずれか, または両方からの入力に対する受容に関し、公式的な要件は課せられない。 この仕様は XML 1.0 と XML 1.1 文書の出力能力を定める( 16 出力 を見よ)。 これについても, XSLT プロセッサに対し、いずれの XML のバージョンをサポートするかについての要件は課せられない。 Construction of the data model is outside the scope of this specification, so XSLT 1.0 places no formal requirements on an XSLT processor to accept input from either XML 1.0 documents or XML 1.1 documents or both. This specification defines capability to output XML 1.0 or XML 1.1 documents (16 Output). There is again no formal requirement on an XSLT processor to support either or both of these XML versions.

元の文書が XML 1.0 か XML 1.1 かに関わらず、データモデルは同じなので、 XSLT 処理の意味内容は元の文書に利用される XML のバージョンには依存しない。 原則的に、一つの変換に用いられる入出力文書すべてが同じバージョンの XML に適合しなければならない理由は存在しない。 Because the data model is the same whether the original document was XML 1.0 or XML 1.1, the semantics of XSLT processing do not depend on the version of XML used by the original document. There is no reason in principle why all the input and output documents used in a single transformation must conform to the same version of XML.

4 式

XSLT は、 XPath [XPath] で定義される式言語を利用する。 XSLT では、以下の例も含め, 様々な用途に式を利用する。 XSLT uses the expression language defined by XPath [XPath]. Expressions are used in XSLT for a variety of purposes including:

は、 XPath の生成規則 Expr に合致しなければならない。 An expression must match the XPath production Expr.

式は、 XSLT で定義する要素の一部の属性に与える値として, あるいは 属性値テンプレート の中で波括弧( {} )で括られた中に生じ得る。 Expressions occur as the value of certain attributes on XSLT-defined elements and within curly braces in attribute value templates.

XSLT では, 最も外側の式(すなわち、他の式の一部でない式)の文脈( context )は次のように取得される: In XSLT, an outermost expression (i.e. an expression that is not part of another expression) gets its context as follows:

5 テンプレートルール

5.1 処理モデル

結果ツリー素片を生成するため、ソースノードのリストが処理される。 結果ツリーは、ルートノードのみを含むリストの処理から構築される。 ソースノードのリストは、リスト内の各ノードを順に処理して生成された結果を, ツリー構造に追加していく形で処理される。 それぞれのノードの処理は、すべてのテンプレートルールからそのノードに合致するパターンを持つものを検索し, その中から最適なテンプレートルールを選択する所から始められる。 選択されたルールのテンプレートは、ノードを 現在のノード に, ソースノードのリストを 現在のノードリスト に設定して、インスタンス化が行われる。 通常、テンプレートには処理の対象になる追加のソースノードのリストを選択する命令が含まれている。 この 合致照合, インスタンス化, 選択の処理行程 が、処理対象として新たに選択されるソースノードがついえるまで再帰的に続けられる。 A list of source nodes is processed to create a result tree fragment. The result tree is constructed by processing a list containing just the root node. A list of source nodes is processed by appending the result tree structure created by processing each of the members of the list in order. A node is processed by finding all the template rules with patterns that match the node, and choosing the best amongst them; the chosen rule's template is then instantiated with the node as the current node and with the list of source nodes as the current node list. A template typically contains instructions that select an additional list of source nodes for processing. The process of matching, instantiation and selection is continued recursively until no new source nodes are selected for processing.

この処理モデルによる結果と同じ処理結果が得られるならば、実装はどのようにソース文書を処理してもよい。 Implementations are free to process the source document in any way that produces the same result as if it were processed using this processing model.

5.2 パターン

テンプレートルールは、 パターン を用いて適用先のノードを選別する。 パターンは、テンプレートルールのみならず, 番号付け ( [7.7 番号付け] を見よ)やキー宣言( [12.2 キー] を見よ)にも利用される。 パターンはノードに対する条件の集合を指定する。 その条件すべてを満たすノードがそのパターンに合致するノードであり, 満たさないノードがそのパターンに合致しないノードとなる。 パターンの構文は、式の構文のサブセットである。 特に, 一定の制約を満たすロケーションパスは、パターンとしても利用できる。 パターンとしても利用可能な式は、常に, 評価結果がノード集合型のオブジェクトになる。 ノードがパターンに合致するのは、何らかの可能な文脈の下でパターンを式として評価した結果のノード集合に そのノードが属するときである。 可能な文脈とは、その文脈ノードが照合対象のノードそのものか, またはその先祖ノードの一つになるものを指す。 Template rules identify the nodes to which they apply by using a pattern. As well as being used in template rules, patterns are used for numbering (see [7.7 Numbering]) and for declaring keys (see [12.2 Keys]). A pattern specifies a set of conditions on a node. A node that satisfies the conditions matches the pattern; a node that does not satisfy the conditions does not match the pattern. The syntax for patterns is a subset of the syntax for expressions. In particular, location paths that meet certain restrictions can be used as patterns. An expression that is also a pattern always evaluates to an object of type node-set. A node matches a pattern if the node is a member of the result of evaluating the pattern as an expression with respect to some possible context; the possible contexts are those whose context node is the node being matched or one of its ancestors.

以下にパターンの例を示す。 Here are some examples of patterns:

パターンは Pattern の構文に一致しなければならない。 Pattern は、 | 区切りのロケーションパスパターンの集合である。 ロケーションパスパターンとは、すべてのステップに child 軸または attribute 軸のみを利用するロケーションパスである。 パターンでは descendant-or-self 軸を利用してはならないが、演算子 / と同様に演算子 // を利用してもよい。 ロケーションパスパターンは、リテラル引数による id 関数や key 関数の呼び出しからも始められる。 パターンの述語には、ロケーションパスの述語と同じく、任意の式を利用できる。 A pattern must match the grammar for Pattern. A Pattern is a set of location path patterns separated by |. A location path pattern is a location path whose steps all use only the child or attribute axes. Although patterns must not use the descendant-or-self axis, patterns may use the // operator as well as the / operator. Location path patterns can also start with an id or key function call with a literal argument. Predicates in a pattern can use arbitrary expressions just like predicates in a location path.

パターン
[1] Pattern ::= LocationPathPattern
| Pattern '|' LocationPathPattern
[2] LocationPathPattern ::= '/' RelativePathPattern?
| IdKeyPattern (('/' | '//') RelativePathPattern)?
| '//'? RelativePathPattern
[3] IdKeyPattern ::= 'id' '(' Literal ')'
| 'key' '(' Literal ',' Literal ')'
[4] RelativePathPattern ::= StepPattern
| RelativePathPattern '/' StepPattern
| RelativePathPattern '//' StepPattern
[5] StepPattern ::= ChildOrAttributeAxisSpecifier NodeTest Predicate*
[6] ChildOrAttributeAxisSpecifier ::= AbbreviatedAxisSpecifier
| ('child' | 'attribute') '::'

パターンがノードに合致するとは、ある「可能な」文脈の下でパターンが式として評価された結果のノード集合にノードが属するとき、と定義される。 ノードが照合される際の可能な文脈とは、文脈ノードが照合対象のノードまたはそのノードの先祖であり, かつ 文脈ノードリストがその文脈ノードのみからなる文脈とする。 A pattern is defined to match a node if and only if there is possible context such that when the pattern is evaluated as an expression with that context, the node is a member of the resulting node-set. When a node is being matched, the possible contexts have a context node that is the node being matched or any ancestor of that node, and a context node list containing just the context node.

例えば p がすべての p 要素に合致するのは、どの p であれ, p 要素の親を文脈ノードとして式 p を評価したとき、結果のノード集合に p 要素が含まれるからである。 For example, p matches any p element, because for any p if the expression p is evaluated with the parent of the p element as context the resulting node-set will contain that p element as one of its members.

注記: このことは、 p 要素が文書要素であっても, 文書のルートが文書要素の親になるので成立する。 NOTE:This matches even a p element that is the document element, since the document root is the parent of the document element.

パターンの意味内容は式の評価に基づいて間接的に指定されるが、パターンの意味は式の評価の視点で考えなくとも直接的に容易に理解できる。 パターンにおいて | は選択肢を示す。 1個以上の | で区切られた選択肢を持つパターンは、選択肢のいずれかが合致するとき, パターンとして合致する。 パターンが / または // で区切られた一連の StepPattern で構成されている場合、パターンの照合は右から左へ順に行われる。 パターンが合致するのは、右端の StepPattern が合致し, 残りのパターンにも合致する「適切な」要素が存在するときになる。 区切りが / の場合、親のみが適切な要素になる。 区切りが // の場合、すべての先祖が適切な要素になる。 child 軸を利用する StepPattern がノードに合致するのは、ノードに対する NodeTest が真であり, かつ そのノードが属性ノードでないときになる。 attribute 軸を利用する StepPattern がノードに合致するのは、ノードに対する NodeTest が真であり, かつ そのノードが属性ノードのときになる。 述語 [] がある場合、照合されるノードが属性ノードでないならば, そのノードを文脈ノードとし、その同胞ノードのうち NodeTest に合致するものを文脈ノードリストとして, StepPattern の最初の PredicateExpr が評価される。 照合されるノードが属性ノードの場合の文脈ノードリストは、 NodeTest に合致する同胞属性(同じ親を持つ属性)のうち, NodeTest に合致するものからなるとする。 Although the semantics of patterns are specified indirectly in terms of expression evaluation, it is easy to understand the meaning of a pattern directly without thinking in terms of expression evaluation. In a pattern, | indicates alternatives; a pattern with one or more | separated alternatives matches if any one of the alternative matches. A pattern that consists of a sequence of StepPatterns separated by / or // is matched from right to left. The pattern only matches if the rightmost StepPattern matches and a suitable element matches the rest of the pattern; if the separator is / then only the parent is a suitable element; if the separator is //, then any ancestor is a suitable element. A StepPattern that uses the child axis matches if the NodeTest is true for the node and the node is not an attribute node. A StepPattern that uses the attribute axis matches if the NodeTest is true for the node and the node is an attribute node. When [] is present, then the first PredicateExpr in a StepPattern is evaluated with the node being matched as the context node and the siblings of the context node that match the NodeTest as the context node list, unless the node being matched is an attribute node, in which case the context node list is all the attributes that have the same parent as the attribute being matched and that match the NameTest.

例えば For example

appendix//ulist/item[position()=1]

は、次に挙げる条件がすべて真となる場合にのみ、ノードに合致する。 matches a node if and only if all of the following are true:

5.3 テンプレートルールの定義

<!-- 分類:top-level-element -->
<xsl:template
  match = pattern 
  name = qname 
  priority = number 
  mode = qname>
  <!-- 内容:(xsl:param*, template) -->
</xsl:template>

テンプレートルールは、xsl:template 要素を用いて指定される。 match 属性がソースノードやルールの適用先ノードを選別する Pattern を与える。 match 属性は xsl:template 要素が name 属性を持つ場合を除き, 必須になる( [6 名前付きテンプレート] を見よ)。 match 属性の値が VariableReference を含む場合、エラーとする。 xsl:template 要素の内容が、テンプレートルールが適用されるときにインスタンス化されるテンプレートである。 A template rule is specified with the xsl:template element. The match attribute is a Pattern that identifies the source node or nodes to which the rule applies. The match attribute is required unless the xsl:template element has a name attribute (see [6 Named Templates]). It is an error for the value of the match attribute to contain a VariableReference. The content of the xsl:template element is the template that is instantiated when the template rule is applied.

例えば XML 文書が次を含むとする: For example, an XML document might contain:

This is an <emph>important</emph> point.

次のテンプレートルールは、上の emph 要素に合致し, font-weight プロパティが bold のフォーマッティングオブジェクト fo:inline-sequence を生成する。 The following template rule matches emph elements and produces a fo:inline-sequence formatting object with a font-weight property of bold.

<xsl:template match="emph">
  <fo:inline-sequence font-weight="bold">
    <xsl:apply-templates/>
  </fo:inline-sequence>
</xsl:template>

注記: この仕様の記述例では、接頭辞 fo:[XSL] が定めるフォーマット化オブジェクトの名前空間 http://www.w3.org/1999/XSL/Format に利用する。 NOTE:Examples in this document use the fo: prefix for the namespace http://www.w3.org/1999/XSL/Format, which is the namespace of the formatting objects defined in [XSL].

次節で述べるように xsl:apply-templates 要素はソース要素の子を再帰的に処理する。 As described next, the xsl:apply-templates element recursively processes the children of the source element.

5.4 テンプレートルールの適用

<!-- 分類:instruction -->
<xsl:apply-templates
  select = node-set-expression 
  mode = qname>
  <!-- 内容:(xsl:sort | xsl:with-param)* -->
</xsl:apply-templates>

次の例は chapter 要素に対し fo:block を生成し、次にその chapter 要素の直下の子を処理する。 This example creates a block for a chapter element and then processes its immediate children.

<xsl:template match="chapter">
  <fo:block>
    <xsl:apply-templates/>
  </fo:block>
</xsl:template>

xsl:apply-templates 命令は、 select 属性が与えられていなければ, テキストノードを含む現在のノードのすべての子ノードを処理する。 ただし、 [3.4 空白の削除] に則って削除されるテキストノードは処理しない。 空白保持要素名の集合に含まれない要素に対しては、要素の内容に含まれるすべての空白がテキストとして処理される。 従って, 子要素に挟まれる空白も、 position 関数から子要素の位置を決定する際にカウントされる。 In the absence of a select attribute, the xsl:apply-templates instruction processes all of the children of the current node, including text nodes. However, text nodes that have been stripped as specified in [3.4 Whitespace Stripping] will not be processed. If stripping of whitespace nodes has not been enabled for an element, then all whitespace in the content of the element will be processed as text, and thus whitespace between child elements will count in determining the position of a child element as returned by the position function.

select 属性を利用すると、すべての子を処理する代わりに, 式により選別したノードだけを処理できる。 select 属性の値は である。 式の評価結果はノード集合でなければならない。 選択されたノード集合は、ソート( [10 ソート] を見よ)が指定されていなければ, 文書順に処理される。 次の例は author-group の子の author すべてを処理する。 A select attribute can be used to process nodes selected by an expression instead of processing all children. The value of the select attribute is an expression. The expression must evaluate to a node-set. The selected set of nodes is processed in document order, unless a sorting specification is present (see [10 Sorting]). The following example processes all of the author children of the author-group:

<xsl:template match="author-group">
  <fo:inline-sequence>
    <xsl:apply-templates select="author"/>
  </fo:inline-sequence>
</xsl:template>

次の例は、 author-group の子の author すべてに対し、その子の given-name すべてを処理する。 The following example processes all of the given-names of the authors that are children of author-group:

<xsl:template match="author-group">
  <fo:inline-sequence>
    <xsl:apply-templates select="author/given-name"/>
  </fo:inline-sequence>
</xsl:template>

次の例は、book 要素のすべての子孫 heading 要素を処理する。 This example processes all of the heading descendant elements of the book element.

<xsl:template match="book">
  <fo:block>
    <xsl:apply-templates select=".//heading"/>
  </fo:block>
</xsl:template>

現在のノードの子孫でない要素も処理できる。 次の例では department 要素が子要素 group および子孫要素 employee を持つものと仮定する。 「従業員」( employee )の「部署」( department )を見つけ、次に department の子の group を処理する。 It is also possible to process elements that are not descendants of the current node. This example assumes that a department element has group children and employee descendants. It finds an employee's department and then processes the group children of the department.

<xsl:template match="employee">
  <fo:block>
    Employee <xsl:apply-templates select="name"/> belongs to group
    <xsl:apply-templates select="ancestor::department/group"/>
  </fo:block>
</xsl:template>

複数の xsl:apply-templates 要素を一つのテンプレート内で利用すると、簡単な再順序付けも行える。 次の例は、2つの HTML テーブルを作成する。 最初のテーブルには「国内販売高」( domestic sales ), 次のテーブルには「海外販売高」( foreign sales )のデータを挿入する。 Multiple xsl:apply-templates elements can be used within a single template to do simple reordering. The following example creates two HTML tables. The first table is filled with domestic sales while the second table is filled with foreign sales.

<xsl:template match="product">
  <table>
    <xsl:apply-templates select="sales/domestic"/>
  </table>
  <table>
    <xsl:apply-templates select="sales/foreign"/>
  </table>
</xsl:template>

注記: 一方が他方の子孫になっているような2つの子孫が合致することもあり得る。 この場合も特別には扱われず、両者とも通常どおり処理される。 例えば次のソース文書: NOTE: It is possible for there to be two matching descendants where one is a descendant of the other. This case is not treated specially: both descendants will be processed as usual. For example, given a source document

<doc><div><div></div></div></doc>

に対し、ルール: the rule

<xsl:template match="doc">
  <xsl:apply-templates select=".//div"/>
</xsl:template>

は、外側の div 要素と内側の div 要素の両方を処理する。 will process both the outer div and inner div elements.

注記: 通常、 xsl:apply-templates は現在のノードの子孫のノードのみを処理する目的に利用される。 そのような利用では、無限処理ループ(無限再帰)は生じない。 xsl:apply-templates を現在のノードの子孫でない要素の処理に利用した場合、終端のない処理ループが生じ得る。 例えば NOTE:Typically, xsl:apply-templates is used to process only nodes that are descendants of the current node. Such use of xsl:apply-templates cannot result in non-terminating processing loops. However, when xsl:apply-templates is used to process elements that are not descendants of the current node, the possibility arises of non-terminating loops. For example,

<xsl:template match="foo">
  <xsl:apply-templates select="."/>
</xsl:template>

実装側がこのようなループを検知できる場合もあるが、検知できない無限ループに陥る可能性もある。 これは、サービスの安全性を侵すリスクになり得る。 Implementations may be able to detect such loops in some cases, but the possibility exists that a stylesheet may enter a non-terminating loop that an implementation is unable to detect. This may present a denial of service security risk.

5.5 テンプレートルールの競合解決

1個のソースノードが、複数のテンプレートに合致することがある。 利用されるテンプレートルールは以下の手順で決定される: It is possible for a source node to match more than one template rule. The template rule to be used is determined as follows:

  1. 最初に、合致するテンプレートルールの中で インポート優先順位 が最高でないものはすべて候補から外す。 First, all matching template rules that have lower import precedence than the matching template rule or rules with the highest import precedence are eliminated from consideration.

  2. 次に、合致したテンプレートルールのうち、優先度( priority )が最高でないものをすべて候補から外す。 テンプレートルールの優先度は、テンプレートルールの priority 属性で指定される。 優先度の値は実数であり(負も許容される)、オプションの先頭の負符号( - )に Number が後続する生成規則に合致しなければならない。 既定の優先度 は、次のように計算される。 Next, all matching template rules that have lower priority than the matching template rule or rules with the highest priority are eliminated from consideration. The priority of a template rule is specified by the priority attribute on the template rule. The value of this must be a real number (positive or negative), matching the production Number with an optional leading minus sign (-). The default priority is computed as follows:

    • パターンに | で区切られた複数の候補が含まれる場合、そのテンプレートは、候補それぞれに1個のテンプレートが存在するテンプレートの集合と同様に扱われる。 If the pattern contains multiple alternatives separated by |, then it is treated equivalently to a set of template rules, one for each alternative.

    • パターンが ChildOrAttributeAxisSpecifier から始まる QName 形式の場合, または ChildOrAttributeAxisSpecifier から始まる processing-instruction ( Literal ) 形式の場合、優先度は 0 。 If the pattern has the form of a QName preceded by a ChildOrAttributeAxisSpecifier or has the form processing-instruction(Literal) preceded by a ChildOrAttributeAxisSpecifier, then the priority is 0.

    • パターンが ChildOrAttributeAxisSpecifier から始まる NCName :* 形式の場合、優先度は -0.25 。 If the pattern has the form NCName:* preceded by a ChildOrAttributeAxisSpecifier, then the priority is -0.25.

    • 上記以外の, パターンが ChildOrAttributeAxisSpecifier から始まる NodeTest のみからなる場合、優先度は -0.5 。 Otherwise, if the pattern consists of just a NodeTest preceded by a ChildOrAttributeAxisSpecifier, then the priority is -0.5.

    • 他の場合、優先度は 0.5 。 Otherwise, the priority is 0.5.

    したがって、最もありふれたパターン(特定の型と特定の展開名を持つノードを選択するパターン)の優先度は 0 になる。 より条件が緩いパターン(特定の型と、特定の名前空間 URI を展開名に持つノードを選択するパターン)の優先度は -0.25 になる。 さらに条件が緩いパターン(単に特定の型を持つノードを選択するパターン)の優先度は -0.5 になる。 最もありふれたパターンより条件が厳しいパターンの優先度は 0.5 になる。 Thus, the most common kind of pattern (a pattern that tests for a node with a particular type and a particular expanded-name) has priority 0. The next less specific kind of pattern (a pattern that tests for a node with a particular type and an expanded-name with a particular namespace URI) has priority -0.25. Patterns less specific than this (patterns that just tests for nodes with particular types) have priority -0.5. Patterns more specific than the most common kind of pattern have priority 0.5.

この手続き後も, 合致するテンプレートルールが複数残る場合、エラーとする。 XSLT プロセッサは、エラーを通知してもよい。 エラーを通知しない場合、残ったテンプレートルールからスタイルシートの最後方に現れるものを選択し、エラーから回復しなければならない。 It is an error if this leaves more than one matching template rule. An XSLT processor may signal the error; if it does not signal the error, it must recover by choosing, from amongst the matching template rules that are left, the one that occurs last in the stylesheet.

5.6 テンプレートルールの上書き

<!-- 分類:instruction -->
<xsl:apply-imports />

テンプレートルールが, インポートしたスタイルシートのテンプレートルールを上書き( [5.5 テンプレートの競合解決] を見よ)していても、 xsl:apply-imports 要素を用いて上書きされたテンプレートルールを呼び出すことができる。 A template rule that is being used to override a template rule in an imported stylesheet (see [5.5 Conflict Resolution for Template Rules]) can use the xsl:apply-imports element to invoke the overridden template rule.

スタイルシート処理中は常に、 現在のテンプレートルール が存在する。 パターンの照合によりテンプレートルールが選択されると、ルール内のテンプレートをインスタンス化している間は, そのテンプレートルールが現在のテンプレートルールになる。 ただし, xsl:for-each 要素のインスタンス化においては、 xsl:for-each 要素の内容をインスタンス化している間は, 現在のテンプレートルールは null になる。 At any point in the processing of a stylesheet, there is a current template rule. Whenever a template rule is chosen by matching a pattern, the template rule becomes the current template rule for the instantiation of the rule's template. When an xsl:for-each element is instantiated, the current template rule becomes null for the instantiation of the content of the xsl:for-each element.

xsl:apply-imports は、現在のテンプレートルールが属するスタイルシート要素にインポートされたテンプレートルールのみを用いて, 現在のノードを処理する。 ノードは現在のテンプレートルールのモードで処理される。 現在のテンプレートルールが null のときに, xsl:apply-imports がインスタンス化された場合、エラーとする。 xsl:apply-imports processes the current node using only template rules that were imported into the stylesheet element containing the current template rule; the node is processed in the current template rule's mode. It is an error if xsl:apply-imports is instantiated when the current template rule is null.

例えば、スタイルシート doc.xslexample 要素用のテンプレートルールが含まれていたとする: For example, suppose the stylesheet doc.xsl contains a template rule for example elements:

<xsl:template match="example">
  <pre><xsl:apply-templates/></pre>
</xsl:template>

doc.xsl をインポートする他のスタイルシートは、次のように example 要素の扱いを変更できる: Another stylesheet could import doc.xsl and modify the treatment of example elements as follows:

<xsl:import href="doc.xsl"/>

<xsl:template match="example">
  <div style="border: solid red">
     <xsl:apply-imports/>
  </div>
</xsl:template>

この組み合わせにより、 example 要素は次の形に変換される: The combined effect would be to transform an example into an element of the form:

<div style="border: solid red"><pre>...</pre></div>

5.7 モード

モードを利用すれば、要素を複数回処理させつつ, 毎回異なる結果が得られるようになる。 Modes allow an element to be processed multiple times, each time producing a different result.

xsl:templatexsl:apply-templates は、オプションで mode 属性を利用できる。 mode 属性の値は QName であり、 [2.4 修飾名] に則って展開される。 xsl:templatematch 属性を持たない場合、 mode 属性も持ってはならない。 mode 属性が与えられている xsl:apply-templates 要素は、同じ mode 属性値を持つ xsl:template 要素のテンプレートルールのみを適用する。 mode 属性が与えられていない xsl:apply-templates 要素は、 mode 属性を持たない xsl:template 要素のテンプレートルールのみを適用する。 Both xsl:template and xsl:apply-templates have an optional mode attribute. The value of the mode attribute is a QName, which is expanded as described in [2.4 Qualified Names]. If xsl:template does not have a match attribute, it must not have a mode attribute. If an xsl:apply-templates element has a mode attribute, then it applies only to those template rules from xsl:template elements that have a mode attribute with the same value; if an xsl:apply-templates element does not have a mode attribute, then it applies only to those template rules from xsl:template elements that do not have a mode attribute.

5.8 組み込みテンプレートルール

合致するパターンを持つテンプレートルールがスタイルシートの中に明示的に与えられていなくても、再帰的な処理の継続を可能にする暗黙の組み込みテンプレートルールがある。 このテンプレートルールは、要素ノードとルートノードの両方に適用される。 組み込みテンプレートルールと等価の記述を次に示す: There is a built-in template rule to allow recursive processing to continue in the absence of a successful pattern match by an explicit template rule in the stylesheet. This template rule applies to both element nodes and the root node. The following shows the equivalent of the built-in template rule:

<xsl:template match="*|/">
  <xsl:apply-templates/>
</xsl:template>

それぞれのモードにも、スタイルシートの中に合致するパターンを持つテンプレートルールが明示的に与えられていなくても、同じモードによる再帰的な処理の継続を可能にする暗黙の組み込みテンプレートルールがある。 このテンプレートルールは、要素ノードとルートノードの両方に適用される。 モード m の組み込みテンプレートルールと等価の記述を次に示す: There is also a built-in template rule for each mode, which allows recursive processing to continue in the same mode in the absence of a successful pattern match by an explicit template rule in the stylesheet. This template rule applies to both element nodes and the root node. The following shows the equivalent of the built-in template rule for mode m.

<xsl:template match="*|/" mode="m">
  <xsl:apply-templates mode="m"/>
</xsl:template>

テキストノードと属性ノードについても、テキストを複製する暗黙の組み込みテンプレートルールが存在する: There is also a built-in template rule for text and attribute nodes that copies text through:

<xsl:template match="text()|@*">
  <xsl:value-of select="."/>
</xsl:template>

処理命令およびコメントに対する組み込みテンプレートルールは、何も実行しない。 The built-in template rule for processing instructions and comments is to do nothing.

<xsl:template match="processing-instruction()|comment()"/>

名前空間ノードに対する組み込みテンプレートルールも、何も実行しない。 名前空間ノードに合致し得るパターンは存在しないため、名前空間ノードに適用されるテンプレートルールは組み込みのものだけになる。 The built-in template rule for namespace nodes is also to do nothing. There is no pattern that can match a namespace node; so, the built-in template rule is the only template rule that is applied for namespace nodes.

組み込みテンプレートルールは、スタイルシートの前に暗黙的にインポートされたかのように扱われるため、 インポート優先順位 は他のすべてのテンプレートルールよりも低くなる。 従って, スタイルシート作成者は、テンプレートルールを明示的に与えることにより, 組み込みテンプレートルールを上書きできる。 The built-in template rules are treated as if they were imported implicitly before the stylesheet and so have lower import precedence than all other template rules. Thus, the author can override a built-in template rule by including an explicit template rule.

6 名前付きテンプレート

<!-- 分類:instruction -->
<xsl:call-template
  name = qname>
  <!-- 内容:xsl:with-param* -->
</xsl:call-template>

テンプレートは、名前で呼び出すこともできる。 name 属性が与えられた xsl:template 要素は、名前付きテンプレートになる。 name 属性の値は QName であり、 [2.4 修飾名] に則って展開される。 name 属性を持つ xsl:template 要素に match 属性を指定してもよいが、そうする必要はない。 xsl:call-template 要素が、テンプレートを名前で呼び出す。従って、呼び出すテンプレートを識別する name 属性を持たなければならない。 xsl:apply-templates と異なり、 xsl:call-template は現在のノードや現在のノードリストを変更しない。 Templates can be invoked by name. An xsl:template element with a name attribute specifies a named template. The value of the name attribute is a QName, which is expanded as described in [2.4 Qualified Names]. If an xsl:template element has a name attribute, it may, but need not, also have a match attribute. An xsl:call-template element invokes a template by name; it has a required name attribute that identifies the template to be invoked. Unlike xsl:apply-templates, xsl:call-template does not change the current node or the current node list.

xsl:template 要素の match 属性, mode 属性, priority 属性は、 xsl:call-template 要素からのテンプレートの呼び出しに影響しない。 同様に, xsl:template 要素の name 属性も、 xsl:apply-templates 要素からのテンプレートの呼び出しに影響しない。 The match, mode and priority attributes on an xsl:template element do not affect whether the template is invoked by an xsl:call-template element. Similarly, the name attribute on an xsl:template element does not affect whether the template is invoked by an xsl:apply-templates element.

スタイルシートに、同じ名前の, 同じ インポート優先順位 のテンプレートが複数含まれる場合、エラーとする。 It is an error if a stylesheet contains more than one template with the same name and same import precedence.

7 結果ツリーの生成

この節では、結果ツリーに直接ノードを生成する命令について述べる。 This section describes instructions that directly create nodes in the result tree.

7.1 要素と属性の生成

7.1.1 リテラル結果要素

スタイルシート内の、 XSLT 名前空間に属さない, 拡張要素( [14.1 拡張要素] を見よ)でもない, テンプレート内の要素は、インスタンス化の際に同一の 展開名 を持つ要素ノードを生成する。 この要素の内容はテンプレートであり、生成される要素ノードの内容を与えるためにインスタンス化される。 生成される要素ノードは、スタイルシートツリー内の要素ノードの属性から XSLT 名前空間に属する属性を除いた属性を持つことになる。 In a template, an element in the stylesheet that does not belong to the XSLT namespace and that is not an extension element (see [14.1 Extension Elements]) is instantiated to create an element node with the same expanded-name. The content of the element is a template, which is instantiated to give the content of the created element node. The created element node will have the attribute nodes that were present on the element node in the stylesheet tree, other than attributes with names in the XSLT namespace.

生成された要素ノードは、スタイルシートツリー内の要素ノードに存在する名前空間ノードの複製も持つ。 ただし、 XSLT 名前空間 URI ( http://www.w3.org/1999/XSL/Transform ), 拡張名前空間として宣言された名前空間 URI ( [14.1 拡張要素] を見よ), および「除外指定」された名前空間 URI , を文字列値とする名前空間ノードは除外される。 名前空間を除外指定にするには、 xsl:stylesheet 要素の exclude-result-prefixes 属性, またはリテラル結果要素の xsl:exclude-result-prefixes 属性に名前空間接頭辞の空白区切りのリストを与える。 各接頭辞に結びつけられた名前空間 URI の名前空間が、除外指定にされる。 それらの名前空間がその属性を持つ要素のスコープに入らない場合、エラーとする。 名前空間接頭辞のリストに #default を含めれば、既定の名前空間( xmlns で宣言されたもの)も除外指定にできる。 名前空間の除外指定は、 exclude-result-prefixes または xsl:exclude-result-prefixes 属性を持つ要素をルートとするスタイルシートの部分ツリーの中で有効になる。 ただし, xsl:stylesheet 要素をルートとする部分ツリーには、その xsl:stylesheet 要素の子によりインポートまたインクルードされたスタイルシートは含まれないものとする。 The created element node will also have a copy of the namespace nodes that were present on the element node in the stylesheet tree with the exception of any namespace node whose string-value is the XSLT namespace URI (http://www.w3.org/1999/XSL/Transform), a namespace URI declared as an extension namespace (see [14.1 Extension Elements]), or a namespace URI designated as an excluded namespace. A namespace URI is designated as an excluded namespace by using an exclude-result-prefixes attribute on an xsl:stylesheet element or an xsl:exclude-result-prefixes attribute on a literal result element. The value of both these attributes is a whitespace-separated list of namespace prefixes. The namespace bound to each of the prefixes is designated as an excluded namespace. It is an error if there is no namespace bound to the prefix on the element bearing the exclude-result-prefixes or xsl:exclude-result-prefixes attribute. The default namespace (as declared by xmlns) may be designated as an excluded namespace by including #default in the list of namespace prefixes. The designation of a namespace as an excluded namespace is effective within the subtree of the stylesheet rooted at the element bearing the exclude-result-prefixes or xsl:exclude-result-prefixes attribute; a subtree rooted at an xsl:stylesheet element does not include any stylesheets imported or included by children of that xsl:stylesheet element.

注記: スタイルシートで, ソースツリーの位置指定の目的のみに名前空間宣言を利用するような場合、 exclude-result-prefixes 属性に接頭辞を指定して, 結果ツリーに余分な名前空間宣言が生成されないようにすることができる。 NOTE:When a stylesheet uses a namespace declaration only for the purposes of addressing the source tree, specifying the prefix in the exclude-result-prefixes attribute will avoid superfluous namespace declarations in the result tree.

リテラル結果要素の属性値は、 属性値テンプレート として解釈される。 このテンプレートには、波括弧( {} )で括った式を含められる。 The value of an attribute of a literal result element is interpreted as an attribute value template: it can contain expressions contained in curly braces ({}).

スタイルシートツリー内の名前空間 URI のうち, 結果ツリー内の名前空間 URI を指定するために利用されるものを リテラル名前空間 URI と呼ぶ。 次に挙げるものがこの URI に該当する: A namespace URI in the stylesheet tree that is being used to specify a namespace URI in the result tree is called a literal namespace URI. This applies to:

  • スタイルシートに含まれるリテラル結果要素の展開名の名前空間 URI the namespace URI in the expanded-name of a literal result element in the stylesheet

  • スタイルシートに含まれるリテラル結果要素に指定されている属性の展開名の名前空間 URI the namespace URI in the expanded-name of an attribute specified on a literal result element in the stylesheet

  • スタイルシートに含まれるリテラル結果要素の名前空間ノードの文字列値 the string-value of a namespace node on a literal result element in the stylesheet

<!-- 分類:top-level-element -->
<xsl:namespace-alias
  stylesheet-prefix = prefix | "#default"
  result-prefix = prefix | "#default" />

xsl:namespace-alias 要素を利用して一つの名前空間 URI を別の名前空間 URI への エイリアス として宣言できる。 リテラル名前空間 URI を, 他の名前空間 URI へのエイリアスとして宣言した場合、結果ツリー内における名前空間 URI が, リテラル名前空間 URI 自身でなく, エイリアスが指す名前空間 URI になる。 xsl:namespace-alias 要素は、 stylesheet-prefix 属性で指定される接頭辞に結びつけられた名前空間 URI が, result-prefix 属性で指定される接頭辞に結びつけられた名前空間 URI へのエイリアスであるものと宣言する。 すなわち, stylesheet-prefix 属性がスタイルシートに現れる名前空間 URI を指し、 result-prefix 属性が, それに対応して結果ツリーに生成される名前空間 URI を指すことになる。 接頭辞の代わりに, #default を用いて既定の名前空間( xmlns で宣言されたもの)を指定してもよい。 一つの名前空間 URI が, 複数の異なる名前空間 URI へのエイリアスとして宣言されている場合、 インポート優先順位 が最高のものが利用される。 そのような宣言が複数存在する場合、エラーとする。 XSLT プロセッサは、エラーを通知してもよい。 エラーを通知しない場合、それらの中からスタイルシートの最後方に現れるものを選択し, エラーから回復しなければならない。 A stylesheet can use the xsl:namespace-alias element to declare that one namespace URI is an alias for another namespace URI. When a literal namespace URI has been declared to be an alias for another namespace URI, then the namespace URI in the result tree will be the namespace URI that the literal namespace URI is an alias for, instead of the literal namespace URI itself. The xsl:namespace-alias element declares that the namespace URI bound to the prefix specified by the stylesheet-prefix attribute is an alias for the namespace URI bound to the prefix specified by the result-prefix attribute. Thus, the stylesheet-prefix attribute specifies the namespace URI that will appear in the stylesheet, and the result-prefix attribute specifies the corresponding namespace URI that will appear in the result tree. The default namespace (as declared by xmlns) may be specified by using #default instead of a prefix. If a namespace URI is declared to be an alias for multiple different namespace URIs, then the declaration with the highest import precedence is used. It is an error if there is more than one such declaration. An XSLT processor may signal the error; if it does not signal the error, it must recover by choosing, from amongst the declarations with the highest import precedence, the one that occurs last in the stylesheet.

リテラル結果要素を XSLT 名前空間 URI を利用する 要素, 属性, 名前空間ノード の生成に利用する場合、エイリアスを利用しなければならなくなる。 例えば, 次のスタイルシート: When literal result elements are being used to create element, attribute, or namespace nodes that use the XSLT namespace URI, the stylesheet must use an alias. For example, the stylesheet

<xsl:stylesheet
  version="1.0"
  xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  xmlns:fo="http://www.w3.org/1999/XSL/Format"
  xmlns:axsl="http://www.w3.org/1999/XSL/TransformAlias">

<xsl:namespace-alias stylesheet-prefix="axsl" result-prefix="xsl"/>

<xsl:template match="/">
  <axsl:stylesheet>
    <xsl:apply-templates/>
  </axsl:stylesheet>
</xsl:template>

<xsl:template match="block">
  <axsl:template match="{.}">
     <fo:block><axsl:apply-templates/></fo:block>
  </axsl:template>
</xsl:template>

</xsl:stylesheet>

は、次の文書から XSLT スタイルシートを生成する。 will generate an XSLT stylesheet from a document of the form:

<elements>
<block>p</block>
<block>h1</block>
<block>h2</block>
<block>h3</block>
<block>h4</block>
</elements>

注記: XSLT 名前空間 URI 以外の名前空間でも、エイリアスを利用しなければならない局面がある。 例えば, リテラル結果要素がデジタル署名を扱う名前空間に属する場合、汎用のセキュリティソフトウェアによる XSLT スタイルシートの誤処理を呼ぶ可能性がある。 名前空間のエイリアスを利用することにより、このような誤処理の可能性を回避できる。 NOTE:It may be necessary also to use aliases for namespaces other than the XSLT namespace URI. For example, literal result elements belonging to a namespace dealing with digital signatures might cause XSLT stylesheets to be mishandled by general-purpose security software; using an alias for the namespace would avoid the possibility of such mishandling.

7.1.2 xsl:element による要素の生成

<!-- 分類:instruction -->
<xsl:element
  name = { qname }
  namespace = { uri-reference }
  use-attribute-sets = qnames>
  <!-- 内容:template -->
</xsl:element>

xsl:element 要素を用いて、式から算出される名前の要素を生成できる。 生成される要素の 展開名 は、必須の name 属性とオプションの namespace 属性で指定する。 xsl:element 要素の内容が、生成される要素の属性および子を生成するためのテンプレートである。 The xsl:element element allows an element to be created with a computed name. The expanded-name of the element to be created is specified by a required name attribute and an optional namespace attribute. The content of the xsl:element element is a template for the attributes and children of the created element.

name 属性は、 属性値テンプレート として処理される。 属性値テンプレートをインスタンス化した結果の文字列が、 QName でない場合はエラーとする。 XSLT プロセッサは、エラーを通知してもよい。 エラーを通知しない場合、 xsl:element 要素の内容から初期属性ノードを除いた部分をインスタンス化した一連のノードを xsl:element 要素のインスタンス化の結果とすることにより, エラーから回復しなければならない。 【「初期属性ノード」 - initial attribute nodes の意味内容がはっきりしないが、要するに xsl:element に与えられた属性を指すものと思われる】 namespace 属性が与えられていない場合、 QNamexsl:element 要素に対し有効な名前空間宣言(既定の名前空間宣言も含む)を利用して展開名へ展開される。 The name attribute is interpreted as an attribute value template. It is an error if the string that results from instantiating the attribute value template is not a QName. An XSLT processor may signal the error; if it does not signal the error, then it must recover by making the the result of instantiating the xsl:element element be the sequence of nodes created by instantiating the content of the xsl:element element, excluding any initial attribute nodes. If the namespace attribute is not present then the QName is expanded into an expanded-name using the namespace declarations in effect for the xsl:element element, including any default namespace declaration.

namespace 属性が与えられている場合、それも 属性値テンプレート として処理される。 そのインスタンス化による結果の文字列は URI 参照になるべきであるが、 URI 参照として構文的に正しくなくても, エラーではない。 結果の文字列が空になった場合、要素の展開名の名前空間 URI は null になる。 そうでない場合、生成される要素の展開名の名前空間 URI になる。 name 属性により指定される QName の局所部は、生成される要素の展開名の局所部になる。 If the namespace attribute is present, then it also is interpreted as an attribute value template. The string that results from instantiating the attribute value template should be a URI reference. It is not an error if the string is not a syntactically legal URI reference. If the string is empty, then the expanded-name of the element has a null namespace URI. Otherwise, the string is used as the namespace URI of the expanded-name of the element to be created. The local part of the QName specified by the name attribute is used as the local part of the expanded-name of the element to be created.

XSLT プロセッサは、生成される要素を XML として出力するために接頭辞を選択する際に, name 属性で指定される QName の接頭辞を利用してもよい。 ただし、これは必須ではない。 XSLT processors may make use of the prefix of the QName specified in the name attribute when selecting the prefix used for outputting the created element as XML; however, they are not required to do so.

7.1.3 xsl:attribute による属性の生成

<!-- 分類:instruction -->
<xsl:attribute
  name = { qname }
  namespace = { uri-reference }>
  <!-- 内容:template -->
</xsl:attribute>

xsl:attribute 要素を用いて, スタイルシートのリテラル結果要素や xsl:element などの命令から生成される結果要素に属性を追加できる。 生成される属性の 展開名 は、必須の name 属性とオプションの namespace 属性に指定する。 xsl:attribute 要素がインスタンス化されると、所属する結果要素ノードに属性ノードが追加される。 xsl:attribute 要素の内容が、生成される属性値のテンプレートである。 The xsl:attribute element can be used to add attributes to result elements whether created by literal result elements in the stylesheet or by instructions such as xsl:element. The expanded-name of the attribute to be created is specified by a required name attribute and an optional namespace attribute. Instantiating an xsl:attribute element adds an attribute node to the containing result element node. The content of the xsl:attribute element is a template for the value of the created attribute.

name 属性は 属性値テンプレート として処理される。 属性値テンプレートをインスタンス化した結果の文字列が, QName でない場合や文字列 xmlns になる場合、エラーとする。 XSLT プロセッサは、エラーを通知してもよい。 エラーを通知しない場合、結果ツリーに属性を追加しないことにより, エラーから回復しなければならない。 namespace 属性が与えられていない場合、 QNamexsl:element 要素に対し有効な名前空間宣言(既定の名前空間宣言を除く)を利用して展開名へ展開される。 The name attribute is interpreted as an attribute value template. It is an error if the string that results from instantiating the attribute value template is not a QName or is the string xmlns. An XSLT processor may signal the error; if it does not signal the error, it must recover by not adding the attribute to the result tree. If the namespace attribute is not present, then the QName is expanded into an expanded-name using the namespace declarations in effect for the xsl:attribute element, not including any default namespace declaration.

namespace 属性が与えられている場合、それも 属性値テンプレート として処理される。 そのインスタンス化による結果の文字列は URI 参照になるべきであるが、 URI 参照として構文的に正しくなくても, エラーではない。 結果の文字列が空になった場合、属性の展開名の名前空間 URI は null になる。 そうでない場合、生成される属性の展開名の名前空間 URI になる。 name 属性により指定される QName の局所部は、生成される属性の展開名の局所部になる。 If the namespace attribute is present, then it also is interpreted as an attribute value template. The string that results from instantiating it should be a URI reference. It is not an error if the string is not a syntactically legal URI reference. If the string is empty, then the expanded-name of the attribute has a null namespace URI. Otherwise, the string is used as the namespace URI of the expanded-name of the attribute to be created. The local part of the QName specified by the name attribute is used as the local part of the expanded-name of the attribute to be created.

XSLT プロセッサは、生成した属性を XML として出力するために接頭辞を選択する際, name 属性に指定されている QName の接頭辞を利用してもよい。 ただし、これは必須ではなく、接頭辞が xmlns だった場合, これを利用してはならない。 次の例は、実行してもエラーにはならないが名前空間宣言は出力されない: XSLT processors may make use of the prefix of the QName specified in the name attribute when selecting the prefix used for outputting the created attribute as XML; however, they are not required to do so and, if the prefix is xmlns, they must not do so. Thus, although it is not an error to do:

<xsl:attribute name="xmlns:xsl" namespace="whatever">http://www.w3.org/1999/XSL/Transform</xsl:attribute>

  it will not result in a namespace declaration being output.

要素に属性を追加すると、その要素と展開名が同じになる既存の属性は上書きされる。 Adding an attribute to an element replaces any existing attribute of that element with the same expanded-name.

次に挙げるものは、すべてエラーとする: The following are all errors:

  • 要素に子を追加した後で、その要素に属性を追加すること。 実装はエラーを通知してもよいし、属性を無視してもよい。 Adding an attribute to an element after children have been added to it; implementations may either signal the error or ignore the attribute.

  • 要素でないノードに属性を追加すること。 実装はエラーを通知してもよいし、属性を無視してもよい。 Adding an attribute to a node that is not an element; implementations may either signal the error or ignore the attribute.

  • xsl:attribute 要素の内容をインスタンス化する際に、テキストノード以外のノードを生成すること。 実装はエラーを通知してもよいし、エラーの要因になったノードをその内容と伴に無視してもよい。 Creating nodes other than text nodes during the instantiation of the content of the xsl:attribute element; implementations may either signal the error or ignore the offending nodes together with their content.

注記: xsl:attribute が改行を伴うテキストノードを含む場合、 XML の出力においては文字参照にしなければならない。 例えば: NOTE:When an xsl:attribute contains a text node with a newline, then the XML output must contain a character reference. For example,

<xsl:attribute name="a">x
y</xsl:attribute>

による出力結果は: will result in the output

a="x&#xA;y"

(または同等の文字参照)。 XML の出力では、次は不可: (or with any equivalent character reference). The XML output cannot be

a="x
y"

これは、 XML 1.0 では, 属性値に含まれる改行文字はスペースに正規化し, 改行文字を表す文字参照は正規化しないことが要求されているためである。 データモデル内の属性値は、正規化後の属性値を表現する。 ツリー内の属性値に現れた改行が、文字参照としてではなく, 改行文字として出力された場合、 XML を再び構文解析して生成されるツリー内の属性値の改行がスペースにすり替えられる, つまり ツリーが正しく出力されなかったことになる。 This is because XML 1.0 requires newline characters in attribute values to be normalized into spaces but requires character references to newline characters not to be normalized. The attribute values in the data model represent the attribute value after normalization. If a newline occurring in an attribute value in the tree were output as a newline character rather than as character reference, then the attribute value in the tree created by reparsing the XML would contain a space not a newline, which would mean that the tree had not been output correctly.

7.1.4 名前付き属性集合

<!-- 分類:top-level-element -->
<xsl:attribute-set
  name = qname 
  use-attribute-sets = qnames>
  <!-- 内容:xsl:attribute* -->
</xsl:attribute-set>

xsl:attribute-set 要素は、名前の付いた属性の集合を定義する。 集合の名前は name 属性で指定する。 name 属性の値は QName であり, [2.4 修飾名] に則って展開される。 xsl:attribute-set 要素の内容は、集合に含まれる属性を指定する0個以上の xsl:attribute 要素からなる。 The xsl:attribute-set element defines a named set of attributes. The name attribute specifies the name of the attribute set. The value of the name attribute is a QName, which is expanded as described in [2.4 Qualified Names]. The content of the xsl:attribute-set element consists of zero or more xsl:attribute elements that specify the attributes in the set.

属性の集合は xsl:element 要素, xsl:copy 要素( [7.5 複製] を見よ), xsl:attribute-set 要素の use-attribute-sets 属性から利用される。 use-attribute-sets 属性の値は、空白区切りの属性集合名からなるリストである。 名前はそれぞれ QName として指定され, [2.4 修飾名] に則って展開される。 use-attribute-sets 属性の指定は、属性集合名のリストに含まれる各名前が指す属性集合に含まれる xsl:attribute 要素を, use-attribute-sets 属性を与えた要素の内容の先頭に, 属性集合名のリストと同じ順序で追加することと等価である。 【集合名の順序については言及されているが個々の属性( xsl:attribute )の順序までは言及されていない。おそらく xsl:attribute-set の内容におけるそれらの順序に従うものと思われるが。】 use-attribute-sets 属性を xsl:attribute-set 要素に利用した結果, 属性集合が直接的に, または間接的に自身を参照する場合、エラーとする。 Attribute sets are used by specifying a use-attribute-sets attribute on xsl:element, xsl:copy (see [7.5 Copying]) or xsl:attribute-set elements. The value of the use-attribute-sets attribute is a whitespace-separated list of names of attribute sets. Each name is specified as a QName, which is expanded as described in [2.4 Qualified Names]. Specifying a use-attribute-sets attribute is equivalent to adding xsl:attribute elements for each of the attributes in each of the named attribute sets to the beginning of the content of the element with the use-attribute-sets attribute, in the same order in which the names of the attribute sets are specified in the use-attribute-sets attribute. It is an error if use of use-attribute-sets attributes on xsl:attribute-set elements causes an attribute set to directly or indirectly use itself.

リテラル結果要素においても、 xsl:use-attribute-sets を指定して, 属性集合を利用できる。 xsl:use-attribute-sets 属性の値は、空白区切りの属性集合名のリストである。 xsl:use-attribute-sets 属性は、 xsl:elementuse-attribute-sets 属性を利用する場合と同じ効果を持ち, かつ 次の追加規則を持つ:リテラル結果要素に指定されている属性は、 xsl:attribute 要素により指定されたかのように扱われ, その指定位置が、実際の xsl:attribute 要素の手前, かつ xsl:use-attribute-sets 属性から暗黙的に指定される xsl:attribute 要素の後に来るものとみなす。 従って, リテラル結果要素においては、まず, xsl:use-attribute-sets 属性で与えられる名前付き属性集合に含まれる属性が属性内にリストされている順序で追加され、次に, リテラル結果要素に指定されている属性が追加され、最後に, xsl:attribute 要素に指定されている要素が追加されることになる。 要素に対する属性の追加は、要素に存在する同名の既存の属性を上書きするため, リテラル結果要素の属性で属性集合に含まれる属性を上書きできる。 Attribute sets can also be used by specifying an xsl:use-attribute-sets attribute on a literal result element. The value of the xsl:use-attribute-sets attribute is a whitespace-separated list of names of attribute sets. The xsl:use-attribute-sets attribute has the same effect as the use-attribute-sets attribute on xsl:element with the additional rule that attributes specified on the literal result element itself are treated as if they were specified by xsl:attribute elements before any actual xsl:attribute elements but after any xsl:attribute elements implied by the xsl:use-attribute-sets attribute. Thus, for a literal result element, attributes from attribute sets named in an xsl:use-attribute-sets attribute will be added first, in the order listed in the attribute; next, attributes specified on the literal result element will be added; finally, any attributes specified by xsl:attribute elements will be added. Since adding an attribute to an element replaces any existing attribute of that element with the same name, this means that attributes specified in attribute sets can be overridden by attributes specified on the literal result element itself.

xsl:attribute-set 要素に含まれる各 xsl:attribute 要素内のテンプレートは、属性集合が利用される度にインスタンス化される。 このインスタンス化に用いられる現在のノードと現在のノードリストは、属性集合を利用する要素( use-attribute-sets 属性または xsl:use-attribute-sets 属性を持つ要素)のインスタンス化に利用されるものと同じである。 一方, 変数束縛については、そのスコープを決定するのは xsl:attribute 要素のスタイルシート内における位置であって, 属性集合を利用する要素の位置ではない( [11 変数とパラメタ] を見よ) 。 故に, 参照可能な変数とパラメタは、 トップレベルxsl:variable 要素と xsl:param 要素が宣言したものに限られる。 The template within each xsl:attribute element in an xsl:attribute-set element is instantiated each time the attribute set is used; it is instantiated using the same current node and current node list as is used for instantiating the element bearing the use-attribute-sets or xsl:use-attribute-sets attribute. However, it is the position in the stylesheet of the xsl:attribute element rather than of the element bearing the use-attribute-sets or xsl:use-attribute-sets attribute that determines which variable bindings are visible (see [11 Variables and Parameters]); thus, only variables and parameters declared by top-levelxsl:variable and xsl:param elements are visible.

次の例は、 title-style という名前の属性集合を作成してテンプレートルールから利用している: The following example creates a named attribute set title-style and uses it in a template rule.

<xsl:template match="chapter/heading">
  <fo:block quadding="start" xsl:use-attribute-sets="title-style">
    <xsl:apply-templates/>
  </fo:block>
</xsl:template>

<xsl:attribute-set name="title-style">
  <xsl:attribute name="font-size">12pt</xsl:attribute>
  <xsl:attribute name="font-weight">bold</xsl:attribute>
</xsl:attribute-set>

同一の展開名の属性集合の定義が複数存在した場合、それらの定義は併合される。 インポート優先順位 が他より高い定義からの属性が優先される。 同じ展開名とインポート優先順位を持つ属性集合が2つ存在し, それらが同じ属性を含む場合、より インポート優先順位 が高い, 同じ属性を持つ定義が存在しなければ、エラーとする。 XSLT プロセッサは、エラーを通知してもよい。 エラーを通知しない場合、それらの定義のうち, スタイルシートの最後方のものを選択することにより, エラーから回復しなければならない。 属性集合の中の属性定義の位置は、属性を集合に併合する際にのみ考慮され, 属性集合の利用時には区別されない。 xsl:attribute-set 要素の use-attribute-sets 属性内の各属性集合名に対し、その名前を持つ属性集合の定義はすべて use-attribute-sets 属性が等価な一連の xsl:attribute 子要素に置換される前に併合されなければならない。 xsl:attribute-set 要素の use-attribute-sets 属性はすべて、 xsl:attribute-set 要素が同じ展開名の他の xsl:attribute-set 要素と併合される前に, 等価な一連の xsl:attribute 子要素に置換されなければならない。 同じ展開名の xsl:attribute-set 要素が併合される際は、 use-attribute-sets 属性を置換するすべての xsl:attribute 子要素はスタイルシートの中で子要素として元々指定されていたかの様に扱われるものとする。 Multiple definitions of an attribute set with the same expanded-name are merged. An attribute from a definition that has higher import precedence takes precedence over an attribute from a definition that has lower import precedence. It is an error if there are two attribute sets that have the same expanded-name and equal import precedence and that both contain the same attribute, unless there is a definition of the attribute set with higher import precedence that also contains the attribute. An XSLT processor may signal the error; if it does not signal the error, it must recover by choosing from amongst the definitions that specify the attribute that have the highest import precedence the one that was specified last in the stylesheet. Where the attributes in an attribute set were specified is relevant only in merging the attributes into the attribute set; it makes no difference when the attribute set is used. For each attribute set name occurring in a use-attribute-sets attribute on an xsl:attribute-set element, all definitions of an attribute set with that name must be merged before the use-attribute-sets attribute is replaced by the equivalent sequence of xsl:attribute child elements. Any use-attribute-sets attribute on an xsl:attribute-set element must be replaced by the equivalent sequence of xsl:attribute child elements before that xsl:attribute-set element is merged with other xsl:attribute-set elements with the same expanded-name. When xsl:attribute-set elements with the same expanded-name are merged, any xsl:attribute child elements added to replace a use-attribute-sets attribute are treated exactly as if they had originally been specified in the stylesheet as child elements.

7.2 テキストの生成

テンプレートは、テキストノードも含み得る。 [3.4 空白の削除] に則って空白の削除後にテンプレート内に残った各テキストノードは、結果ツリーの中で同一の文字列を持つテキストノードを生成する。 結果ツリーの中で隣接するテキストノードは自動的に連結されて一つに併合される。 A template can also contain text nodes. Each text node in a template remaining after whitespace has been stripped as specified in [3.4 Whitespace Stripping] will create a text node with the same string-value in the result tree. Adjacent text nodes in the result tree are automatically merged.

テキストはツリーレベルで処理されることに注意。 すなわち, テンプレート内のマークアップ &lt; は、スタイルシートツリー内では, 文字 < を含むテキストノードで表現される。 この文字は、結果ツリー内で文字 < を含むテキストノードを生成する。 結果ツリーが XML 文書として外部に出力されると( [16.4 出力エスケープの無効化] で述べるように出力エスケープが無効化されていない限り)、マークアップ &lt; (または同等の文字参照)で表現される事になる。 Note that text is processed at the tree level. Thus, markup of &lt; in a template will be represented in the stylesheet tree by a text node that includes the character <. This will create a text node in the result tree that contains a < character, which will be represented by the markup &lt; (or an equivalent character reference) when the result tree is externalized as an XML document (unless output escaping is disabled as described in [16.4 Disabling Output Escaping]).

<!-- 分類:instruction -->
<xsl:text
  disable-output-escaping = "yes" | "no">
  <!-- 内容:#PCDATA -->
</xsl:text>

リテラル文字データは xsl:text 要素にくるむこともできる。 このラッピングは、どの空白文字が削除されるかを変更し得るが( [3.4 空白の削除] を見よ), その後の XSLT プロセッサによる文字の扱い方には影響しない。 Literal data characters may also be wrapped in an xsl:text element. This wrapping may change what whitespace characters are stripped (see [3.4 Whitespace Stripping]) but does not affect how the characters are handled by the XSLT processor thereafter.

注記: xml:lang 属性と xml:space 属性は XSLT プロセッサからは特別に扱われない。 特に: NOTE:The xml:lang and xml:space attributes are not treated specially by XSLT. In particular,

  • 結果ツリーに必要になるすべての xml:lang 属性と xml:space 属性に関し、それらの明示的な生成はスタイルシート作成者が責を負う。 it is the responsibility of the stylesheet author explicitly to generate any xml:lang or xml:space attributes that are needed in the result;

  • XSLT 名前空間の要素に xml:lang 属性や xml:space 属性を指定しても、結果に xml:lang属性や xml:space 属性を生じさせることはない。 specifying an xml:lang or xml:space attribute on an element in the XSLT namespace will not cause any xml:lang or xml:space attributes to appear in the result.

7.3 処理命令の生成

<!-- 分類:instruction -->
<xsl:processing-instruction
  name = { ncname }>
  <!-- 内容:template -->
</xsl:processing-instruction>

xsl:processing-instruction 要素のインスタンス化により、処理命令ノードが生成される。 xsl:processing-instruction 要素の内容は、処理命令ノードの文字列値のテンプレートである。 xsl:processing-instruction 要素は、処理命令ノードの名前を指定する必須の name 属性を持つ。 name 属性の値は 属性値テンプレートとして処理される。 The xsl:processing-instruction element is instantiated to create a processing instruction node. The content of the xsl:processing-instruction element is a template for the string-value of the processing instruction node. The xsl:processing-instruction element has a required name attribute that specifies the name of the processing instruction node. The value of the name attribute is interpreted as an attribute value template.

例えば, For example, this

<xsl:processing-instruction name="xml-stylesheet">href="book.css" type="text/css"</xsl:processing-instruction>

は、次の処理命令を生成する。 would create the processing instruction

<?xml-stylesheet href="book.css" type="text/css"?>

name 属性をインスタンス化した結果の文字列が, NCName かつ PITarget にならない場合、エラーとする。 XSLT プロセッサは、エラーを通知してもよい。 エラーを通知しない場合、結果ツリーに処理命令を追加しないことにより, エラーから回復しなければならない。 It is an error if the string that results from instantiating the name attribute is not both an NCName and a PITarget. An XSLT processor may signal the error; if it does not signal the error, it must recover by not adding the processing instruction to the result tree.

注記: これは xsl:processing-instruction を XML 宣言の出力に利用できないことを意味する。 この目的には、代わりに xsl:output 要素( [16 出力] を見よ)を利用すべきである。 NOTE:This means that xsl:processing-instruction cannot be used to output an XML declaration. The xsl:output element should be used instead (see [16 Output]).

xsl:processing-instruction の内容がインスタンス化される際に, テキストノード以外のノードが生成された場合、エラーとする。 XSLT プロセッサは、エラーを通知してもよい。 エラーを通知しない場合、問題が生じたノードとその内容を無視して, エラーから回復しなければならない。 It is an error if instantiating the content of xsl:processing-instruction creates nodes other than text nodes. An XSLT processor may signal the error; if it does not signal the error, it must recover by ignoring the offending nodes together with their content.

xsl:processing-instruction の内容がインスタンス化された結果に文字列 ?> が含まれる場合、エラーとする。 XSLT プロセッサは、エラーを通知してもよい。 エラーを通知しない場合、 > が直後に続く ? すべてに後ろに1個のスペースを挿入して, エラーから回復しなければならない。 It is an error if the result of instantiating the content of the xsl:processing-instruction contains the string ?>. An XSLT processor may signal the error; if it does not signal the error, it must recover by inserting a space after any occurrence of ? that is followed by a >.

7.4 コメントの生成

<!-- 分類:instruction -->
<xsl:comment>
  <!-- 内容:template -->
</xsl:comment>

xsl:comment 要素がインスタンス化されると、結果ツリー内にコメントノードが生成される。 xsl:comment 要素の内容は、コメントノードの文字列値のテンプレートである。 The xsl:comment element is instantiated to create a comment node in the result tree. The content of the xsl:comment element is a template for the string-value of the comment node.

例えば For example, this

<xsl:comment>This file is automatically generated.
Do not edit!</xsl:comment>

は、次のコメントを生成する。 would create the comment

<!--This file is automatically generated.
Do not edit!-->

xsl:comment の内容がインスタンス化される際に, テキストノード以外のノードが生成された場合、エラーとする。 XSLT プロセッサは、エラーを通知してもよい。 エラーを通知しない場合、問題の生じたノードとその内容を無視して, エラーから回復しなければならない。 It is an error if instantiating the content of xsl:comment creates nodes other than text nodes. An XSLT processor may signal the error; if it does not signal the error, it must recover by ignoring the offending nodes together with their content.

xsl:comment の内容がインスタンス化された結果に 文字列 -- が含まれていたり, 末尾に - がある場合、エラーとする。 XSLT プロセッサは、エラーを通知してもよい。 エラーを通知しない場合、連続する - の間すべて, およびコメントの末尾の - の直後にスペースを1個挿入して, エラーから回復しなければならない。 It is an error if the result of instantiating the content of the xsl:comment contains the string -- or ends with -. An XSLT processor may signal the error; if it does not signal the error, it must recover by inserting a space after any occurrence of - that is followed by another - or that ends the comment.

7.5 複製

<!-- 分類:instruction -->
<xsl:copy
  use-attribute-sets = qnames>
  <!-- 内容:template -->
</xsl:copy>

xsl:copy 要素を利用すると、現在のノードを容易に複製できる。 xsl:copy 要素がインスタンス化されると、現在のノードの複製が生成される。 現在のノードの名前空間ノードも自動的に複製されるが, ノードの属性と子は自動的に複製されない。 xsl:copy 要素の内容は、生成されるノードの属性と子を生成するテンプレートである。 この内容は、属性や子を持てるノード型(すなわち、ルートノードと要素ノード)に限ってインスタンス化される。 The xsl:copy element provides an easy way of copying the current node. Instantiating the xsl:copy element creates a copy of the current node. The namespace nodes of the current node are automatically copied as well, but the attributes and children of the node are not automatically copied. The content of the xsl:copy element is a template for the attributes and children of the created node; the content is instantiated only for nodes of types that can have attributes or children (i.e. root nodes and element nodes).

xsl:copy 要素は use-attribute-sets 属性 ( [7.1.4 名前付き属性の集合] を見よ) を持てる。 この属性は、要素ノードを複製するときにのみ利用される。 The xsl:copy element may have a use-attribute-sets attribute (see [7.1.4 Named Attribute Sets]). This is used only when copying element nodes.

結果ツリーのルートノードは暗黙的に生成されるため、ルートノードだけは特別に扱われる。 現在のノードがルートノードだった場合、 xsl:copy はルートノードを生成せず, 単にその内容のテンプレートを利用する。 The root node is treated specially because the root node of the result tree is created implicitly. When the current node is the root node, xsl:copy will not create a root node, but will just use the content template.

例えば、恒等変換は xsl:copy を用いて次のように記述できる: For example, the identity transformation can be written using xsl:copy as follows:

<xsl:template match="@*|node()">
  <xsl:copy>
    <xsl:apply-templates select="@*|node()"/>
  </xsl:copy>
</xsl:template>

現在のノードが属性ノードの場合、現在のノードと同名の属性を生成するために xsl:attribute を利用するとエラーになるような状況においては, xsl:copy の利用もエラーとする( [7.1.3 xsl:attribute による属性の生成] を見よ)。 When the current node is an attribute, then if it would be an error to use xsl:attribute to create an attribute with the same name as the current node, then it is also an error to use xsl:copy (see [7.1.3 Creating Attributes with xsl:attribute]).

現在のノードが名前空間ノードの場合、複製により, 結果ツリーにおいてその親ノードに名前空間ノードが追加される。 その親ノードが要素でなかった場合、エラーとする。 実装は、エラーを通知してもよいし, その名前空間ノードを無視してもよい。 要素に子ノードや属性ノードを追加した後に, 名前空間ノードを追加するのは、エラーとする。 実装は、エラーを通知してもよいし, その名前空間ノードを無視してもよい。 既に同じ名前の名前空間を持っている要素に名前空間ノードを追加した場合、2つの名前空間ノードが同じ 文字列値 でない限り(この場合の重複は無視される), エラーとする。 null 名前空間 URI を持つ要素に null 名の名前空間ノードを追加するのは、エラーとする。 When the current node is a namespace node, then copying it adds a namespace node to the containing node in the result tree. It is an error if this containing node is not an element; implementations may either signal the error or ignore the namespace node. It is an error to add a namespace node to an element after children have been added to it or after attributes have been added to it; implementations may either signal an error or ignore the namespace node. It is an error to add a namespace node to an element if the element already has a namespace node with the same name, unless both namespace nodes have the same string-value, in which case the duplicate is ignored. It is an error to add a namespace node to an element if the namespace node has a null name and the element has a null namespace URI.

次の例に、ソースツリーから結果ツリーへの xml:lang 属性の複製がいかに容易かを示す。 スタイルシートに、次の名前付きテンプレートが定義されているとする: The following example shows how xml:lang attributes can be easily copied through from source to result. If a stylesheet defines the following named template:

<xsl:template name="apply-templates-copy-lang">
 <xsl:for-each select="@xml:lang">
   <xsl:copy/>
 </xsl:for-each>
 <xsl:apply-templates/>
</xsl:template>

このとき, xml:lang 属性の複製は、単に then it can simply do

<xsl:call-template name="apply-templates-copy-lang"/>

と記述すればよく, instead of

<xsl:apply-templates/>

を用いる必要はない。 when it wants to copy the xml:lang attribute.

7.6 テキストの動的生成

テンプレート内では, xsl:value-of 要素を、ソースツリーからのテキストの取得や変数の値の挿入など, 演算によるテキスト生成に利用できる。 この処理は xsl:value-of 要素の select 属性の値に指定された を用いて行われる。 式は、リテラル結果要素の属性値においても波括弧( {} )に括って利用できる。 Within a template, the xsl:value-of element can be used to compute generated text, for example by extracting text from the source tree or by inserting the value of a variable. The xsl:value-of element does this with an expression that is specified as the value of the select attribute. Expressions can also be used inside attribute values of literal result elements by enclosing the expression in curly braces ({}).

7.6.1 xsl:value-of によるテキストの生成

<!-- 分類:instruction -->
<xsl:value-of
  select = string-expression 
  disable-output-escaping = "yes" | "no" />

xsl:value-of 要素がインスタンス化されると、結果ツリー内にテキストノードが生成される。 必須の select 属性の値は である。 この式が評価されると、 string 関数が呼び出されたかのように, 結果のオブジェクトが文字列に変換される。 この文字列が、生成されるテキストノードの文字列値を与える。 文字列が空になった場合、テキストノードは生成されない。 生成されるテキストノードは、隣接するすべてのテキストノードと連結され一つに併合される。 The xsl:value-of element is instantiated to create a text node in the result tree. The required select attribute is an expression; this expression is evaluated and the resulting object is converted to a string as if by a call to the string function. The string specifies the string-value of the created text node. If the string is empty, no text node will be created. The created text node will be merged with any adjacent text nodes.

xsl:copy-of 要素を利用して、ノード集合を文字列に変換することなく, 結果ツリーに複製できる。 [11.3 xsl:copy-of における変数とパラメタの値の利用 ] を見よ。 The xsl:copy-of element can be used to copy a node-set over to the result tree without converting it to a string. See [11.3 Using Values of Variables and Parameters with xsl:copy-of].

下の例は given-name 属性と family-name 属性を持つ person 要素から HTML の段落を生成する。 段落には、現在のノードの given-name 属性の値, 1個のスペース, 現在のノードの family-name 属性の値 が、この順で挿入されることになる。 For example, the following creates an HTML paragraph from a person element with given-name and family-name attributes. The paragraph will contain the value of the given-name attribute of the current node followed by a space and the value of the family-name attribute of the current node.

<xsl:template match="person">
  <p>
   <xsl:value-of select="@given-name"/>
   <xsl:text> </xsl:text>
   <xsl:value-of select="@family-name"/>
  </p>
</xsl:template>

次の例は、 given-name 要素と family-name 要素を子に持つ person 要素から, HTML の段落を生成する。 段落には、現在のノードの最初の given-name 子要素の文字列値, 1個のスペース, 現在のノードの最初の family-name 子要素の文字列値 が、この順で挿入されることになる。 For another example, the following creates an HTML paragraph from a person element with given-name and family-name children elements. The paragraph will contain the string-value of the first given-name child element of the current node followed by a space and the string-value of the first family-name child element of the current node.

<xsl:template match="person">
  <p>
   <xsl:value-of select="given-name"/>
   <xsl:text> </xsl:text>
   <xsl:value-of select="family-name"/>
  </p>
</xsl:template>

次の例では、各 procedure 要素の最初に, procedure のセキュリティレベルを含む段落を配置させる。 ここでは, 各「手続き」( procedure )に適用されるセキュリティレベルが procedure 要素またはその先祖要素の security 属性から決定されていて、 security 属性を持つ要素が複数存在する場合のセキュリティレベルは procedure 要素から最も近い要素から決定されるものと見なされている。 The following precedes each procedure element with a paragraph containing the security level of the procedure. It assumes that the security level that applies to a procedure is determined by a security attribute on the procedure element or on an ancestor element of the procedure. It also assumes that if more than one such element has a security attribute then the security level is determined by the element that is closest to the procedure.

<xsl:template match="procedure">
  <fo:block>
    <xsl:value-of select="ancestor-or-self::*[@security][1]/@security"/>
  </fo:block>
  <xsl:apply-templates/>
</xsl:template>

7.6.2 属性値テンプレート

リテラル結果要素の属性など, 属性値テンプレート として処理される属性値においては、波括弧( {} )で括られた を利用できる。 属性値テンプレートは、式とそれを括る波括弧を式の評価結果に置換し, 結果のオブジェクトを string 関数が呼び出されたかのように文字列に変換することにより, インスタンス化される。 XSLT スタイルシートの属性においては、属性値を属性値テンプレートとして処理するものと明示的に指定される属性を除き, 属性値内の波括弧は認識されない。 要素の構文要約においては、このような属性の値は波括弧で括られている。 In an attribute value that is interpreted as an attribute value template, such as an attribute of a literal result element, an expression can be used by surrounding the expression with curly braces ({}). The attribute value template is instantiated by replacing the expression together with surrounding curly braces by the result of evaluating the expression and converting the resulting object to a string as if by a call to the string function. Curly braces are not recognized in an attribute value in an XSLT stylesheet unless the attribute is specifically stated to be one that is interpreted as an attribute value template; in an element syntax summary, the value of such attributes is surrounded by curly braces.

注記: すべての属性が属性値テンプレートに解釈されるわけではない。 値が式またはパターンの属性, トップレベル 要素の属性, 名前が付けられた XSLT オブジェクトを参照する属性は、属性値テンプレートに解釈されない。 加えて、 xmlns 属性も属性値テンプレートには解釈されない。 このような処理は XML 名前空間勧告に適合しないからである。 NOTE:Not all attributes are interpreted as attribute value templates. Attributes whose value is an expression or pattern, attributes of top-level elements and attributes that refer to named XSLT objects are not interpreted as attribute value templates. In addition, xmlns attributes are not interpreted as attribute value templates; it would not be conformant with the XML Namespaces Recommendation to do this.

次の例は img 結果要素を、ソース内の photograph 要素から生成する。 img 要素の src 属性の値は、 image-dir 変数の値と photograph 要素の href 子要素の文字列値から算出される。 img 要素の width 属性の値は photograph 要素の size 子要素の width 属性の値から算出される。 The following example creates an img result element from a photograph element in the source; the value of the src attribute of the img element is computed from the value of the image-dir variable and the string-value of the href child of the photograph element; the value of the width attribute of the img element is computed from the value of the width attribute of the size child of the photograph element:

<xsl:variable name="image-dir">/images</xsl:variable>

<xsl:template match="photograph">
<img src="{$image-dir}/{href}" width="{size/@width}"/>
</xsl:template>

次のソース With this source

<photograph>
  <href>headquarters.jpg</href>
  <size width="300"/>
</photograph>

から生成される結果は次のようになる: the result would be

<img src="/images/headquarters.jpg" width="300"/>

属性値テンプレートがインスタンス化される際は, 式の外側の右または左2重波括弧は、1重波括弧に置換される。 式の外側の属性値テンプレートでは, 右波括弧の後ろに2つ目の右波括弧がない場合、エラーとする。 式の Literal 内の右波括弧は、式を終了する波括弧とは認識されない。 When an attribute value template is instantiated, a double left or right curly brace outside an expression will be replaced by a single curly brace. It is an error if a right curly brace occurs in an attribute value template outside an expression without being followed by a second right curly brace. A right curly brace inside a Literal in an expression is not recognized as terminating the expression.

波括弧が式内部で再帰的に認識されることはない。 例えば: Curly braces are not recognized recursively inside expressions. For example:

<a href="#{id({@ref})/title}">

は認められない。 代わりに、単に次のように表記する: is not allowed. Instead, use simply:

<a href="#{id(@ref)/title}">

7.7 番号付け

<!-- 分類:instruction -->
<xsl:number
  level = "single" | "multiple" | "any"
  count = pattern 
  from = pattern 
  value = number-expression 
  format = { string }
  lang = { nmtoken }
  letter-value = { "alphabetic" | "traditional" }
  grouping-separator = { char }
  grouping-size = { number } />

xsl:number 要素は、結果ツリーにフォーマット化した数値を挿入するために利用される。 挿入する数値は、式で指定してもよい。 value 属性の値は を含む。 この式が評価されると、結果のオブジェクトは number 関数を呼び出したかのように数値に変換される。 数値が NaN, infinite になった場合, または 0.5 より小さくなった場合、エラーとする。 XSLT プロセッサは、エラーを通知してもよい。 エラーを通知しない場合、数値を string 関数を呼び出したかのように文字列に変換して, エラーから回復しなければならない。 他の場合、 この数値は整数に丸められ, [7.7.1 数値から文字列への変換属性] で述べる属性により文字列に変換される。 この処理において、これらの属性値はそれぞれ 属性値テンプレート として処理される。 変換後の結果の文字列が結果ツリーに挿入される。 次の例は、ソートされたリストに番号付けを行う。 The xsl:number element is used to insert a formatted number into the result tree. The number to be inserted may be specified by an expression. The value attribute contains an expression. The expression is evaluated and the resulting object is converted to a number as if by a call to the number function. It is an error if the number is NaN, infinite or less than 0.5; an XSLT processor may signal the error; if it does not signal the error, it must recover by converting the number to a string as if by a call to the string function and inserting the resulting string into the result tree. Otherwise, The number is rounded to an integer and then converted to a string using the attributes specified in [7.7.1 Number to String Conversion Attributes]; in this context, the value of each of these attributes is interpreted as an attribute value template. After conversion, the resulting string is inserted in the result tree. For example, the following example numbers a sorted list:

<xsl:template match="items">
  <xsl:for-each select="item">
    <xsl:sort select="."/>
    <p>
      <xsl:number value="position()" format="1. "/>
      <xsl:value-of select="."/>
    </p>
  </xsl:for-each>
</xsl:template>

value 属性が指定されていない場合、 xsl:number 要素はソースツリー内の現在のノード位置に基づいて数値を挿入する。 次に挙げる属性は、現在のノードに対する番号付けの方法を制御する。 If no value attribute is specified, then the xsl:number element inserts a number based on the position of the current node in the source tree. The following attributes control how the current node is to be numbered:

加えて, 数値から文字列への変換には、 value 属性が指定された場合と同様に [7.7.1 数値から文字列への変換属性] で述べる属性が利用される。 In addition, the attributes specified in [7.7.1 Number to String Conversion Attributes] are used for number to string conversion, as in the case when the value attribute is specified.

xsl:number 要素は、まず, level 属性, count 属性, from 属性から正の整数のリストを構築する。 The xsl:number element first constructs a list of positive integers using the level, count and from attributes:

次に、上で構築した数のリストを [7.7.1 数値から文字列への変換属性] で述べる属性を用いて文字列に変換する。 この処理においては, これらの属性値は、それぞれ 属性値テンプレート として処理される。 変換後の結果の文字列が結果ツリーに挿入される。 The list of numbers is then converted into a string using the attributes specified in [7.7.1 Number to String Conversion Attributes]; in this context, the value of each of these attributes is interpreted as an attribute value template. After conversion, the resulting string is inserted in the result tree.

次の例は、順序付きリスト( ol )の項目( item )に対する番号付けを行なう。 The following would number the items in an ordered list:

<xsl:template match="ol/item">
  <fo:block>
    <xsl:number/><xsl:text>. </xsl:text><xsl:apply-templates/>
  </fo:block>
<xsl:template>

次の2つのルールは、 title 要素に番号付けを行う。 この例では、一連の chapter と後続の appendix を含む文書が意図されている。 これらの chapterappendix のいずれも section を含み, sectionsubsection を含んでいるとする。 chapter は 1, 2, 3, ... , appendix は A, B, C, ... , chapter の中の section は 1.1, 1.2, 1.3, ..., appendix の中の section は A.1, A.2, A.3, ... のような形に番号が振られる。 The following two rules would number title elements. This is intended for a document that contains a sequence of chapters followed by a sequence of appendices, where both chapters and appendices contain sections, which in turn contain subsections. Chapters are numbered 1, 2, 3; appendices are numbered A, B, C; sections in chapters are numbered 1.1, 1.2, 1.3; sections in appendices are numbered A.1, A.2, A.3.

<xsl:template match="title">
  <fo:block>
     <xsl:number level="multiple"
                 count="chapter|section|subsection"
                 format="1.1 "/>
     <xsl:apply-templates/>
  </fo:block>
</xsl:template>

<xsl:template match="appendix//title" priority="1">
  <fo:block>
     <xsl:number level="multiple"
                 count="appendix|section|subsection"
                 format="A.1 "/>
     <xsl:apply-templates/>
  </fo:block>
</xsl:template>

次の例は、 chapter の中の note に番号付けを行う: The following example numbers notes sequentially within a chapter:

<xsl:template match="note">
  <fo:block>
     <xsl:number level="any" from="chapter" format="(1) "/>
     <xsl:apply-templates/>
  </fo:block>
</xsl:template>

次の例では、 HTML の H4 要素に対し、3部分からなるラベルで番号付けを行う: The following example would number H4 elements in HTML with a three-part label:

<xsl:template match="H4">
 <fo:block>
   <xsl:number level="any" from="H1" count="H2"/>
   <xsl:text>.</xsl:text>
   <xsl:number level="any" from="H2" count="H3"/>
   <xsl:text>.</xsl:text>
   <xsl:number level="any" from="H3" count="H4"/>
   <xsl:text> </xsl:text>
   <xsl:apply-templates/>
 </fo:block>
</xsl:template>

7.7.1 数値から文字列への変換の属性

以下の属性は、数値のリストを文字列へ変換する際の制御に利用される。 数値は正整数とする。 属性はすべてオプションである。 The following attributes are used to control conversion of a list of numbers into a string. The numbers are integers greater than 0. The attributes are all optional.

主要な属性は format である。 format 属性の既定値は 1である。 format 属性は、トークンのシーケンスに分割される。 各トークンは、英数文字の最長シーケンスまたは非英数文字の最長シーケンスである。 英数文字とは, Nd, Nl, No, Lu, Ll, Lt, Lm, Lo いずれかの Unicode 分類に入る文字を意味する。 英数文字トークン(フォーマットトークン)は、リスト内の各数値に用いるフォーマットを指定する。 最初のトークンが非英数文字のトークンであれば、構築される文字列はそのトークンから始まり, 最後のトークンが非英数文字のトークンであれば、構築される文字列はそのトークンで終わることになる。 2つのフォーマットトークンの間に現れる非英数文字のトークンは、リスト内の数値を結合する区切りトークンである。 n 番目のフォーマットトークンは、リスト内の n 番目の数値のフォーマットに利用される。 フォーマットトークンより数値の個数が多い場合、最後のフォーマットトークンが残りの数値のフォーマットに利用される。 フォーマットトークンが存在しない場合、フォーマットトークン 1 がすべての数値のフォーマットに利用される。 フォーマットトークンは、数値の 1 の表現に用いられる文字列を指定する。 2番目以降の各数値は、その数値のフォーマットに利用するフォーマットトークンの前にある区切りトークンにより, 手前の数値と区切られる。 区切りトークンが存在しない場合、文字 . (ピリオド)が区切りに利用される。 The main attribute is format. The default value for the format attribute is 1. The format attribute is split into a sequence of tokens where each token is a maximal sequence of alphanumeric characters or a maximal sequence of non-alphanumeric characters. Alphanumeric means any character that has a Unicode category of Nd, Nl, No, Lu, Ll, Lt, Lm or Lo. The alphanumeric tokens (format tokens) specify the format to be used for each number in the list. If the first token is a non-alphanumeric token, then the constructed string will start with that token; if the last token is non-alphanumeric token, then the constructed string will end with that token. Non-alphanumeric tokens that occur between two format tokens are separator tokens that are used to join numbers in the list. The nth format token will be used to format the nth number in the list. If there are more numbers than format tokens, then the last format token will be used to format remaining numbers. If there are no format tokens, then a format token of 1 is used to format all numbers. The format token specifies the string to be used to represent the number 1. Each number after the first will be separated from the preceding number by the separator token preceding the format token used to format that number, or, if there are no separator tokens, then by . (a period character).

フォーマットトークンは、 HTML 4.0 の OL 要素の type 属性で利用できる値のスーパーセットであり, 次のように解釈される: Format tokens are a superset of the allowed values for the type attribute for the OL element in HTML 4.0 and are interpreted as follows:

  • 最後の文字が( Unicode の文字プロパティデータベースで規定された)十進数の 1 で終わり, その前の文字の Unicode 値が最後の文字の Unicode 値より 1 小さくなるような, すべてのトークンは、各数が少なくともフォーマットトークンの長さ以上になる十進数表現を生成する。 従って、フォーマットトークン 1 はフォーマット列 1 2 ... 10 11 12 ... を生成し, フォーマットトークン 01 はフォーマット列 01 02 ... 09 10 11 12 ... 99 100 101 を生成する。 Any token where the last character has a decimal digit value of 1 (as specified in the Unicode character property database), and the Unicode value of preceding characters is one less than the Unicode value of the last character generates a decimal representation of the number where each number is at least as long as the format token. Thus, a format token 1 generates the sequence 1 2 ... 10 11 12 ..., and a format token 01 generates the sequence 01 02 ... 09 10 11 12 ... 99 100 101.

  • フォーマットトークン A はフォーマット列 A B C ... Z AA AB AC... を生成する。 A format token A generates the sequence A B C ... Z AA AB AC....

  • フォーマットトークン a はフォーマット列 a b c ... z aa ab ac... を生成する。 A format token a generates the sequence a b c ... z aa ab ac....

  • フォーマットトークン i はフォーマット列 i ii iii iv v vi vii viii ix x ... を生成する。 A format token i generates the sequence i ii iii iv v vi vii viii ix x ....

  • フォーマットトークン I はフォーマット列 I II III IV V VI VII VIII IX X ... を生成する。 A format token I generates the sequence I II III IV V VI VII VIII IX X ....

  • その他のフォーマットトークンは、そのトークンから始まる番号付け規則を指示する。 実装は、あるトークンで始まる番号付け規則をサポートしていない場合、フォーマットトークン 1 を利用しなければならない。 Any other format token indicates a numbering sequence that starts with that token. If an implementation does not support a numbering sequence that starts with that token, it must use a format token of 1.

アルファベット順に番号付けを行う際には、 lang 属性がどの言語のアルファベットを利用するかを指定する。 この属性は、xml:lang [XML] と同じ範囲の値をとる。 lang が指定されていない場合、システム環境から言語を決定すべきである。 実装側は、番号付けをサポートする言語の種類を文書化しておくべきである。 When numbering with an alphabetic sequence, the lang attribute specifies which language's alphabet is to be used; it has the same range of values as xml:lang[XML]; if no lang value is specified, the language should be determined from the system environment. Implementers should document for which languages they support numbering.

注記: 実装側は、特定の言語に対する番号付けのふるまいを仮定せず, サポートしようとする言語を正確に調べるべきである。 多くの言語では、番号付けの慣行が英語とは大きく異なる。 NOTE:Implementers should not make any assumptions about how numbering works in particular languages and should properly research the languages that they wish to support. The numbering conventions of many languages are very different from English.

letter-value 属性は、文字を用いる番号付けに生じる多義性を排除する。 多くの言語では、一般的に利用されている文字による番号付けに2種類の方法が存在する。 一つは数値をアルファベット順に文字に割り振る方法であり、もう一つはその言語で伝統的に用いられる別の作法になる。 英語の場合、これらの作法はフォーマットトークン ai で指定される番号付け規則に対応する。 一部の言語では、異なるフォーマット列の最初の文字が同じため, フォーマットトークンだけではあいまいになる。 値に alphabetic を指定した場合はアルファベット順が適用され、 traditional を指定した場合はもう一方の規則が適用される。 letter-value 属性が指定されていない場合、あいまいさの解決は実装依存になる。 The letter-value attribute disambiguates between numbering sequences that use letters. In many languages there are two commonly used numbering sequences that use letters. One numbering sequence assigns numeric values to letters in alphabetic sequence, and the other assigns numeric values to each letter in some other manner traditional in that language. In English, these would correspond to the numbering sequences specified by the format tokens a and i. In some languages, the first member of each sequence is the same, and so the format token alone would be ambiguous. A value of alphabetic specifies the alphabetic sequence; a value of traditional specifies the other sequence. If the letter-value attribute is not specified, then it is implementation-dependent how any ambiguity is resolved.

注記: 規定に適合する2つの XSLT プロセッサによる数値の文字列への変換結果が、完全に一致しない場合がある。 XSLT プロセッサには一部の言語をサポートしないものもあり得る。 さらに, xsl:number の属性による指定では不可能な特定の言語においては、変換の実行に様々な方法があり得る。 将来版の XSLT には、このようなバリエーションを制御する属性の追加が検討されている。 実装は、この目的で実装固有の名前空間の属性を xsl:number に用いてもよい。 NOTE:It is possible for two conforming XSLT processors not to convert a number to exactly the same string. Some XSLT processors may not support some languages. Furthermore, there may be variations possible in the way conversions are performed for any particular language that are not specifiable by the attributes on xsl:number. Future versions of XSLT may provide additional attributes to provide control over these variations. Implementations may also use implementation-specific namespaced attributes on xsl:number for this.

grouping-separator 属性は、十進記数法におけるグループ分け(例えば 1000 単位)の区切り記号を与える。 grouping-size 属性で, そのグループ化のサイズ(通常は 3 )を指定する。 例えば grouping-separator=",", grouping-size="3" とした場合、 1,000,000 の形式の数値が生成される。 grouping-separator 属性と grouping-size 属性の一方のみしか指定されていない場合、その指定は無視される。 The grouping-separator attribute gives the separator used as a grouping (e.g. thousands) separator in decimal numbering sequences, and the optional grouping-size specifies the size (normally 3) of the grouping. For example, grouping-separator="," and grouping-size="3" would produce numbers of the form 1,000,000. If only one of the grouping-separator and grouping-size attributes is specified, then it is ignored.

以下に, 変換指定の例を示す。 Here are some examples of conversion specifications:

  • format="&#x30A2;" は、五十音順のカタカナによる番号付けを指定する。 format="&#x30A2;" specifies Katakana numbering

  • format="&#x30A4;" は、「いろは」順のカタカナによる番号付けを指定する。 format="&#x30A4;" specifies Katakana numbering in the "iroha" order

  • format="&#x0E51;" は、タイ数字による番号付けを指定する。 format="&#x0E51;" specifies numbering with Thai digits

  • format="&#x05D0;" letter-value="traditional" は、ヘブライ語の「伝統的」番号付けを指定する。 format="&#x05D0;" letter-value="traditional" specifies "traditional" Hebrew numbering

  • format="&#x10D0;" letter-value="traditional" は、グルジア語による番号付けを指定する。 format="&#x10D0;" letter-value="traditional" specifies Georgian numbering

  • format="&#x03B1;" letter-value="traditional" は、「古典」ギリシア語による番号付けを指定する。 format="&#x03B1;" letter-value="traditional" specifies "classical" Greek numbering

  • format="&#x0430;" letter-value="traditional" は、古スラヴ語による番号付けを指定する。 format="&#x0430;" letter-value="traditional" specifies Old Slavic numbering

8 繰り返し

<!-- 分類:instruction -->
<xsl:for-each
  select = node-set-expression>
  <!-- 内容:(xsl:sort*, template) -->
</xsl:for-each>

結果が規則的な構造を持つことが明らかな場合、選択したノードに直接テンプレートを指定できる機能が有用になる。 xsl:for-each 命令は1個のテンプレートを含む。 このテンプレートは、 select 属性に指定された によって選択される各ノードごとにインスタンス化される。 select 属性の指定は必須である。 式の評価結果はノード集合でなければならない。 このテンプレートは、選択したノードを 現在のノード に利用し, 選択した全ノードのリストを 現在のノードリスト に利用してインスタンス化される。 ノードは、ソートの指定がなければ( [10 ソート] を見よ), 文書順に処理される。 When the result has a known regular structure, it is useful to be able to specify directly the template for selected nodes. The xsl:for-each instruction contains a template, which is instantiated for each node selected by the expression specified by the select attribute. The select attribute is required. The expression must evaluate to a node-set. The template is instantiated with the selected node as the current node, and with a list of all of the selected nodes as the current node list. The nodes are processed in document order, unless a sorting specification is present (see [10 Sorting]).

例えば, 次の構造の XML 文書: For example, given an XML document with this structure

<customers>
  <customer>
    <name>...</name>
    <order>...</order>
    <order>...</order>
  </customer>
  <customer>
    <name>...</name>
    <order>...</order>
    <order>...</order>
  </customer>
</customers>

に対し、次のものは, 各 customer 要素に対応する行を持つテーブルを含む HTML 文書を生成する。 the following would create an HTML document containing a table with a row for each customer element

<xsl:template match="/">
  <html>
    <head>
      <title>Customers</title>
    </head>
    <body>
      <table>
        <tbody>
          <xsl:for-each select="customers/customer">
            <tr>
              <th>
                <xsl:apply-templates select="name"/>
              </th>
              <xsl:for-each select="order">
                <td>
                  <xsl:apply-templates/>
                </td>
              </xsl:for-each>
            </tr>
          </xsl:for-each>
        </tbody>
      </table>
    </body>
  </html>
</xsl:template>

9 条件処理

XSLT には、テンプレートにおける条件処理をサポートする2つの命令: xsl:if および xsl:choose がある。 xsl:if 命令は、単純な if-then による条件処理を行い, xsl:choose 命令は、選択肢がいくつかある中での選択処理をサポートする。 There are two instructions in XSLT that support conditional processing in a template: xsl:if and xsl:choose. The xsl:if instruction provides simple if-then conditionality; the xsl:choose instruction supports selection of one choice when there are several possibilities.

9.1 xsl:if による条件処理

<!-- 分類:instruction -->
<xsl:if
  test = boolean-expression>
  <!-- 内容:template -->
</xsl:if>

xsl:if 要素は を指定する test 属性を持つ。 要素の内容はテンプレートである。 式が評価されると、結果のオブジェクトは boolean 関数を呼び出したかのようにブール型に変換され, 結果が真の場合、内容のテンプレートがインスタンス化され, そうでなければ何も生成されない。 次の例は namelist に含まれる name をコンマ区切りのリストにフォーマットする: The xsl:if element has a test attribute, which specifies an expression. The content is a template. The expression is evaluated and the resulting object is converted to a boolean as if by a call to the boolean function. If the result is true, then the content template is instantiated; otherwise, nothing is created. In the following example, the names in a group of names are formatted as a comma separated list:

<xsl:template match="namelist/name">
  <xsl:apply-templates/>
  <xsl:if test="not(position()=last())">, </xsl:if>
</xsl:template>

次の例は、表の行を1行おきに yellow にする: The following colors every other table row yellow:

<xsl:template match="item">
  <tr>
    <xsl:if test="position() mod 2 = 0">
       <xsl:attribute name="bgcolor">yellow</xsl:attribute>
    </xsl:if>
    <xsl:apply-templates/>
  </tr>
</xsl:template>

9.2 xsl:choose による条件処理

<!-- 分類:instruction -->
<xsl:choose>
  <!-- 内容:(xsl:when+, xsl:otherwise?) -->
</xsl:choose>
<xsl:when
  test = boolean-expression>
  <!-- 内容:template -->
</xsl:when>
<xsl:otherwise>
  <!-- 内容:template -->
</xsl:otherwise>

xsl:choose 要素は、いくつかの選択肢の中から一つを選択する。 この要素の内容は、一連の xsl:when 要素と, 後続するオプションの xsl:otherwise 要素からなる。 各 xsl:when 要素は を指定する1個の属性 test を持つ。 xsl:when 要素と xsl:otherwise 要素の内容は、テンプレートである。 xsl:choose 要素の処理においては、各 xsl:when 要素が順番にテストされる。 各テストでは、 test に与えた式が評価され, その結果のオブジェクトが boolean 関数を呼び出しかのようにブール型に変換される。 テスト結果が真になる xsl:when 要素のうち、最初の要素の内容のみがインスタンス化される。 テスト結果が真になる xsl:when が存在しない場合、 xsl:otherwise 要素の内容がインスタンス化される。 テスト結果が真の xsl:when 要素が存在せず, xsl:otherwise 要素も存在しない場合、何も生成されない。 The xsl:choose element selects one among a number of possible alternatives. It consists of a sequence of xsl:when elements followed by an optional xsl:otherwise element. Each xsl:when element has a single attribute, test, which specifies an expression. The content of the xsl:when and xsl:otherwise elements is a template. When an xsl:choose element is processed, each of the xsl:when elements is tested in turn, by evaluating the expression and converting the resulting object to a boolean as if by a call to the boolean function. The content of the first, and only the first, xsl:when element whose test is true is instantiated. If no xsl:when is true, the content of the xsl:otherwise element is instantiated. If no xsl:when element is true, and no xsl:otherwise element is present, nothing is created.

次の例は、順序付きリスト( orderedlist )の各項目( item )に対し、リストの入れ子の深さに応じて, アラビア数字, アルファベット, ローマ数字による番号を振る。 The following example enumerates items in an ordered list using arabic numerals, letters, or roman numerals depending on the depth to which the ordered lists are nested.

<xsl:template match="orderedlist/listitem">
  <fo:list-item indent-start='2pi'>
    <fo:list-item-label>
      <xsl:variable name="level"
                    select="count(ancestor::orderedlist) mod 3"/>
      <xsl:choose>
        <xsl:when test='$level=1'>
          <xsl:number format="i"/>
        </xsl:when>
        <xsl:when test='$level=2'>
          <xsl:number format="a"/>
        </xsl:when>
        <xsl:otherwise>
          <xsl:number format="1"/>
        </xsl:otherwise>
      </xsl:choose>
      <xsl:text>. </xsl:text>
    </fo:list-item-label>
    <fo:list-item-body>
      <xsl:apply-templates/>
    </fo:list-item-body>
  </fo:list-item>
</xsl:template>

10 ソート処理

<xsl:sort
  select = string-expression 
  lang = { nmtoken }
  data-type = { "text" | "number" | qname-but-not-ncname }
  order = { "ascending" | "descending" }
  case-order = { "upper-first" | "lower-first" } />

ソートを指定するには、 xsl:apply-templates 要素または xsl:for-each 要素の子に, xsl:sort 要素を与える。 1番目の xsl:sort 子要素が1次ソートキーを指定し, 2番目の xsl:sort 子要素が2次ソートキーを指定し, 以下同様である。 xsl:apply-templates 要素または xsl:for-each 要素に1個以上の xsl:sort 子要素が含まれている場合、選択されたノードは文書順ではなく, 指定されたソートキーに従ったソート処理が施された後の順序で処理される。 xsl:for-each 要素で利用する場合、 xsl:sort 要素は先頭に置かれなければならない。 テンプレートが xsl:sort 要素を子に含む xsl:apply-templates または xsl:for-each によりインスタンス化される際の 現在のノードリスト は、処理対象ノードすべてをソート後の順序に整列させたリストになる。 Sorting is specified by adding xsl:sort elements as children of an xsl:apply-templates or xsl:for-each element. The first xsl:sort child specifies the primary sort key, the second xsl:sort child specifies the secondary sort key and so on. When an xsl:apply-templates or xsl:for-each element has one or more xsl:sort children, then instead of processing the selected nodes in document order, it sorts the nodes according to the specified sort keys and then processes them in sorted order. When used in xsl:for-each, xsl:sort elements must occur first. When a template is instantiated by xsl:apply-templates and xsl:for-each, the current node list list consists of the complete list of nodes being processed in sorted order.

xsl:sort を値にとる select 属性を持つ。 処理される各ノードに対し、そのノードを現在のノードに, 処理されるノードの文書順の完全なリストを現在のノードリストにして、この式が評価される。 結果のオブジェクトは string 関数を呼び出したかのように文字列に変換され, この文字列がノードのソートキーに利用される。 select 属性の既定値は . であり, その値の場合、現在のノードの文字列値がソートキーに利用される。 xsl:sort has a select attribute whose value is an expression. For each node to be processed, the expression is evaluated with that node as the current node and with the complete list of nodes being processed in unsorted document order as the current node list. The resulting object is converted to a string as if by a call to the string function; this string is used as the sort key for that node. The default value of the select attribute is ., which will cause the string-value of the current node to be used as the sort key.

この文字列が、ノードのソートキーの役割を果たす。 以下に挙げる xsl:sort の属性はオプションであり, ソートキーのリストをどのようにソートするかを制御する。 これらの属性の値はすべて 属性値テンプレート として処理される。 This string serves as a sort key for the node. The following optional attributes on xsl:sort control how the list of sort keys are sorted; the values of all of these attributes are interpreted as attribute value templates.

注記: 規定に適合する2つの XSLT プロセッサによるソート結果が完全に一致しない場合もある。 更に、どの言語にも xsl:sort の属性では指定できないソートのバリエーションが存在し得る。 例えば日本語の場合、ひらがなとカタカナのどちらを優先するかなど。 将来版の XSLT には、このようなバリエーションを制御する属性の追加が検討されている。 実装は、この目的で実装固有の名前空間の属性を xsl:sort に用いてもよい。 NOTE:It is possible for two conforming XSLT processors not to sort exactly the same. Some XSLT processors may not support some languages. Furthermore, there may be variations possible in the sorting of any particular language that are not specified by the attributes on xsl:sort, for example, whether Hiragana or Katakana is sorted first in Japanese. Future versions of XSLT may provide additional attributes to provide control over these variations. Implementations may also use implementation-specific namespaced attributes on xsl:sort for this.

注記: 実装者は、多言語対応のソート処理に関し [UNICODE TR10] を参考にすることが推奨される。 NOTE:It is recommended that implementers consult [UNICODE TR10] for information on internationalized sorting.

ソートは安定ソートでなければならない。 すなわち、ソート順で等しいソートキーを持つ複数のノードはソート後においても文書順に並んでいなければならない。 The sort must be stable: in the sorted list of nodes, any sub list that has sort keys that all compare equal must be in document order.

次のような形の employee (従業員)のデータベースを例にとる: For example, suppose an employee database has the form

<employees>
  <employee>
    <name>
      <given>James</given>
      <family>Clark</family>
    </name>
    ...
  </employee>
</employees>

このとき, 従業員の name によるソートのリストは、次のようにして生成できる: Then a list of employees sorted by name could be generated using:

<xsl:template match="employees">
  <ul>
    <xsl:apply-templates select="employee">
      <xsl:sort select="name/family"/>
      <xsl:sort select="name/given"/>
    </xsl:apply-templates>
  </ul>
</xsl:template>

<xsl:template match="employee">
  <li>
    <xsl:value-of select="name/given"/>
    <xsl:text> </xsl:text>
    <xsl:value-of select="name/family"/>
  </li>
</xsl:template>

11 変数とパラメタ

<!-- 分類:top-level-element -->
<!-- 分類:instruction -->
<xsl:variable
  name = qname 
  select = expression>
  <!-- 内容:template -->
</xsl:variable>
<!-- 分類:top-level-element -->
<xsl:param
  name = qname 
  select = expression>
  <!-- 内容:template -->
</xsl:param>

変数とは、値に結びつけられ得る名前である。 変数が束縛される値(変数の)は、式の返せる型であれば, どのような型のオブジェクトでもよい。 変数の束縛に利用できる要素には、xsl:variablexsl:param の2つがある。 xsl:param 変数に指定される値は、束縛の既定値に限るという点が両者の違いになる。 xsl:param 要素を含むテンプレートやスタイルシートは、呼び出される際に既定値になり代わって利用されるパラメタを渡し得る。 A variable is a name that may be bound to a value. The value to which a variable is bound (the value of the variable) can be an object of any of the types that can be returned by expressions. There are two elements that can be used to bind variables: xsl:variable and xsl:param. The difference is that the value specified on the xsl:param variable is only a default value for the binding; when the template or stylesheet within which the xsl:param element occurs is invoked, parameters may be passed that are used in place of the default values.

xsl:variablexsl:param のいずれも name 属性は必須である。 この属性は変数の名前を指定する。 name 属性の値は QName であり、この値は [2.4 修飾名] に則って展開される。 Both xsl:variable and xsl:param have a required name attribute, which specifies the name of the variable. The value of the name attribute is a QName, which is expanded as described in [2.4 Qualified Names].

これらの変数束縛要素( Variable-binding element )の利用においては、束縛が見える(スコープに入る)スタイルシートツリーの範囲は限定される。 ある式から見える変数束縛の集合は、スタイルシートにその式が現れる場所から見える束縛からなる。 For any use of these variable-binding elements, there is a region of the stylesheet tree within which the binding is visible ; within this region, any binding of the variable that was visible on the variable-binding element itself is hidden. Thus, only the innermost binding of a variable is visible. The set of variable bindings in scope for an expression consists of those bindings that are visible at the point in the stylesheet where the expression occurs.

11.1 結果ツリー素片

変数は式言語に新しいデータ型を導入する。 この追加のデータ型を、 結果ツリー素片 と呼ぶ。 変数を XPath の4種の基本データ型( string, number, boolean, node-set )のいずれかではなく、結果ツリー素片に束縛してもよい。 結果ツリー素片は、結果ツリーの素片を表現する。 結果ツリー素片は、ルートノード1個のみからなるノード集合と等価に扱われる。 ただし、結果ツリー素片に許容される演算は、ノード集合に許容される演算のサブセットになる。 文字列に許容される演算のみが、結果ツリー素片に許容される(文字列に対する演算には、最初に数値やブール型に変換する処理も含まれ得る)。 特に, 結果ツリー素片に対しては演算子 /, //, [] は許容されない。 結果ツリー素片に許容される演算は、等価なノード集合に対する演算と全く同じに実行される。 Variables introduce an additional data-type into the expression language. This additional data type is called result tree fragment. A variable may be bound to a result tree fragment instead of one of the four basic XPath data-types (string, number, boolean, node-set). A result tree fragment represents a fragment of the result tree. A result tree fragment is treated equivalently to a node-set that contains just a single root node. However, the operations permitted on a result tree fragment are a subset of those permitted on a node-set. An operation is permitted on a result tree fragment only if that operation would be permitted on a string (the operation on the string may involve first converting the string to a number or boolean). In particular, it is not permitted to use the /, //, and [] operators on result tree fragments. When a permitted operation is performed on a result tree fragment, it is performed exactly as it would be on the equivalent node-set.

結果ツリー素片が結果ツリーに複製される際は( [11.3 xsl:copy-of における変数とパラメタの値の利用] を見よ)、その結果ツリー素片と等価なノード集合におけるルートノードのすべての子ノードが、連続する形で結果ツリーに追加される。 When a result tree fragment is copied into the result tree (see [11.3 Using Values of Variables and Parameters with xsl:copy-of]), then all the nodes that are children of the root node in the equivalent node-set are added in sequence to the result tree.

式の評価結果が結果ツリー素片の型になるのは、結果ツリー素片型の変数を参照したときか, 結果ツリー素片を返す拡張関数を呼び出したときか, 値が結果ツリー素片のシステムプロパティを取得したときか、のいずれかのみである。 Expressions can only return values of type result tree fragment by referencing variables of type result tree fragment or calling extension functions that return a result tree fragment or getting a system property whose value is a result tree fragment.

11.2 変数とパラメタの値

変数束縛要素には、次の3方法いずれかにより変数の値を指定できる。 A variable-binding element can specify the value of the variable in three alternative ways.

注記: 位置によってノードを選択する目的で変数を利用する場合、次のように記述しないように注意する。 NOTE:When a variable is used to select nodes by position, be careful not to do:

<xsl:variable name="n">2</xsl:variable>
...
<xsl:value-of select="item[$n]"/>

この記述では、最初の item 要素の値を出力することになる。 これは、変数 n が数値ではなく, 結果ツリー素片に束縛されるためである。 This will output the value of the first item element, because the variable n will be bound to a result tree fragment, not a number.

代わりに、次のいずれかにする: Instead, do either

<xsl:variable name="n" select="2"/>
...
<xsl:value-of select="item[$n]"/>

or

<xsl:variable name="n">2</xsl:variable>
...
<xsl:value-of select="item[position()=$n]"/>

注記: 空のノード集合をパラメタの既定値として指定する場合、次のようにするのが便利である。 NOTE:One convenient way to specify the empty node-set as the default value of a parameter is:

<xsl:param name="x" select="/.."/>

11.3 xsl:copy-of における変数とパラメタの値の利用

<!-- 分類:instruction -->
<xsl:copy-of
  select = expression />

xsl:copy-of 要素の利用により、 xsl:value-of のときのような文字列への変換を行わずに( [7.6.1 xsl:value-of によるテキストの生成] を見よ)、結果ツリー素片を結果ツリーに挿入できる。 必須の select 属性には、 が含まれる。 式の評価結果が結果ツリー素片であれば、その完全な素片が結果ツリーの中に複製される。 評価結果がノード集合の場合は、その全ノードが文書順に結果ツリーの中に複製され, 要素ノードの複製に伴なって属性ノード, 名前空間ノード, 要素ノードの子も複製される。 ルートノード1個はその子の複製により複製される。 属性ノードと名前空間ノードの複製については xsl:copy と同じ規則が適用される( [7.5 複製] を見よ)。 評価結果がノード集合でも結果ツリー素片でもない場合、 xsl:value-of の場合と同様に文字列に変換されてから結果ツリーに挿入される。 The xsl:copy-of element can be used to insert a result tree fragment into the result tree, without first converting it to a string as xsl:value-of does (see [7.6.1 Generating Text with xsl:value-of]). The required select attribute contains an expression. When the result of evaluating the expression is a result tree fragment, the complete fragment is copied into the result tree. When the result is a node-set, all the nodes in the set are copied in document order into the result tree; copying an element node copies the attribute nodes, namespace nodes and children of the element node as well as the element node itself; a root node is copied by copying its children. For copying an attribute or namespace node, the same rules apply as with xsl:copy (see [7.5 Copying]). When the result is neither a node-set nor a result tree fragment, the result is converted to a string and then inserted into the result tree, as with xsl:value-of.

11.4 トップレベルの変数とパラメタ

xsl:variablexsl:paramトップレベル 要素として利用できる。 トップレベルに置く変数束縛要素は、どこからでも見える大域変数を宣言する (他の束縛により 隠蔽 されない限り) 。 トップレベルの xsl:param 要素はスタイルシートに渡すパラメタを宣言する。 XSLT においては、どのパラメタをスタイルシートに渡すかの仕組みは定義しない。 一つのスタイルシートに, 同じ名前の束縛が複数ある場合、最も インポート優先順位 が高いものが利用される。 一つのスタイルシートに, 名前も インポート優先順位 も同じトップレベルの変数束縛が複数含まれる場合、エラーとする。 トップレベルにおいて, 変数の値を指定する式またはテンプレートは、ソース文書のルートノードを処理する際に利用される文脈と同じ文脈で評価される:すなわち, 現在のノードはソース文書のルートノード, 現在のノードリストはソース文書のルートノード1個からなる。 それらのテンプレートや式が大域変数 x の値を指定していて、大域変数 y を参照している場合、y の値は x の値より先に算出されなければならない。 いずれかの大域変数定義でこの順序の処理ができなくなる場合, すなわち定義が循環している場合、エラーとする。 Both xsl:variable and xsl:param are allowed as top-level elements. A top-level variable-binding element declares a global variable that is visible everywhere (except where it is shadowed by another binding). A top-level xsl:param element declares a parameter to the stylesheet; XSLT does not define the mechanism by which parameters are passed to the stylesheet. If a stylesheet contains more than one binding for a variable of a particular name, then the binding with the highest import precedence is used. It is an error if a stylesheet contains more than one binding of a top-level variable with the same name and same import precedence. At the top-level, the expression or template specifying the variable value is evaluated with the same context as that used to process the root node of the source document: the current node is the root node of the source document and the current node list is a list containing just the root node of the source document. If the template or expression specifying the value of a global variable x references a global variable y, then the value for y must be computed before the value of x. It is an error if it is impossible to do this for all global variable definitions; in other words, it is an error if the definitions are circular.

次の例は、大域変数 para-font-size を宣言し, 属性値テンプレートから参照させる。 This example declares a global variable para-font-size, which it references in an attribute value template.

<xsl:variable name="para-font-size">12pt</xsl:variable>

<xsl:template match="para">
 <fo:block font-size="{$para-font-size}">
   <xsl:apply-templates/>
 </fo:block>
</xsl:template>

11.5 テンプレート内の変数とパラメタ

xsl:variablexsl:param のいずれも、トップレベルに限らず, テンプレート内でも利用できる。 xsl:variable は、テンプレート内で命令が利用できる場所なら, どこでも利用できる。 この場合、束縛は xsl:fallback 命令を除く後続のすべての同胞の子孫 から参照できる。 この束縛は xsl:variable 要素自身からは見えないことに注意。 xsl:param は、xsl:template 要素の先頭の子として記述できる。 この場合、束縛は xsl:fallback 命令を除く後続のすべての同胞の子孫 から参照できる。 この束縛は xsl:param 要素自身からは見えないことに注意。 As well as being allowed at the top-level, both xsl:variable and xsl:param are also allowed in templates. xsl:variable is allowed anywhere within a template that an instruction is allowed. In this case, the binding is visible for all following siblings and their descendants the descendants of all following siblings that are not xsl:fallback instructions. Note that the binding is not visible for the xsl:variable element itself. xsl:param is allowed as a child at the beginning of an xsl:template element. In this context, the binding is visible for all following siblings and their descendants the descendants of all following siblings that are not xsl:fallback instructions. Note that the binding is not visible for the xsl:param element itself.

同じ名前の他の束縛が見える位置に新たに現れた束縛は、その束縛を 隠蔽する 。 テンプレート内の xsl:variable 要素や xsl:param 要素が確立する束縛が, 同じテンプレート内の xsl:variable 要素や xsl:param 要素が確立した束縛を 隠蔽 する場合、エラーとする。 テンプレート内の xsl:variable 要素や xsl:param 要素が確立した束縛が、 トップレベルxsl:variable 要素や xsl:param 要素が確立した束縛を 隠蔽 するのはエラーではない。 この場合、トップレベルの束縛はスタイルシート内で他の束縛により隠蔽される場所からは見えなくなる。 従って, 次はエラーになるが: A binding shadows another binding if the binding occurs at a point where the other binding is visible, and the bindings have the same name. It is an error if a binding established by an xsl:variable or xsl:param element within a template shadows another binding established by an xsl:variable or xsl:param element also within the template. It is not an error if a binding established by an xsl:variable or xsl:param element in a template shadows another binding established by an xsl:variable or xsl:paramtop-level element. In this case, the top-level binding will not be visible in the region of the stylesheet where it is shadowed by the other binding. Thus, the following is an error:

<xsl:template name="foo">
<xsl:param name="x" select="1"/>
<xsl:variable name="x" select="2"/>
</xsl:template>

次は許容される: However, the following is allowed:

<xsl:param name="x" select="1"/>
<xsl:template name="foo">
<xsl:variable name="x" select="2"/>
</xsl:template>

注記: Java 言語において, テンプレート内の xsl:variable 要素と最も近い存在は、初期化子を伴う final 局所変数の宣言になる。 例えば, NOTE:The nearest equivalent in Java to an xsl:variable element in a template is a final local variable declaration with an initializer. For example,

<xsl:variable name="x" select="'value'"/>

は、次と似た意味内容になる: has similar semantics to

final Object x = "value";

ただし, XSLT には次の Java の代入演算子と等価な表記は存在しない。 XSLT does not provide an equivalent to the Java assignment operator

x = "value";

その理由は、これを取り入れると, 先頭から終わりまで間断なく続けるバッチ的手法以外に文書の処理を実装することが難しくなるためである。 because this would make it harder to create an implementation that processes a document other than in a batch-like way, starting at the beginning and continuing through to the end.

11.6 テンプレートへのパラメタの引き渡し

<xsl:with-param
  name = qname 
  select = expression>
  <!-- 内容:template -->
</xsl:with-param>

xsl:with-param 要素を通してパラメタをテンプレートに渡すことができる。 必須の name 属性に、パラメタ(束縛の値に置換される変数)の名前を指定する。 name 属性の値は QName であり, [2.4 修飾名] に則って展開される。 xsl:with-paramxsl:call-templatexsl:apply-templates の内部で利用できる。 同じ xsl:call-template または xsl:apply-templates 要素内に同じ名前の複数の xsl:with-param 要素が含まれる場合、エラーとする。 パラメタの値は xsl:variablexsl:param の場合と同じ方法で指定する。 xsl:with-param 要素に指定された値の評価に利用される現在のノードと現在のノードリストは、 xsl:apply-templates 要素や xsl:call-template 要素の場合と同じものになる。 パラメタ x を受け取る xsl:param 要素を持たないテンプレートに、パラメタ x を渡してもエラーにはならない。 このようなパラメタは単に無視される。 Parameters are passed to templates using the xsl:with-param element. The required name attribute specifies the name of the parameter (the variable the value of whose binding is to be replaced). The value of the name attribute is a QName, which is expanded as described in [2.4 Qualified Names]. xsl:with-param is allowed within both xsl:call-template and xsl:apply-templates. It is an error if a single xsl:call-template or xsl:apply-templates element contains more than one xsl:with-param element with the same name. The value of the parameter is specified in the same way as for xsl:variable and xsl:param. The current node and current node list used for computing the value specified by xsl:with-param element is the same as that used for the xsl:apply-templates or xsl:call-template element within which it occurs. It is not an error to pass a parameter x to a template that does not have an xsl:param element for x; the parameter is simply ignored.

次の例は、数値フォーマットを制御する引数を伴う名前付きテンプレート numbered-block を定義している。 This example defines a named template for a numbered-block with an argument to control the format of the number.

<xsl:template name="numbered-block">
  <xsl:param name="format">1. </xsl:param>
  <fo:block>
    <xsl:number format="{$format}"/>
    <xsl:apply-templates/>
  </fo:block>
</xsl:template>

<xsl:template match="ol//ol/li">
  <xsl:call-template name="numbered-block">
    <xsl:with-param name="format">a. </xsl:with-param>
  </xsl:call-template>
</xsl:template>

12 その他の追加の関数

この節では、 XPath のコア関数ライブラリに追加される XSLT 固有の関数について述べる。 これらの追加の関数の一部は、スタイルシートの トップレベル 要素で指定された情報も利用するため、それらの要素についても述べる。 This section describes XSLT-specific additions to the core XPath function library. Some of these additional functions also make use of information specified by top-level elements in the stylesheet; this section also describes these elements.

12.1 複数のソース文書

関数: node-set document ( object, node-set?) Function: node-set document(object, node-set?)

document 関数は、メインのソース文書以外の XML 文書へのアクセスを可能にする。 The document function allows access to XML documents other than the main source document.

【第1引数がノード集合の場合の結果は第1引数が文字列の場合の結果から定義される】 document 関数の引数が1個だけで, その引数がノード集合だった場合、その結果は, 引数のノード集合に含まれる各ノードに対し、ノードの 文字列値 を第1引数に, そのノードを唯一のメンバとするノード集合を第2引数にして document 関数を呼び出した結果の和集合をとったものになる。 document 関数の引数が2個あり, 第1引数がノード集合だった場合、その結果は, 引数のノード集合に含まれる各ノードに対し、ノードの 文字列値 を第1引数に, 第2引数を document 関数に渡された第2引数にして document 関数を呼び出した結果の和集合をとったものになる。 When the document function has exactly one argument and the argument is a node-set, then the result is the union, for each node in the argument node-set, of the result of calling the document function with the first argument being the string-value of the node, and the second argument being a node-set with the node as its only member. When the document function has two arguments and the first argument is a node-set, then the result is the union, for each node in the argument node-set, of the result of calling the document function with the first argument being the string-value of the node, and with the second argument being the second argument passed to the document function.

document 関数に指定した第1引数がノード集合でない場合、第1引数は string 関数を呼び出したかのように文字列に変換される。 この文字列は URI 参照として扱われ, まず この URI が参照するリソースが取得される。 取得された結果のデータは XML 文書として構文解析され, データモデルに従ってツリーが構築される( [3 データモデル] を見よ)。 リソースの取得時にエラーが生じた場合、 XSLT プロセッサはエラーを通知してもよい。 エラーを通知しない場合、空のノード集合を返してエラーから回復しなければならない。 リソース取得時のエラーとしては XSLT プロセッサが URI のスキーマをサポートしていないなどが挙げられる。 XSLT プロセッサには特定の URI スキーマのサポートは要求されていないが、実装側は XSLT プロセッサの説明書においてどの URI スキーマをサポートしているかを示すべきである。 When the first argument to the document function is not a node-set, the first argument is converted to a string as if by a call to the string function. This string is treated as a URI reference; the resource identified by the URI is retrieved. The data resulting from the retrieval action is parsed as an XML document and a tree is constructed in accordance with the data model (see [3 Data Model]). If there is an error retrieving the resource, then the XSLT processor may signal an error; if it does not signal an error, it must recover by returning an empty node-set. One possible kind of retrieval error is that the XSLT processor does not support the URI scheme used by the URI. An XSLT processor is not required to support any particular URI schemes. The documentation for an XSLT processor should specify which URI schemes the XSLT processor supports.

URI 参照が素片識別子を含まない場合、文書のルートノードのみからなるノード集合が返される。 URI 参照が素片識別子を含む場合、この関数は URI 参照の素片識別子から特定されるツリー内のノード集合を返す。 素片識別子の意味内容は、 URI による取得結果のメディア型から決定される。 素片識別子の処理過程でエラーが発生した場合、 XSLT プロセッサはエラーを通知してもよい。 エラーを通知しない場合、空のノード集合を返してエラーから回復しなければならない。 生じ得るエラーには次のものが挙げられる: If the URI reference does not contain a fragment identifier, then a node-set containing just the root node of the document is returned. If the URI reference does contain a fragment identifier, the function returns a node-set containing the nodes in the tree identified by the fragment identifier of the URI reference. The semantics of the fragment identifier is are dependent on the media type of the result of retrieving the URI. If there is an error in processing the fragment identifier, the XSLT processor may signal the error; if it does not signal the error, it must recover by returning an empty node-set. Possible errors include:

メディア型に関わらず、取得結果のデータは XML 文書として構文解析される。 構文解析においては, トップレベルメディア型が text だった場合、メディア型を text/xml とみなした上で行い, それ以外の場合、メディア型を application/xml とみなした上で行うものとする。 The data resulting from the retrieval action is parsed as an XML document regardless of the media type of the retrieval result; if the top-level media type is text, then it is parsed in the same way as if the media type were text/xml; otherwise, it is parsed in the same way as if the media type were application/xml.

注記: トップレベルの xml メディア型は存在しないため, text/xml または application/xml 以外のメディア型のデータでも、実際は XML になっていることがある。 NOTE:Since there is no top-level xml media type, data with a media type other than text/xml or application/xml may in fact be XML.

URI 参照は相対 URI にもなり得る。 この場合、相対 URI の解決に用いる基底 URI ( [3.2 基底 URI] を見よ)は、第2引数のノード集合に含まれるノードのうち, 文書順で最初のノードの基底 URI とする。 URI 参照が相対 URI にもかかわらず第2引数のノード集合が空だった場合、エラーとする。 この場合、 XSLT プロセッサはエラーを通知してもよい。 エラーを通知しない場合、空のノード集合を返して, エラーから回復しなければならない。 第2引数が省略された場合、 document 関数の呼び出しを含む式を含んでいるスタイルシート内のノードの基底 URI を既定のものとして利用するものとする。 長さゼロの URI 参照は、解決対象の URI 参照に相対的な文書への参照になることに注意。 従って document("") は、スタイルシートのルートノードを参照することになり, そのツリー表現は、そのスタイルシートを含む XML 文書を, ソース文書としてあてがったときと全く同じになる。 The URI reference may be relative. The base URI (see [3.2 Base URI]) of the node in the second argument node-set that is first in document order is used as the base URI for resolving the relative URI into an absolute URI. It is an error if the second argument node-set is empty and the URI reference is relative; the XSLT processor may signal the error; if it does not signal an error, it must recover by returning an empty node-set. If the second argument is omitted, then it defaults to the node in the stylesheet that contains the expression that includes the call to the document function. Note that a zero-length URI reference is a reference to the document relative to which the URI reference is being resolved; thus document("") refers to the root node of the stylesheet; the tree representation of the stylesheet is exactly the same as if the XML document containing the stylesheet was the initial source document.

同一の URI から取得された文書は、同一の文書として扱われる。 識別時の比較に用いる URI においては、相対 URI は絶対 URI に解決されるものとし, かつ 素片識別子は含まないものとする。 2つのルートノードが同一の文書からのものであった場合、同一のノードとして扱われる。 従って, 次の式は常に真になる。 Two documents are treated as the same document if they are identified by the same URI. The URI used for the comparison is the absolute URI into which any relative URI was resolved and does not include any fragment identifier. One root node is treated as the same node as another root node if the two nodes are from the same document. Thus, the following expression will always be true:

generate-id(document("foo.xml"))=generate-id(document("foo.xml"))

document 関数の利用においては、ノード集合は複数の文書からのノードを含み得る。 このようなノード集合においては, 同一の文書からの2つのノードの相対的な文書順は、 XPath [XPath] で定められる通常の 文書順 とし, 異なる文書からの2つのノードの相対的な文書順は、それらの文書の実装依存の順序付けに従うものとする。 複数の文書の順序付けについては、一貫性のある順序付けを行わなければならないこと以外に制約はない。 すなわち, 実装は、同じ文書集合に対し常に同じ順序を与えなければならない。 The document function gives rise to the possibility that a node-set may contain nodes from more than one document. With such a node-set, the relative document order of two nodes in the same document is the normal document order defined by XPath [XPath]. The relative document order of two nodes in different documents is determined by an implementation-dependent ordering of the documents containing the two nodes. There are no constraints on how the implementation orders documents other than that it must do so consistently: an implementation must always use the same order for the same set of documents.

12.2 キー

キーを利用すると、暗黙的な相互参照構造を持つ文書を扱えるようになる。 XML の属性型 ID, IDREF, IDREFS は、 XML 文書の相互参照を明示的に利用可能にする仕組みを提供する。 XSLT は XPath の id 関数を利用してこの仕組みをサポートする。 しかしながら、この仕組みには以下に挙げるようないくつもの制約がある。 Keys provide a way to work with documents that contain an implicit cross-reference structure. The ID, IDREF and IDREFS attribute types in XML provide a mechanism to allow XML documents to make their cross-reference explicit. XSLT supports this through the XPath id function. However, this mechanism has a number of limitations:

これらの制約のため、 XML 文書には明示的に ID, IDREF, IDREFS 型の属性で宣言されないような相互参照構造を含むものがある。 Because of these limitations XML documents sometimes contain a cross-reference structure that is not explicitly declared by ID/IDREF/IDREFS attributes.

キーは次の三つ組からなる: A key is a triple containing:

  1. キーを持つノード the node which has the key

  2. キーの名前( 展開名 the name of the key (an expanded-name)

  3. キーの値(文字列) the value of the key (a string)

スタイルシートは、xsl:key 要素を用いて各文書ごとにキーの集合を宣言する。 以下, この集合に属するキーがノード x, 名前 y, 値 z を持つとき、ノード x は名前 y, 値 z のキーを持つ, と表現することにする。 A stylesheet declares a set of keys for each document using the xsl:key element. When this set of keys contains a member with node x, name y and value z, we say that node x has a key with name y and value z.

このようにキーは ID を一般化したものなので、 XML の ID のような制約は課されない。 Thus, a key is a kind of generalized ID, which is not subject to the same limitations as an XML ID:

<!-- Category:
top-level-element -->
<xsl:key
  name = qname
         match = pattern
         use = expression />

キーの宣言には xsl:key 要素を利用する。 name 属性の値(以下これを y とする)にキーの名前を指定する。 値は QName であり, [2.4 修飾名] に則って展開される。 match 属性の値は Pattern である。 xsl:key 要素は match 属性に指定されたパターンに合致するすべてのノードに対し、それらのキーの情報を提供するものになる。 use 属性はキーの値を指定する である。 この式はパターンに合致したノード( x とする)ごとに1度ずつ評価される。 その結果がノード集合の場合、 x は結果の各ノードごとに, その文字列値を値とする名前 y のキーを持つ。 他の場合、結果は文字列に変換され, x はその文字列を値とする名前 y のキーを持つ。 すなわち, xsl:key 要素が次の条件を満たす場合、そのときに限り, ノード x に名前 y , 値 z を持つキーが存在する。 The xsl:key element is used to declare keys. The name attribute specifies the name of the key. The value of the name attribute is a QName, which is expanded as described in [2.4 Qualified Names]. The match attribute is a Pattern; an xsl:key element gives information about the keys of any node that matches the pattern specified in the match attribute. The use attribute is an expression specifying the values of the key; the expression is evaluated once for each node that matches the pattern. If the result is a node-set, then for each node in the node-set, the node that matches the pattern has a key of the specified name whose value is the string-value of the node in the node-set; otherwise, the result is converted to a string, and the node that matches the pattern has a key of the specified name with value equal to that string. Thus, a node x has a key with name y and value z if and only if there is an xsl:key element such that:

ノードに合致する xsl:key 要素は複数存在し得ることに注意。 要素の インポート優先順位 が異なっていても、合致する xsl:key 要素はすべて利用される。 Note also that there may be more than one xsl:key element that matches a given node; all of the matching xsl:key elements are used, even if they do not have the same import precedence.

use 属性または match 属性のいずれかの値が VariableReference を含む , または key 関数を呼び出した 場合、エラーとする。 It is an error for the value of either the use attribute or the match attribute to contain a VariableReference , or a call to the key function .

関数: node-set key ( string, object ) Function: node-set key(string, object)

key 関数は、 ID に対し id 関数が実行することをキーに対して実行する。 第1引数にはキーの名前を指定する。 この引数の値は QName でなければならない。 この値は [2.4 修飾名] に則って展開される。 key 関数の第2引数がノード集合の場合、それに属する各ノードに対し, その 文字列値 を第2引数として key 関数を呼び出した結果の和集合が返される。 key 関数の第2引数が他の型の場合、 string 関数を呼び出したかのように文字列に変換し, 文脈ノードと同じ文書に含まれるノードのうち, 第1引数の名前とこの文字列に等しい値のキーを持つものからなるノード集合が返される。 The key function does for keys what the id function does for IDs. The first argument specifies the name of the key. The value of the argument must be a QName, which is expanded as described in [2.4 Qualified Names]. When the second argument to the key function is of type node-set, then the result is the union of the result of applying the key function to the string-value of each of the nodes in the argument node-set. When the second argument to key is of any other type, the argument is converted to a string as if by a call to the string function; it returns a node-set containing the nodes in the same document as the context node that have a value for the named key equal to this string.

例えば次の宣言: For example, given a declaration

<xsl:key name="idkey" match="div" use="@id"/>

において, 式 key("idkey",@ref) は、 XML ソース文書に宣言されている唯一の ID 型の属性が次のもの: an expression key("idkey",@ref) will return the same node-set as id(@ref), assuming that the only ID attribute declared in the XML source document is:

<!ATTLIST div id ID #IMPLIED>

で, かつ 現在のノードの ref 属性に空白が含まれていなければ、 id(@ref) と同じノード集合を返す。 and that the ref attribute of the current node contains no whitespace.

関数ライブラリを記述する文書があって, 次のように prototype 要素を用いて関数を定義しているとする: Suppose a document describing a function library uses a prototype element to define functions

<prototype name="key" return-type="node-set">
<arg type="string"/>
<arg type="object"/>
</prototype>

更に, function 要素があって次のように関数名を参照しているとする: and a function element to refer to function names

<function>key</function>

このとき, 次ようなスタイルシートで、参照と定義の間にハイパーリンクを生成できる: Then the stylesheet could generate hyperlinks between the references and definitions as follows:

<xsl:key name="func" match="prototype" use="@name"/>

<xsl:template match="function">
<b>
  <a href="#{generate-id(key('func',.))}">
    <xsl:apply-templates/>
  </a>
</b>
</xsl:template>

<xsl:template match="prototype">
<p><a name="{generate-id()}">
<b>Function: </b>
...
</a></p>
</xsl:template>

key 関数は、常に現在のノードと同じ文書のノードの集合を返す。 他の文書からキーを取得するためには、まず現在のノードを変更しておく必要がある。 例えば <bibref>XSLT</bibref> の形式の書籍目録参照を含む文書があって, 書籍目録データベースを内容とする別の XML 文書 bib.xml に次の形式の項目が含まれているとする: The key can be used to retrieve a key from a document other than the document containing the context node. The key always returns nodes that are in the same document as the current node; to retrieve a key from any other document, it is necessary first to change the current node. For example, suppose a document contains bibliographic references in the form <bibref>XSLT</bibref>, and there is a separate XML document bib.xml containing a bibliographic database with entries in the form:

<entry name="XSLT">...</entry>

このとき, スタイルシートでは、次のようにして bibref 要素を変換できる: Then the stylesheet could use the following to transform the bibref elements:

<xsl:key name="bib" match="entry" use="@name"/>

<xsl:template match="bibref">
  <xsl:variable name="name" select="."/>
  <xsl:for-each select="document('bib.xml')">
    <xsl:apply-templates select="key('bib',$name)"/>
  </xsl:for-each>
</xsl:template>

12.3 数値のフォーマット化

関数: string format-number ( number, string, string ? ) Function: string format-number(number, string, string?)

format-number 関数は、第2引数で与えられたフォーマットパターン文字列と第3引数で与えられた名前の十進フォーマット( decimal-format )を利用して, 第1引数を文字列に変換する。 第3引数が指定されていない場合、既定の十進フォーマットが利用される。 フォーマットパターン文字列の構文は、 JDK 1.1 の DecimalFormat クラスで規定されるものとする。 フォーマットパターン文字列は、ローカライズされた記法で表記される。 十進フォーマットは、パターン内で特別な意味を持つ文字を規定する(引用符はローカライズされないので, これには含まれない)。 フォーマットパターンには通貨記号( #x00A4 )を含めてはならない。 この通貨記号が JDK 1.1 の初期リリース版以後にサポートされるようになったためである。 十進フォーマットの名前は QName でなければならない。 この値は [2.4 修飾名] に則って展開される。 スタイルシートが, 指定された 展開名 を持つ十進フォーマットの宣言を含まない場合、エラーとする。 The format-number function converts its first argument to a string using the format pattern string specified by the second argument and the decimal-format named by the third argument, or the default decimal-format, if there is no third argument. The format pattern string is in the syntax specified by the JDK 1.1 DecimalFormat class. The format pattern string is in a localized notation: the decimal-format determines what characters have a special meaning in the pattern (with the exception of the quote character, which is not localized). The format pattern must not contain the currency sign (#x00A4); support for this feature was added after the initial release of JDK 1.1. The decimal-format name must be a QName, which is expanded as described in [2.4 Qualified Names]. It is an error if the stylesheet does not contain a declaration of the decimal-format with the specified expanded-name.

注記: XSLT の実装には JDK 1.1 の実装の利用は要求されていないし, XSLT を Java で実装することも要求されていない。 NOTE:Implementations are not required to use the JDK 1.1 implementation, nor are implementations required to be implemented in Java.

注記: スタイルシートは、数値の丸め方の制御に XPath のその他の機能を利用できる。 NOTE:Stylesheets can use other facilities in XPath to control rounding.

<!-- 分類:top-level-element -->
<xsl:decimal-format
  name = qname 
  decimal-separator = char 
  grouping-separator = char 
  infinity = string 
  minus-sign = char 
  NaN = string 
  percent = char 
  per-mille = char 
  zero-digit = char 
  digit = char 
  pattern-separator = char />

xsl:decimal-format 要素は、十進フォーマットを宣言して format-number 関数が利用するフォーマットパターンの解釈を制御する。 要素に name 属性が与えられた場合、名前付きの十進フォーマットを宣言する。 他の場合、既定の十進フォーマットを宣言する。 name 属性の値は QName であり, [2.4 修飾名] に則って展開される。 既定の十進フォーマットまたは同じ名前の十進フォーマットが( インポート優先順位 に関わらず)複数回宣言された場合、それらの(すべての既定値も含めた)すべての属性値が同じになる場合を除き, エラーとする。 スタイルシートに既定の十進フォーマットの宣言が与えられていない場合、属性を持たない xsl:decimal-format 要素と等価な宣言が既定のものとして利用されるものとする。 The xsl:decimal-format element declares a decimal-format, which controls the interpretation of a format pattern used by the format-number function. If there is a name attribute, then the element declares a named decimal-format; otherwise, it declares the default decimal-format. The value of the name attribute is a QName, which is expanded as described in [2.4 Qualified Names]. It is an error to declare either the default decimal-format or a decimal-format with a given name more than once (even with different import precedence), unless it is declared every time with the same value for all attributes (taking into account any default values). If a stylesheet does not contain a declaration of the default decimal format, a declaration equivalent to an xsl:decimal-format element with no attributes is implied.

xsl:decimal-format の他の属性は、 JDK 1.1 の DecimalFormatSymbols クラスが提供するメソッドに対応している。 xsl:decimal-format 要素には、このクラスの get, set メソッドの各ペアに対応する属性が定義されている。 The other attributes on xsl:decimal-format correspond to the methods on the JDK 1.1 DecimalFormatSymbols class. For each get/set method pair there is an attribute defined for the xsl:decimal-format element.

次に挙げる属性は、フォーマットパターンに含まれる文字の解釈を制御するとともに, 数値のフォーマット結果に現れる文字を規定する。 The following attributes both control the interpretation of characters in the format pattern and specify characters that may appear in the result of formatting the number:

次に挙げる属性は、フォーマットパターンに含まれる文字の解釈を制御する。 The following attributes control the interpretation of characters in the format pattern:

次に挙げる属性は、数値をフォーマットした結果に現れる文字または文字列を指定する。 The following attributes specify characters or strings that may appear in the result of formatting the number:

12.4 その他の追加の関数

関数: node-set current() Function: node-set current()

current 関数は、 現在のノード のみからなるノード集合を返す。 最も外側の式(他の式の内部に現れない式)においては、現在のノードは常に文脈ノードと同じになる。 従って, The current function returns a node-set that has the current node as its only member. For an outermost expression (an expression not occurring within another expression), the current node is always the same as the context node. Thus,

<xsl:value-of select="current()"/>

は、次と同じ意味になる。 means the same as

<xsl:value-of select="."/>

しかしながら, 角括弧内では、通常, 現在のノードと文脈ノードは異なる。 例えば: However, within square brackets the current node is usually different from the context node. For example,

<xsl:apply-templates select="//glossary/item[@name=current()/@ref]"/>

は、親要素が glossary, かつ name 属性の値が現在のノードの ref 属性の値と等しい, すべての item 要素を処理する。 これは次とは異なる: will process all item elements that have a glossary parent element and that have a name attribute with value equal to the value of the current node's ref attribute. This is different from

<xsl:apply-templates select="//glossary/item[@name=./@ref]"/>

これは次と同じ意味になる: which means the same as

<xsl:apply-templates select="//glossary/item[@name=@ref]"/>

この場合, 親要素が glossary, かつ name 属性と ref 属性の値が等しい, すべての item 要素を処理することになる。 and so would process all item elements that have a glossary parent element and that have a name attribute and a ref attribute with the same value.

パターン 内の current 関数の利用は、エラーとする。 It is an error to use the current function in a pattern.

関数: string unparsed-entity-uri ( string ) Function: string unparsed-entity-uri(string)

unparsed-entity-uri 関数は、文脈ノードと同じ文書に含まれる, 引数に指定された名前の解析対象外実体の URI を返す ( [3.3 解析対象外実体] を見よ)。 該当する解析対象外実体が存在しない場合、空文字列を返す。 The unparsed-entity-uri returns the URI of the unparsed entity with the specified name in the same document as the context node (see [3.3 Unparsed Entities]). It returns the empty string if there is no such entity.

関数: string generate-id ( node-set?) Function: string generate-id(node-set?)

generate-id 関数は、引数に指定されたノード集合の中から, 文書順で最初のノードを一意的に識別する文字列を返す。 この識別子は ASCII の英数文字からなり, 先頭の文字はアルファベットでなければならない。 従って, この文字列は構文上は XML 名になる。 実装は、同じノードには常に同じ識別子を生成し, 異なるノードには常に異なる識別子を生成する限り, どのような方法で識別子を生成してもよい。 実装は、文書が変換されるごとに同じ識別子を生成する義務はない。 生成される一意的な識別子が、ソース文書内の一意 ID とは別個になる保証はない。 引数に指定されたノード集合が空の場合、空文字列を返す。 引数が省略された場合、文脈ノードが既定の引数として利用される。 The generate-id function returns a string that uniquely identifies the node in the argument node-set that is first in document order. The unique identifier must consist of ASCII alphanumeric characters and must start with an alphabetic character. Thus, the string is syntactically an XML name. An implementation is free to generate an identifier in any convenient way provided that it always generates the same identifier for the same node and that different identifiers are always generated from different nodes. An implementation is under no obligation to generate the same identifiers each time a document is transformed. There is no guarantee that a generated unique identifier will be distinct from any unique IDs specified in the source document. If the argument node-set is empty, the empty string is returned. If the argument is omitted, it defaults to the context node.

関数: object system-property ( string ) Function: object system-property(string)

引数は QName の文字列に評価されなければならない。その QName は、式のスコープに含まれる名前空間宣言を用いて名前に展開される。 system-property 関数は、その名前で識別されるシステムプロパティの値を表すオブジェクトを返す。 システムプロパティが存在しない場合、空文字列を返すべきである。 The argument must evaluate to a string that is a QName. The QName is expanded into a name using the namespace declarations in scope for the expression. The system-property function returns an object representing the value of the system property identified by the name. If there is no such system property, the empty string should be returned.

実装は、次に挙げるシステムプロパティを提供しなければならない。 これらはすべて XSLT 名前空間に属する: Implementations must provide the following system properties, which are all in the XSLT namespace:

ベンダは XSLT 名前空間に属する追加のシステムプロパティを定義してはならない。 Vendors must not define additional system properties in the XSLT namespace.

13 メッセージ

<!-- 分類:instruction -->
<xsl:message
  terminate = "yes" | "no">
  <!-- 内容:template -->
</xsl:message>

xsl:message 命令は、 XSLT プロセッサに固有の形式でメッセージを送信する。 xsl:message 命令の内容はテンプレートである。 xsl:message は、その内容のインスタンス化によりインスタンス化され, XML の素片を生成する。 この XML 素片がメッセージの内容になる。 The xsl:message instruction sends a message in a way that is dependent on the XSLT processor. The content of the xsl:message instruction is a template. The xsl:message is instantiated by instantiating the content to create an XML fragment. This XML fragment is the content of the message.

注記: XSLT プロセッサは xsl:message の実装において、警告ボックスのポップアップやログファイルへの書き込みのような方法をとってもよい。 NOTE:An XSLT processor might implement xsl:message by popping up an alert box or by writing to a log file.

terminate 属性に yes が指定されている場合、 XSLT プロセッサはメッセージ送信後に処理を終了すべきである。 既定値は no If the terminate attribute has the value yes, then the XSLT processor should terminate processing after sending the message. The default value is no.

ローカライズを行う便利な方法の一つは、ローカライズ済みの情報(メッセージのテキストなど)を XML 文書に挿入することである。 これは、スタイルシートへの追加の入力ファイルになる。 例えば、言語 L のメッセージが次の形式で XML ファイル resources/L.xml に格納されているとする: One convenient way to do localization is to put the localized information (message text, etc.) in an XML document, which becomes an additional input file to the stylesheet. For example, suppose messages for a language L are stored in an XML file resources/L.xml in the form:

<messages>
  <message name="problem">A problem was detected.</message>
  <message name="error">An error was detected.</message>
</messages>

スタイルシートは、次のやり方でメッセージをローカライズできる: Then a stylesheet could use the following approach to localize messages:

<xsl:param name="lang" select="'en'"/>
<xsl:variable name="messages"
  select="document(concat('resources/', $lang, '.xml'))/messages"/>

<xsl:template name="localized-message">
  <xsl:param name="name"/>
  <xsl:message>
    <xsl:value-of select="$messages/message[@name=$name]"/>
  </xsl:message>
</xsl:template>

<xsl:template name="problem">
  <xsl:call-template name="localized-message"/>
    <xsl:with-param name="name">problem</xsl:with-param>
  </xsl:call-template>
</xsl:template>

14 拡張

XSLT では、拡張要素と拡張関数の2種類の拡張が可能である。 XSLT allows two kinds of extension, extension elements and extension functions.

このバージョンの XSLT では、拡張機能の実装を定義する仕組みは提供しない。 したがって, 異なる XSLT 実装間での相互利用が必須になる XSLT スタイルシートは、特定の拡張機能に依存できない。 そのため, XSLT では、 XSLT スタイルシートにおいて, それを処理する XSLT プロセッサに特定の拡張機能が実装されているかどうかを判定し、利用できない場合の処理を指定できる仕組みを提供している。 XSLT スタイルシートにおいてこの仕組みを注意深く利用することにより, 拡張機能の利便性を享受しつつ、スタイルシートがどの XSLT 実装でも有効に機能するようにできる。 This version of XSLT does not provide a mechanism for defining implementations of extensions. Therefore, an XSLT stylesheet that must be portable between XSLT implementations cannot rely on particular extensions being available. XSLT provides mechanisms that allow an XSLT stylesheet to determine whether the XSLT processor by which it is being processed has implementations of particular extensions available, and to specify what should happen if those extensions are not available. If an XSLT stylesheet is careful to make use of these mechanisms, it is possible for it to take advantage of extensions and still work with any XSLT implementation.

14.1 拡張要素

要素を拡張する仕組みにより、名前空間を 拡張名前空間 に指定できる(以下「拡張指定」)。 名前空間が拡張指定にされると, その名前空間に属する名前の要素は、テンプレートの中ではリテラル結果要素としてではなく, 命令として扱われる。 この名前空間は、命令の意味内容を定める。 The element extension mechanism allows namespaces to be designated as extension namespaces. When a namespace is designated as an extension namespace and an element with a name from that namespace occurs in a template, then the element is treated as an instruction rather than as a literal result element. The namespace determines the semantics of the instruction.

注記: xsl:stylesheet 要素の子要素はテンプレートの内部の要素ではないので, 非 XSLT の トップレベル の要素は、ここで定義する拡張要素には該当せず, この節の内容は全て適用されない。 NOTE:Since an element that is a child of an xsl:stylesheet element is not occurring in a template, non-XSLT top-level elements are not extension elements as defined here, and nothing in this section applies to them.

名前空間を拡張指定にするためには、 xsl:stylesheet 要素に extension-element-prefixes 属性を与えるか, リテラル結果要素または拡張要素に xsl:extension-element-prefixes 属性を与える。 これらの属性の値は、いずれも名前空間接頭辞の空白区切りのリストである。 各接頭辞に結びつけられた名前空間が、拡張指定にされる。 extension-element-prefixes 属性または xsl:extension-element-prefixes 属性を持つ要素のスコープに, これらの接頭辞に結びつけられた名前空間が存在しない場合、エラーとする。 名前空間接頭辞のリストに #default を含めることにより, 既定の名前空間( xmlns で宣言されたもの)を拡張指定にしてもよい。 名前空間の拡張指定は、 extension-element-prefixes 属性または xsl:extension-element-prefixes 属性を持つ要素をルートとするスタイルシートの部分ツリーの中で有効になる。 xsl:stylesheet 要素をルートとする部分ツリーでは、その xsl:stylesheet 要素の子によりインポートまたはインクルードされたスタイルシートには指定の効力は及ばない。 A namespace is designated as an extension namespace by using an extension-element-prefixes attribute on an xsl:stylesheet element or an xsl:extension-element-prefixes attribute on a literal result element or extension element. The value of both these attributes is a whitespace-separated list of namespace prefixes. The namespace bound to each of the prefixes is designated as an extension namespace. It is an error if there is no namespace bound to the prefix on the element bearing the extension-element-prefixes or xsl:extension-element-prefixes attribute. The default namespace (as declared by xmlns) may be designated as an extension namespace by including #default in the list of namespace prefixes. The designation of a namespace as an extension namespace is effective within the subtree of the stylesheet rooted at the element bearing the extension-element-prefixes or xsl:extension-element-prefixes attribute; a subtree rooted at an xsl:stylesheet element does not include any stylesheets imported or included by children of that xsl:stylesheet element.

XSLT プロセッサが特定の拡張要素に対応する実装を備えていない場合、 element-available 関数はその要素の名前に対し, 偽を返さなければならない。 そのような拡張要素がインスタンス化される際は、 XSLT プロセッサは [15 フォールバック] に則って, その要素に対するフォールバックを実行しなければならない。 XSLT プロセッサは、単に実装が対応しない拡張要素がテンプレートに含まれているだけの理由でエラーを通知してはならない。 If the XSLT processor does not have an implementation of a particular extension element available, then the element-available function must return false for the name of the element. When such an extension element is instantiated, then the XSLT processor must perform fallback for the element as specified in [15 Fallback]. An XSLT processor must not signal an error merely because a template contains an extension element for which no implementation is available.

XSLT プロセッサの実装が特定の拡張要素に対応している場合、 element-available 関数はその要素の名前に対し, 真を返さなければならない。 If the XSLT processor has an implementation of a particular extension element available, then the element-available function must return true for the name of the element.

14.2 拡張関数

FunctionCall (関数呼び出しの生成規則)に含まれる FunctionName (関数名)が NCName でない場合(すなわちコロンが含まれる)、この FunctionName は拡張関数の呼び出しとして扱われる。 この FunctionName は評価文脈のスコープに入る名前空間宣言を用いて名前に展開される。 If a FunctionName in a FunctionCall expression is not an NCName (i.e. if it contains a colon), then it is treated as a call to an extension function. The FunctionName is expanded to a name using the namespace declarations from the evaluation context.

XSLT プロセッサの実装が特定の名前の拡張関数に対応していない場合、 function-available 関数はその名前に対し, 偽を返さなければならない。 そのような拡張関数が式に現れ, 実際に呼び出された場合、 XSLT プロセッサはエラーを通知しなければならない。 XSLT プロセッサは、実装が対応しない拡張関数が式に含まれているだけの理由でエラーを通知してはならない。 If the XSLT processor does not have an implementation of an extension function of a particular name available, then the function-available function must return false for that name. If such an extension function occurs in an expression and the extension function is actually called, the XSLT processor must signal an error. An XSLT processor must not signal an error merely because an expression contains an extension function for which no implementation is available.

XSLT プロセッサの実装が特定の名前の拡張関数に対応している場合、 function-available 関数はその名前に対し、真を返さなければならない。 そのような拡張機能が呼び出された場合、 XSLT プロセッサは関数呼び出しの引数を渡して実装を呼び出さなければならない。 実装から返された結果が、その関数呼び出しの結果として返される。 If the XSLT processor has an implementation of an extension function of a particular name available, then the function-available function must return true for that name. If such an extension is called, then the XSLT processor must call the implementation passing it the function call arguments; the result returned by the implementation is returned as the result of the function call.

15 フォールバック

<!-- 分類:instruction -->
<xsl:fallback>
  <!-- 内容:template -->
</xsl:fallback>

通常, xsl:fallback 要素のインスタンス化では何も実行されないが、 XSLT プロセッサがある命令要素に対し, フォールバックを実行する場合、その命令要素に1個以上の xsl:fallback 子要素が含まれているならば、それら各子要素の内容を順次インスタンス化しなければならない。 そうでないならば、エラーを通知しなければならない。 xsl:fallback 要素の内容はテンプレートである。 Normally, instantiating an xsl:fallback element does nothing. However, when an XSLT processor performs fallback for an instruction element, if the instruction element has one or more xsl:fallback children, then the content of each of the xsl:fallback children must be instantiated in sequence; otherwise, an error must be signaled. The content of an xsl:fallback element is a template.

xsl:choose 命令および xsl:if 命令と伴に次の関数を利用すると、特定の要素または関数を利用できない場合のスタイルシートのふるまいを明示的に制御できる。 The following functions can be used with the xsl:choose and xsl:if instructions to explicitly control how a stylesheet should behave if particular elements or functions are not available.

関数: boolean element-available ( string ) Function: boolean element-available(string)

引数は QName の文字列に評価されなければならない。 この QName は、式のスコープに入る名前空間宣言を用いて 展開名 に展開される。 スコープに既定の名前空間が入る場合、それが接頭辞無しの QName の展開に用いられる。 element-available 関数は、展開名が命令の名前に一致するとき, そのときに限り真を返す。 展開名が XSLT 名前空間 URI と同じ名前空間 URI を持つ場合、 XSLT が定義する要素を参照する。 他の場合は拡張要素を参照する。 展開名の名前空間 URI が null の場合、 element-available 関数は偽を返す。 The argument must evaluate to a string that is a QName. The QName is expanded into an expanded-name using the namespace declarations in scope for the expression. If there is a default namespace in scope, then it is used to expand an unprefixed QName. The element-available function returns true if and only if the expanded-name is the name of an instruction. If the expanded-name has a namespace URI equal to the XSLT namespace URI, then it refers to an element defined by XSLT. Otherwise, it refers to an extension element. If the expanded-name has a null namespace URI, the element-available function will return false.

関数: boolean function-available ( string ) Function: boolean function-available(string)

引数は QName の文字列に評価されなければならない。 この QName は、式のスコープに入る名前空間宣言を用いて 展開名 に展開される。 function-available 関数は、展開名が関数名として関数ライブラリに含まれる場合にのみ真を返す。 展開名が非 null 名前空間 URI を持つ場合、拡張関数を参照する。 他の場合、 XPath または XSLT が定義する関数を参照する。 The argument must evaluate to a string that is a QName. The QName is expanded into an expanded-name using the namespace declarations in scope for the expression. The function-available function returns true if and only if the expanded-name is the name of a function in the function library. If the expanded-name has a non-null namespace URI, then it refers to an extension function; otherwise, it refers to a function defined by XPath or XSLT.

16 出力

<!-- 分類:top-level-element -->
<xsl:output
  method = "xml" | "html" | "text" | qname-but-not-ncname 
  version = nmtoken 
  encoding = string 
  omit-xml-declaration = "yes" | "no"
  standalone = "yes" | "no"
  doctype-public = string 
  doctype-system = string 
  cdata-section-elements = qnames 
  indent = "yes" | "no"
  media-type = string />

XSLT プロセッサは、バイト列として結果ツリーを出力してもよいが, この形式の出力機能は要求されていない( [17 適合性] を見よ)。 xsl:output 要素を利用して、結果ツリーの出力方法をスタイルシートの作成時に指定できる。 XSLT プロセッサが結果ツリーを出力する際は xsl:output 要素の指定に従って出力すべきである。 しかしながら、これは必須ではない。 An XSLT processor may output the result tree as a sequence of bytes, although it is not required to be able to do so (see [17 Conformance]). The xsl:output element allows stylesheet authors to specify how they wish the result tree to be output. If an XSLT processor outputs the result tree, it should do so as specified by the xsl:output element; however, it is not required to do so.

xsl:output 要素は、 トップレベル の要素としてのみ許容される。 The xsl:output element is only allowed as a top-level element.

xsl:outputmethod 属性は、結果ツリーの出力全般に渡り適用されるべきメソッド(フォーマット方式)を指定する。 この値は QName でなければならない。 QName に接頭辞がない場合、この仕様が規定する出力メソッドであるものと解釈され, 値は xml, html, text のいずれかでなければならない。 QName に接頭辞がある場合、 QName[2.4 修飾名] に則って 展開名 に展開され, この展開名から出力メソッドが特定される。 この場合のふるまいについてはこの仕様では規定しない。 The method attribute on xsl:output identifies the overall method that should be used for outputting the result tree. The value must be a QName. If the QName does not have a prefix, then it identifies a method specified in this document and must be one of xml, html or text. If the QName has a prefix, then the QName is expanded into an expanded-name as described in [2.4 Qualified Names]; the expanded-name identifies the output method; the behavior in this case is not specified by this document.

method 属性の既定は、次のように選択される。 まず, 以下の条件を満たすとき、既定の出力メソッドは html になる: The default for the method attribute is chosen as follows. If

上記以外の場合、既定の出力メソッドは xml になる。 xsl:output 要素が与えられていない場合, あるいはどの xsl:output 要素にも method 属性の値が指定されていない場合、既定の出力メソッドが利用されるべきである。 then the default output method is html; otherwise, the default output method is xml. The default output method should be used if there are no xsl:output elements or if none of the xsl:output elements specifies a value for the method attribute.

xsl:output の他の属性には、出力メソッドに与えるパラメタを指定する。 以下に挙げる属性がある: The other attributes on xsl:output provide parameters for the output method. The following attributes are allowed:

各属性の意味内容の詳細は、その属性の適用対象になる出力メソッドごとに説明を与える。 意味内容についての言及がない所は、その出力メソッドにはその属性が適用されないことを意味する。 The detailed semantics of each attribute will be described separately for each output method for which it is applicable. If the semantics of an attribute are not described for an output method, then it is not applicable to that output method.

スタイルシートは複数の xsl:output 要素を含み得る。 また, xsl:output 要素を持つ他のスタイルシートのインクルードやインポートもできる。 スタイルシートに現れるすべての xsl:output 要素は、1個の有効な xsl:output 要素に併合される。 cdata-section-elements 属性については、指定された値全体の和集合が有効な値になる。 その他の属性については、指定された値のうち インポート優先順位 が最高のものが有効な値になる。 一つの属性において最高の優先順位を持つ値が複数存在する場合、エラーとする。 XSLT プロセッサはエラーを通知してもよい。 エラーを通知しない場合、スタイルシートの最後方に現れる値を利用して, エラーから回復すべきである。 属性の既定値は xsl:output 要素が併合された後で設定される。 属性の既定値は出力メソッドにより異なり得る。 A stylesheet may contain multiple xsl:output elements and may include or import stylesheets that also contain xsl:output elements. All the xsl:output elements occurring in a stylesheet are merged into a single effective xsl:output element. For the cdata-section-elements attribute, the effective value is the union of the specified values. For other attributes, the effective value is the specified value with the highest import precedence. It is an error if there is more than one such value for an attribute. An XSLT processor may signal the error; if it does not signal the error, if should recover by using the value that occurs last in the stylesheet. The values of attributes are defaulted after the xsl:output elements have been merged; different output methods may have different default values for an attribute.

16.1 XML 出力メソッド

xml 出力メソッドは、結果ツリーを整形式 XML の外部一般解析対象実体として出力する。 結果ツリーのルートノードが、1個の要素を子に持ち, テキストノードは1個も子に持たない場合、この実体は整形式 XML 文書にもなる。 そのような実体が、次のような小さな XML 文書ラッパー: The xml output method outputs the result tree as a well-formed XML external general parsed entity. If the root node of the result tree has a single element node child and no text node children, then the entity should also be a well-formed XML document entity. When the entity is referenced within a trivial XML document wrapper like this

<?xml version="xml-version"?>
<!DOCTYPE doc [
<!ENTITY e SYSTEM "entity-URI">
]>
<doc>&e;</doc>

から参照されている場合( ここで entity-URI は実体の URI , xml-version は実体に対応する XML のバージョン を表すとする)、ラッパー文書は [XML Names] または [XML Names 1.1] に適合する整形式 XML 文書になるべきである。 加えて, 出力に対しては、ラッパーを [3 データモデル] に則って XML 文書として構文解析し, 文書要素の子要素をルートノードの子にそっくり移し替えて出来上がるツリーが、以下に挙げる例外を除いて結果ツリーと同じになるべきである: where entity-URI is a URI for the entity and xml-version corresponds to the XML version of the entity , then the wrapper document as a whole should be a well-formed XML document conforming to the XML Namespaces Recommendation [XML Names]. either to [XML Names] or [XML Names 1.1]. In addition, the output should be such that if a new tree was constructed by parsing the wrapper as an XML document as specified in [3 Data Model], and then removing the document element, making its children instead be children of the root node, then the new tree would be the same as the result tree, with the following possible exceptions:

XSLT プロセッサが doctype-system 属性の指定により文書型宣言を生成する場合, あるいは standalone 属性の指定によりスタンドアロン文書宣言を生成する場合、出力は整形式 XML 文書でなければならず, 上の要件は DTD を処理しない XML プロセッサを用いて出力文書をラッパ無しに直接構文解析することにより構築されるツリーに適用される。 If the XSLT processor generated a document type declaration because of the doctype-system attribute, then the above requirements apply to the entity with the generated document type declaration removed. If the XSLT processor generated a document type declaration because of the doctype-system attribute or generated a standalone document declaration because of the standalone attribute, then the output must be a well-formed XML document, and the above requirements apply to the tree constructed by parsing that document directly, without any wrapper, using an XML processor that does not process the DTD.

注記: DTD の処理が行われる場合、属性の既定値により, ツリー内に追加の属性が現れ得る。 NOTE:Processing the DTD might cause additional attributes to appear in the tree because of attribute defaulting.

version 属性は、結果ツリーの出力に利用される XML のバージョンを指定する。 XSLT プロセッサは, このバージョンをサポートしない場合、サポートするバージョンを利用すべきである。 XML 宣言が出力される場合、宣言内に出力されるバージョンは, XSLT プロセッサが結果ツリーの出力に利用したバージョンに対応するものにすべきである。 既定値は 1.0 。 値が 1.1 で XSLT プロセッサが XML 1.1 と XML Names 1.1 をともにサポートする場合、次の制約が課せられる: The version attribute specifies the version of XML to be used for outputting the result tree. If the XSLT processor does not support this version of XML, it should use a version of XML that it does support. The version output in the XML declaration (if an XML declaration is output) should correspond to the version of XML that the processor used for outputting the result tree. The value of the version attribute should match the VersionNum production of the XML Recommendation [XML]. The default value is 1.0. The default value is 1.0. If the value is 1.1 and the XSLT processor does support XML 1.1 and XML Names 1.1, then the following restrictions apply:

encoding 属性には、結果ツリーの出力処理に望まれるエンコーディングを指定する。 XSLT プロセッサには、値 UTF-8UTF-16 に対するサポートが要求される。 他の値については, XSLT プロセッサが未サポートのエンコーディングが指定された場合、 XSLT プロセッサはエラーを通知してもよい。 エラーを通知しない場合、代わりに UTF-8 または UTF-16 を利用すべきである。 XSLT プロセッサは、 XML 勧告 [XML] または [XML 1.1] の生成規則 EncName に合致しない名前のエンコーディングを利用してはならない。 encoding 属性が指定されていない場合、 XSLT プロセッサは UTF-8 または UTF-16 のいずれかを利用すべきである。 結果ツリーには、 XSLT プロセッサが出力に利用するエンコーディングでは表現できない文字も含まれ得る。 この場合、 XML において文字参照が認識され得る場所に(すなわち属性ノードの値の中またはテキストノードの内部に)その文字が現れるのであれば, 文字参照として出力すべきである。 それ以外の場合(例えばその文字が要素名に現れる場合)、 XSLT プロセッサはエラーを通知すべきである。 The encoding attribute specifies the preferred encoding to use for outputting the result tree. XSLT processors are required to respect values of UTF-8 and UTF-16. For other values, if the XSLT processor does not support the specified encoding it may signal an error; if it does not signal an error it should use UTF-8 or UTF-16 instead. The XSLT processor must not use an encoding whose name does not match the EncName production of the XML Recommendation [XML] or [XML 1.1]. If no encoding attribute is specified, then the XSLT processor should use either UTF-8 or UTF-16. It is possible that the result tree will contain a character that cannot be represented in the encoding that the XSLT processor is using for output. In this case, if the character occurs in a context where XML recognizes character references (i.e. in the value of an attribute node or text node), then the character should be output as a character reference; otherwise (for example if the character occurs in the name of an element) the XSLT processor should signal an error.

indent 属性の値が yes の場合、 xml 出力メソッドは, 結果を見栄え良くインデント(字下げ)するため, 結果ツリー内の空白に(可能ならソース文書やスタイルシートから削除された空白などを基にして)空白を追加して出力してもよい。 indent 属性の値が no (既定値)の場合、空白を追加出力すべきではない。 xml 出力メソッドで利用する空白追加出力のアルゴリズムは、その出力に対し xsl:text のみを空白保持要素名の集合として [3.4 空白の削除] で述べたプロセスにより空白を削除した結果が、空白を追加出力しないときの出力に対し同じプロセスを適用した結果と一致するようなものになるべきである。 If the indent attribute has the value yes, then the xml output method may output whitespace in addition to the whitespace in the result tree (possibly based on whitespace stripped from either the source document or the stylesheet) in order to indent the result nicely; if the indent attribute has the value no, it should not output any additional whitespace. The default value is no. The xml output method should use an algorithm to output additional whitespace that ensures that the result if whitespace were to be stripped from the output using the process described in [3.4 Whitespace Stripping] with the set of whitespace-preserving elements consisting of just xsl:text would be the same when additional whitespace is output as when additional whitespace is not output.

注記: 一般に、混合内容を持つ要素型を含む文書型に indent="yes" を利用すると問題が生じ易い。 NOTE:It is usually not safe to use indent="yes" with document types that include element types with mixed content.

cdata-section-elements 属性の値は、空白区切りの QName のリストである。 これらの QName は、各 QName が現れる xsl:output 要素で有効な名前空間宣言を用いて展開名に展開される。 接頭辞を持たない QName の展開には、既定の名前空間が(存在すれば)利用される。 この展開処理は、複数の xsl:output 要素が有効な xsl:output 要素に併合される前に行われる。 テキストノードはその親の展開名がこのリストに含まれるならば CDATA セクションとして出力されるべきである。 例えば: The cdata-section-elements attribute contains a whitespace-separated list of QNames. Each QName is expanded into an expanded-name using the namespace declarations in effect on the xsl:output element in which the QName occurs; if there is a default namespace, it is used for QNames that do not have a prefix. The expansion is performed before the merging of multiple xsl:output elements into a single effective xsl:output element. If the expanded-name of the parent of a text node is a member of the list, then the text node should be output as a CDATA section. For example,

<xsl:output cdata-section-elements="example"/>

により、次のリテラル結果要素: would cause a literal result element written in the stylesheet as

<example>&lt;foo></example>

あるいは、次のリテラル結果要素: or as

<example><![CDATA[<foo>]]></example>

の出力は、いずれも次のようになる: to be output as

<example><![CDATA[<foo>]]></example>

テキストノードが文字列 ]]> を含む場合、処理中の CDATA セクションを ]] の直後で閉じ, 新たな CDATA セクションを > の直前から開始させるべきである。 例えば、スタイルシートの次のリテラル結果要素: If the text node contains the sequence of characters ]]>, then the currently open CDATA section should be closed following the ]] and a new CDATA section opened before the >. For example, a literal result element written in the stylesheet as

<example>]]&gt;</example>

の出力は、次のようになる: would be output as

<example><![CDATA[]]]]><![CDATA[>]]></example>

結果ツリーの出力に利用する文字エンコーディングで表現できない文字がテキストノードに含まれている場合、処理中の CDATA セクションをその文字の直前で閉じ, その文字を文字参照または実体参照を用いて出力し, 新たな CDATA セクションを開始してから後続の文字出力するべきである。 If the text node contains a character that is not representable in the character encoding being used to output the result tree, then the currently open CDATA section should be closed before the character, the character should be output using a character reference or entity reference, and a new CDATA section should be opened for any further characters in the text node.

cdata-section-elements 属性により CDATA セクションを用いた出力が明示的に指示されていない限り、テキストノードの出力に CDATA セクションを用いるべきではない。 CDATA sections should not be used except for text nodes that the cdata-section-elements attribute explicitly specifies should be output using CDATA sections.

omit-xml-declaration 属性の値が yes でない限り、 xml 出力メソッドは XML 宣言を出力すべきである。 XML 宣言には、バージョン情報もエンコーディング宣言も含めるべきである。 standalone 属性が指定されている場合はその属性値と同じ値のスタンドアロン文書宣言も含めるべきである。 そうでない場合、スタンドアロン文書宣言は含めるべきではない:これにより, (文書実体の先頭で記述が許されている) XML 宣言になると同時に、(外部一般解析対象実体の先頭で記述が許されている)テキスト宣言にもなるので。 The xml output method should output an XML declaration unless the omit-xml-declaration attribute has the value yes. The XML declaration should include both version information and an encoding declaration. If the standalone attribute is specified, it should include a standalone document declaration with the same value as the value as the value of the standalone attribute. Otherwise, it should not include a standalone document declaration; this ensures that it is both an XML declaration (allowed at the beginning of a document entity) and a text declaration (allowed at the beginning of an external general parsed entity).

doctype-system 属性が指定されている場合、 xml 出力メソッドは最初の要素の直前に文書型宣言を出力すべきである。 <!DOCTYPE に後続する名前は、最初の要素の名前になるべきである。 doctype-public 属性も指定されている場合、 xml 出力メソッドは PUBLIC に続けて公開識別子を出力し, 次にシステム識別子を出力すべきである。 そうでない場合、 SYSTEM に続けてシステム識別子を出力すべきである。 内部サブセットは空にすべきである。 doctype-public 属性は doctype-system 属性が指定されていない限り無視される。 If the doctype-system attribute is specified, the xml output method should output a document type declaration immediately before the first element. The name following <!DOCTYPE should be the name of the first element. If doctype-public attribute is also specified, then the xml output method should output PUBLIC followed by the public identifier and then the system identifier; otherwise, it should output SYSTEM followed by the system identifier. The internal subset should be empty. The doctype-public attribute should be ignored unless the doctype-system attribute is specified.

media-type 属性は xml 出力メソッドに適用できる。 既定の値は text/xml である。 The media-type attribute is applicable for the xml output method. The default value for the media-type attribute is text/xml.

16.2 HTML 出力メソッド

html 出力メソッドは結果ツリーを HTML として出力する。 例を次に示す。 The html output method outputs the result tree as HTML; for example,

<xsl:stylesheet version="1.0"
                xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

<xsl:output method="html"/>

<xsl:template match="/">
  <html>
   <xsl:apply-templates/>
  </html>
</xsl:template>

...

</xsl:stylesheet>

version 属性は HTML のバージョンを指示する。 既定値の 4.0 は、結果ツリーを HTML 4.0 勧告 [HTML] に適合する HTML で出力すべきであることを指定する。 The version attribute indicates the version of the HTML. The default value is 4.0, which specifies that the result should be output as HTML conforming to the HTML 4.0 Recommendation [HTML].

html 出力メソッドは、要素の展開名の名前空間 URI が null でない限り, xml 出力メソッドと異なる方法で要素を出力すべきではない。 展開名が非 null の名前空間 URI を持つ要素は、 XML として出力すべきである。 展開名の名前空間 URI が null で, 局所部が HTML 要素名と認識されない要素は、 span などの空要素でない行内要素と同じ方法で出力すべきである。 The html output method should not output an element differently from the xml output method unless the expanded-name of the element has a null namespace URI; an element whose expanded-name has a non-null namespace URI should be output as XML. If the expanded-name of the element has a null namespace URI, but the local part of the expanded-name is not recognized as the name of an HTML element, the element should output in the same way as a non-empty, inline element such as span.

html 出力メソッドは空要素の終了タグを出力すべきではない。 HTML 4.0 の空要素は、 area, base, basefont, br, col, frame, hr, img, input, isindex, link, meta, param である。 例えば, スタイルシートに <br/> あるいは <br></br> と記述された要素の出力は、 <br> にすべきである。 The html output method should not output an end-tag for empty elements. For HTML 4.0, the empty elements are area, base, basefont, br, col, frame, hr, img, input, isindex, link, meta and param. For example, an element written as <br/> or <br></br> in the stylesheet should be output as <br>.

html 出力メソッドは、文字の大小を区別せずに HTML 要素名を認識すべきである。 例えば、要素名 br, BR, Br はすべて HTML の br 要素と認識され, 終了タグなしで出力される。 The html output method should recognize the names of HTML elements regardless of case. For example, elements named br, BR or Br should all be recognized as the HTML br element and output without an end-tag.

html 出力メソッドは、script および style 要素の内容にエスケープ処理を施すべきではない。 例えば, 次の2つのリテラル結果要素: The html output method should not perform escaping for the content of the script and style elements. For example, a literal result element written in the stylesheet as

<script>if (a &lt; b) foo()</script>

or

<script><![CDATA[if (a < b) foo()]]></script>

の出力は、いずれも次になる: should be output as

<script>if (a < b) foo()</script>

html 出力メソッドでは、属性値に現れる文字 < をエスケープすべきではない。 The html output method should not escape < characters occurring in attribute values.

indent 属性の値が yes (既定値)の場合、html 出力メソッドは、 HTML ユーザエージェントによるレンダリングに影響を与えない範囲で, 結果ツリーの出力に空白を追加/削除してよい。 If the indent attribute has the value yes, then the html output method may add or remove whitespace as it outputs the result tree, so long as it does not change how an HTML user agent would render the output. The default value is yes.

html 出力メソッドは、 HTML 4.0 勧告 B.2.1 節 で推奨される方法を用いて, URI 属性の値に含まれる非 ASCII 文字をエスケープすべきである。 The html output method should escape non-ASCII characters in URI attribute values using the method recommended in Section B.2.1 of the HTML 4.0 Recommendation.

html 出力メソッドは、文字に対する文字実体参照が利用中の HTML のバージョンで定義されていれば, 文字実体参照を用いてその文字を出力してもよい。 The html output method may output a character using a character entity reference, if one is defined for it in the version of HTML that the output method is using.

html 出力メソッドは、 ?> ではなく > により処理命令を閉じるべきである。 The html output method should terminate processing instructions with > rather than ?>.

html 出力メソッドは、ブール型の属性(属性名と同じ値のみが, 値として許されている属性)を最小形で出力すべきである。 例えば, スタイルシートの次の開始タグ: The html output method should output boolean attributes (that is attributes with only a single allowed value that is equal to the name of the attribute) in minimized form. For example, a start-tag written in the stylesheet as

<OPTION selected="selected">

の出力は次のようになる: should be output as

<OPTION selected>

html 出力メソッドは属性値に現れる文字 { の直前の文字 & をエスケープすべきではない( HTML 4.0 勧告の B.7.1 節 を見よ)。 例えば, スタイルシートに次の開始タグが記述されている場合: The html output method should not escape a & character occurring in an attribute value immediately followed by a { character (see Section B.7.1 of the HTML 4.0 Recommendation). For example, a start-tag written in the stylesheet as

<BODY bgcolor='&amp;{{randomrbg}};'>

出力は次のようになるべきである: should be output as

<BODY bgcolor='&{randomrbg};'>

encoding 属性は、 HTML 出力メソッドに利用する望ましい文字エンコーディングを指定する。 HEAD 要素がある場合、 html 出力メソッドは HEAD 要素の開始タグの直後に META 要素を追加して, 実際に用いられる文字エンコーディングを指定すべきである。 例えば: The encoding attribute specifies the preferred encoding to be used. If there is a HEAD element, then the html output method should add a META element immediately after the start-tag of the HEAD element specifying the character encoding actually used. For example,

<HEAD>
<META http-equiv="Content-Type" content="text/html; charset=EUC-JP">
...

結果ツリーには、 XSLT プロセッサが出力に利用するエンコーディングで表現できない文字も含まれ得る。 この場合、 HTML において文字参照が認識され得る場所にその文字が現れるのであれば, 文字実体参照または十進コードによる文字参照として出力すべきである。 それ以外の場合(例えば script 要素や style 要素内, またはコメント内にその文字が現れた場合)、 XSLT プロセッサはエラーを通知すべきである。 It is possible that the result tree will contain a character that cannot be represented in the encoding that the XSLT processor is using for output. In this case, if the character occurs in a context where HTML recognizes character references, then the character should be output as a character entity reference or decimal numeric character reference; otherwise (for example, in a script or style element or in a comment), the XSLT processor should signal an error.

doctype-public 属性または doctype-system 属性が指定されている場合、 html 出力メソッドは最初の要素の直前に文書型宣言を出力すべきである。 <!DOCTYPE に後続する名前は、 HTML または html である。 doctype-public 属性も指定されている場合、出力メソッドは PUBLIC に続けて指定された公開識別子を出力すべきである。 doctype-system 属性も指定されている場合、公開識別子に続けてシステム識別子も出力すべきである。 doctype-system 属性は指定されているが, doctype-public 属性は指定されていない場合、出力メソッドは SYSTEM に続けて指定されたシステム識別子を出力すべきである。 If the doctype-public or doctype-system attributes are specified, then the html output method should output a document type declaration immediately before the first element. The name following <!DOCTYPE should be HTML or html. If the doctype-public attribute is specified, then the output method should output PUBLIC followed by the specified public identifier; if the doctype-system attribute is also specified, it should also output the specified system identifier following the public identifier. If the doctype-system attribute is specified but the doctype-public attribute is not specified, then the output method should output SYSTEM followed by the specified system identifier.

media-type 属性は html 出力メソッドに適用できる。 既定の値は text/html The media-type attribute is applicable for the html output method. The default value is text/html.

16.3 テキスト出力メソッド

テキスト出力メソッドにおける結果ツリーの出力では、エスケープ処理を施さずに, 結果ツリーの各テキストノードの文字列値を文書順に出力する。 The text output method outputs the result tree by outputting the string-value of every text node in the result tree in document order without any escaping.

media-type 属性はテキスト出力メソッドに適用できる。 既定の値は text/plain である。 The media-type attribute is applicable for the text output method. The default value for the media-type attribute is text/plain.

encoding 属性には、テキスト出力メソッドが文字列をバイト列に変換する際に利用するエンコーディングを指定する。 既定の値はシステム依存になる。 XSLT プロセッサが出力に利用するエンコーディングでは表現できない文字が結果ツリーに含まれている場合、 XSLT プロセッサはエラーを通知すべきである。 The encoding attribute identifies the encoding that the text output method should use to convert sequences of characters to sequences of bytes. The default is system-dependent. If the result tree contains a character that cannot be represented in the encoding that the XSLT processor is using for output, the XSLT processor should signal an error.

16.4 出力エスケープの無効化

通常, xml 出力メソッドによるテキストノードの出力においては、 & や < (あるいは他の文字も)にエスケープが施される。 このような処理により、出力結果は確実に整形式 XML になる。 しかしながら、出力結果が完全ではなくともほぼ整形式 XML になっていることが便利な場合もある。 例えば、後段の XML 非対応の処理プロセスで整形式 XML に変換することを意図して, 整形式でないセクションを出力結果に含める場合など。 このため XSLT では、出力エスケープを無効化する仕組みを提供している。 xsl:value-of 要素や xsl:text 要素には、 disable-output-escaping 属性を与えられる。 値は yes または no (既定値)のいずれかであり, yes だった場合、 xsl:value-of 要素や xsl:text 要素のインスタンス化により生成されるテキストノードは, エスケープ処理を施さずに出力すべきである。 例えば: Normally, the xml output method escapes & and < (and possibly other characters) when outputting text nodes. This ensures that the output is well-formed XML. However, it is sometimes convenient to be able to produce output that is almost, but not quite well-formed XML; for example, the output may include ill-formed sections which are intended to be transformed into well-formed XML by a subsequent non-XML aware process. For this reason, XSLT provides a mechanism for disabling output escaping. An xsl:value-of or xsl:text element may have a disable-output-escaping attribute; the allowed values are yes or no; the default is no; if the value is yes, then a text node generated by instantiating the xsl:value-of or xsl:text element should be output without any escaping. For example,

<xsl:text disable-output-escaping="yes">&lt;</xsl:text>

は、1個の文字 < を生成する。 ルートノードが xsl:copy-of 要素を用いて複製される際に( [11.3 xsl:copy-of における変数とパラメタの値の利用] を見よ), ルートノードの子孫のテキストノードに対するエスケープが無効化されている場合、それらのテキストノードの複製結果に対するエスケープも無効化されるべきである。 例えば: should generate the single character <. When a root node is copied using an xsl:copy-of element (see [11.3 Using Values of Variables and Parameters with xsl:copy-of]) and escaping was disabled for a text node descendant of that root node, then escaping should also be disabled for the resulting copy of that text node. For example


<xsl:variable name="x">
  <xsl:text disable-output-escaping="yes">&lt;</xsl:text>
</xsl:variable>
<xsl:copy-of select="$x"/>

&lt; でなく, < と出力されるべきである。 . should output < not &lt;.

結果ツリーのテキストノード以外の部分に利用されるテキストノードに対する出力エスケープの無効化は、エラーとする。 従って、コメント, 処理命令, 属性ノードの文字列値の生成に利用される xsl:value-of 要素や xsl:text 要素に対する出力エスケープの無効化もエラーとする。 また、エスケープ処理を無効化したテキストノードが含まれている 結果ツリー素片 を数値や文字列に変換しようとした場合もエラーとする。 いずれの場合も、 XSLT プロセッサはエラーを通知してもよい。 エラーを通知しない場合、 disable-output-escaping 属性を無視してエラーから回復しなければならない。 It is an error for output escaping to be disabled for a text node that is used for something other than a text node in the result tree. Thus, it is an error to disable output escaping for an xsl:value-of or xsl:text element that is used to generate the string-value of a comment, processing instruction or attribute node; it is also an error to convert a result tree fragment to a number or a string if the result tree fragment contains a text node for which escaping was disabled. In both cases, an XSLT processor may signal the error; if it does not signal the error, it must recover by ignoring the disable-output-escaping attribute.

disable-output-escaping 属性は、 xml 出力メソッドのみならず, html 出力メソッドでも利用できる。 テキスト出力メソッドでは、出力のエスケープ処理は行われないので disable-output-escaping 属性は無視される。 The disable-output-escaping attribute may be used with the html output method as well as with the xml output method. The text output method ignores the disable-output-escaping attribute, since it does not perform any output escaping.

XSLT プロセッサは、結果ツリーの出力を制御する場合にのみ, 出力エスケープを無効にできるが、例外もある。 例えば、結果ツリーは出力以外にも別の XSLT 変換のソースツリーとして利用し得る。 XSLT プロセッサには、出力エスケープの無効化のサポートは要求されていない。 xsl:value-ofxsl:text に出力エスケープを無効化すべきことが指定されていて, XSLT プロセッサがそれをサポートしていない場合、 XSLT プロセッサはエラーを通知してもよい。 エラーを通知しない場合、出力エスケープの無効化を行わないことにより, エラーから回復しなければならない。 An XSLT processor will only be able to disable output escaping if it controls how the result tree is output. This may not always be the case. For example, the result tree may be used as the source tree for another XSLT transformation instead of being output. An XSLT processor is not required to support disabling output escaping. If an xsl:value-of or xsl:text specifies that output escaping should be disabled and the XSLT processor does not support this, the XSLT processor may signal an error; if it does not signal an error, it must recover by not disabling output escaping.

XSLT プロセッサが出力に利用するエンコーディングで表現できない文字に対し, 出力エスケープが無効化されている場合、 XSLT プロセッサはエラーを通知してもよい。 エラーを通知しない場合、出力エスケープの無効化を行わないことにより, エラーから回復しなければならない。 If output escaping is disabled for a character that is not representable in the encoding that the XSLT processor is using for output, then the XSLT processor may signal an error; if it does not signal an error, it must recover by not disabling output escaping.

出力エスケープの無効化は、すべての XSLT プロセッサで働くとは限らない上に, XML の出力結果は整形式にならない可能性もあるので、この機能は他に選択肢が無い場合に限って利用すべきである。 Since disabling output escaping may not work with all XSLT processors and can result in XML that is not well-formed, it should be used only when there is no alternative.

17 適合性

適合 XSLT プロセッサは、この仕様の規定に従って, スタイルシートを利用してソースツリーを結果ツリーに変換できなければならない。 適合 XSLT プロセッサには、 XML またはその他の形式による結果の出力機能は要求されていない。 A conforming XSLT processor must be able to use a stylesheet to transform a source tree into a result tree as specified in this document. A conforming XSLT processor need not be able to output the result in XML or in any other form.

注記: XSLT プロセッサのベンダには、結果ツリーを XML として出力可能にしたり, DOM や SAX などの標準 API からの結果ツリーへのアクセスを提供することにより、プロセッサのふるまいの適合性を検証する手段を提供することが強く奨励される。 NOTE:Vendors of XSLT processors are strongly encouraged to provide a way to verify that their processor is behaving conformingly by allowing the result tree to be output as XML or by providing access to the result tree through a standard API such as the DOM or SAX.

適合 XSLT プロセッサは、この仕様でエラーを通知しなくてよいことを特に指定しているもの以外の, すべてのエラーを通知しなければならない。 適合 XSLT プロセッサは、通知したエラーから回復してもよいが, エラーからの回復は適合性の要件ではない。 A conforming XSLT processor must signal any errors except for those that this document specifically allows an XSLT processor not to signal. A conforming XSLT processor may but need not recover from any errors that it signals.

適合 XSLT プロセッサは、スタイルシートの処理に消費される処理演算リソースに制限を設けてもよい。 A conforming XSLT processor may impose limits on the processing resources consumed by the processing of a stylesheet.

18 表記法

XSLT で定義する要素型それぞれの仕様記述の最初に、その要素型の要素を見本にした構文の要約を与えている。 構文の要約における表記法の意味は、次のようになる: 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. The meaning of syntax summary notation is as follows:


A 参照文献

A.1 正式な参照文献

XML
World Wide Web Consortium. Extensible Markup Language (XML) 1.0. W3C Recommendation. See http://www.w3.org/TR/1998/REC-xml-19980210
XML11
World Wide Web Consortium. Extensible Markup Language (XML) 1.1. 1.0. W3C Recommendation. See http://www.w3.org/TR/xml11/
XML Names
World Wide Web Consortium. Namespaces in XML. W3C Recommendation. See http://www.w3.org/TR/REC-xml-names
XML Names 1.1
World Wide Web Consortium. Namespaces in XML 1.1. W3C Recommendation. See http://www.w3.org/TR/xml-names11/
XPath
World Wide Web Consortium. XML Path Language. W3C Recommendation. See http://www.w3.org/TR/xpath

A.2 その他の参照文献

CSS2
World Wide Web Consortium. Cascading Style Sheets, level 2 (CSS2). W3C Recommendation. See http://www.w3.org/TR/1998/REC-CSS2-19980512
DSSSL
International Organization for Standardization, International Electrotechnical Commission. ISO/IEC 10179:1996. Document Style Semantics and Specification Language (DSSSL). International Standard.
HTML
World Wide Web Consortium. HTML 4.0 specification. W3C Recommendation. See http://www.w3.org/TR/REC-html40
IANA
Internet Assigned Numbers Authority. Character Sets. See ftp://ftp.isi.edu/in-notes/iana/assignments/character-sets.
RFC2278
N. Freed, J. Postel. IANA Charset Registration Procedures. IETF RFC 2278. See http://www.ietf.org/rfc/rfc2278.txt.
RFC2376
E. Whitehead, M. Murata. XML Media Types. IETF RFC 2376. See http://www.ietf.org/rfc/rfc2376.txt.
RFC2396
T. Berners-Lee, R. Fielding, and L. Masinter. Uniform Resource Identifiers (URI): Generic Syntax. IETF RFC 2396. See http://www.ietf.org/rfc/rfc2396.txt.
UNICODE TR10
Unicode Consortium. Unicode Technical Report #10. Unicode Collation Algorithm. Unicode Technical Report. See http://www.unicode.org/unicode/reports/tr10/index.html.
XHTML
World Wide Web Consortium. XHTML 1.0: The Extensible HyperText Markup Language. W3C Proposed Recommendation. See http://www.w3.org/TR/xhtml1
XPointer
World Wide Web Consortium. XML Pointer Language (XPointer). W3C Working Draft. See http://www.w3.org/TR/xptr
XML Stylesheet
World Wide Web Consortium. Associating stylesheets with XML documents. W3C Recommendation. See http://www.w3.org/TR/xml-stylesheet
XSL
World Wide Web Consortium. Extensible Stylesheet Language (XSL). W3C Working Draft. See http://www.w3.org/TR/WD-xsl

B 要素構文要約

<!-- Category: instruction -->
<xsl:apply-imports />
<!-- Category: instruction -->
<xsl:apply-templates 
  select = node-set-expression 
  mode = qname>
  <!-- Content: (xsl:sort | xsl:with-param)* -->
</xsl:apply-templates>
<!-- Category: instruction -->
<xsl:attribute
  name = { qname }
  namespace = { uri-reference }>
  <!-- Content: template -->
</xsl:attribute>
<!-- Category: top-level-element -->
<xsl:attribute-set
  name = qname 
  use-attribute-sets = qnames>
  <!-- Content: xsl:attribute* -->
</xsl:attribute-set>
<!-- Category: instruction -->
<xsl:call-template
  name = qname>
  <!-- Content: xsl:with-param* -->
</xsl:call-template>
<!-- Category: instruction -->
<xsl:choose>
  <!-- Content: (xsl:when+, xsl:otherwise?) -->
</xsl:choose>
<!-- Category: instruction -->
<xsl:comment>
  <!-- Content: template -->
</xsl:comment>
<!-- Category: instruction -->
<xsl:copy 
  use-attribute-sets = qnames>
  <!-- Content: template -->
</xsl:copy>
<!-- Category: instruction -->
<xsl:copy-of
  select = expression />
<!-- Category: top-level-element -->
<xsl:decimal-format 
  name = qname 
  decimal-separator = char 
  grouping-separator = char 
  infinity = string 
  minus-sign = char 
  NaN = string 
  percent = char 
  per-mille = char 
  zero-digit = char 
  digit = char 
  pattern-separator = char />
<!-- Category: instruction -->
<xsl:element
  name = { qname }
  namespace = { uri-reference }
  use-attribute-sets = qnames>
  <!-- Content: template -->
</xsl:element>
<!-- Category: instruction -->
<xsl:fallback>
  <!-- Content: template -->
</xsl:fallback>
<!-- Category: instruction -->
<xsl:for-each
         select = node-set-expression>
  <!-- Content: (xsl:sort*, template) -->
</xsl:for-each>
<!-- Category: instruction -->
<xsl:if
         test = boolean-expression>
  <!-- Content: template -->
</xsl:if>
<xsl:import
         href = uri-reference />
<!-- Category: top-level-element -->
<xsl:include
         href = uri-reference />
<!-- Category: top-level-element -->
<xsl:key
  name = qname
         match = pattern
         use = expression />
<!-- Category: instruction -->
<xsl:message 
  terminate = "yes" | "no">
  <!-- Content: template -->
</xsl:message>
<!-- Category: top-level-element -->
<xsl:namespace-alias
         stylesheet-prefix = prefix | "#default"
  result-prefix = prefix | "#default" />
<!-- Category: instruction -->
<xsl:number 
  level = "single" | "multiple" | "any"
  count = pattern 
  from = pattern 
  value = number-expression 
  format = { string }
  lang = { nmtoken }
  letter-value = { "alphabetic" | "traditional" }
  grouping-separator = { char }
  grouping-size = { number } />
<xsl:otherwise>
  <!-- Content: template -->
</xsl:otherwise>
<!-- Category: top-level-element -->
<xsl:output 
  method = "xml" | "html" | "text" | qname-but-not-ncname 
  version = nmtoken 
  encoding = string 
  omit-xml-declaration = "yes" | "no"
  standalone = "yes" | "no"
  doctype-public = string 
  doctype-system = string 
  cdata-section-elements = qnames 
  indent = "yes" | "no"
  media-type = string />
<!-- Category: top-level-element -->
<xsl:param
  name = qname 
  select = expression>
  <!-- Content: template -->
</xsl:param>
<!-- Category: top-level-element -->
<xsl:preserve-space
         elements = tokens />
<!-- Category: instruction -->
<xsl:processing-instruction
  name = { ncname }>
  <!-- Content: template -->
</xsl:processing-instruction>
<xsl:sort 
  select = string-expression 
  lang = { nmtoken }
  data-type = { "text" | "number" | qname-but-not-ncname }
  order = { "ascending" | "descending" }
  case-order = { "upper-first" | "lower-first" } />
<!-- Category: top-level-element -->
<xsl:strip-space
         elements = tokens />
<xsl:stylesheet 
  id = id 
  extension-element-prefixes = tokens 
  exclude-result-prefixes = tokens
         version = number>
  <!-- Content: (xsl:import*, top-level-elements) -->
</xsl:stylesheet>
<!-- Category: top-level-element -->
<xsl:template 
  match = pattern 
  name = qname 
  priority = number 
  mode = qname>
  <!-- Content: (xsl:param*, template) -->
</xsl:template>
<!-- Category: instruction -->
<xsl:text 
  disable-output-escaping = "yes" | "no">
  <!-- Content: #PCDATA -->
</xsl:text>
<xsl:transform 
  id = id 
  extension-element-prefixes = tokens 
  exclude-result-prefixes = tokens
         version = number>
  <!-- Content: (xsl:import*, top-level-elements) -->
</xsl:transform>
<!-- Category: instruction -->
<xsl:value-of
         select = string-expression 
  disable-output-escaping = "yes" | "no" />
<!-- Category: top-level-element -->
<!-- Category: instruction -->
<xsl:variable
  name = qname 
  select = expression>
  <!-- Content: template -->
</xsl:variable>
<xsl:when
         test = boolean-expression>
  <!-- Content: template -->
</xsl:when>
<xsl:with-param
  name = qname 
  select = expression>
  <!-- Content: template -->
</xsl:with-param>

C XSLT スタイルシート用 DTD 素片(規定外)

注記: この DTD 素片は、正式ではない。 理由は、 XML 1.0 の DTD は XML 名前空間をサポートしていないため, XSLT スタイルシートが許容する構造を正しく記述できないためである。 NOTE:This DTD Fragment is not normative because XML 1.0 DTDs do not support XML Namespaces and thus cannot correctly describe the allowed structure of an XSLT stylesheet.

下の実体を、特定の結果 DTD のインスタンスを生成する XSLT スタイルシート用の DTD の構築に利用できる。 この実体が参照される前に、スタイルシート用の DTD に結果において許容される要素を列挙する result-elements パラメタ実体が定義されなければならない。 例えば: The following entity can be used to construct a DTD for XSLT stylesheets that create instances of a particular result DTD. Before referencing the entity, the stylesheet DTD must define a result-elements parameter entity listing the allowed result element types. For example:

<!ENTITY % result-elements "
  | fo:inline-sequence
  | fo:block
">

このような結果要素は、属性として xsl:use-attribute-setsxsl:extension-element-prefixes を持つことを宣言しておくべきである。 下の実体で、この目的に result-element-atts パラメタを宣言する。 XSLT が結果要素に許容する内容は、次の実体の中で内容モデル %template; を伴って宣言される XSLT の要素に対し許容される内容と同じである。 DTD では、結果 DTD にかけられる制約を反映させるため, %template; より制限が強い内容モデルを利用してもよい。 Such result elements should be declared to have xsl:use-attribute-sets and xsl:extension-element-prefixes attributes. The following entity declares the result-element-atts parameter for this purpose. The content that XSLT allows for result elements is the same as it allows for the XSLT elements that are declared in the following entity with a content model of %template;. The DTD may use a more restrictive content model than %template; to reflect the constraints of the result DTD.

この DTD では、 XSLT 名前空間以外の名前空間から追加のトップレベル要素を許容するために non-xsl-top-level パラメタ実体を定義してもよい。 The DTD may define the non-xsl-top-level parameter entity to allow additional top-level elements from namespaces other than the XSLT namespace.

この DTD は接頭辞 xsl: を利用しているが、 XSLT のスタイルシートでもこの接頭辞の利用が要求されるわけではない。 この DTD で宣言しているすべての要素は、この DTD で宣言される属性に加え, xmlns: から始まる名前の属性や名前が xmlns の属性を持ち得る。 The use of the xsl: prefix in this DTD does not imply that XSLT stylesheets are required to use this prefix. Any of the elements declared in this DTD may have attributes whose name starts with xmlns: or is equal to xmlns in addition to the attributes declared in this DTD.

<!ENTITY % char-instructions "
  | xsl:apply-templates
  | xsl:call-template
  | xsl:apply-imports
  | xsl:for-each
  | xsl:value-of
  | xsl:copy-of
  | xsl:number
  | xsl:choose
  | xsl:if
  | xsl:text
  | xsl:copy
  | xsl:variable
  | xsl:message
  | xsl:fallback
">

<!ENTITY % instructions "
  %char-instructions;
  | xsl:processing-instruction
  | xsl:comment
  | xsl:element
  | xsl:attribute
">

<!ENTITY % char-template "
 (#PCDATA
  %char-instructions;)*
">

<!ENTITY % template "
 (#PCDATA
  %instructions;
  %result-elements;)*
">

<!-- Used for the type of an attribute value that is a URI reference.-->
<!ENTITY % URI "CDATA">

<!-- Used for the type of an attribute value that is a pattern.-->
<!ENTITY % pattern "CDATA">

<!-- Used for the type of an attribute value that is an
     attribute value template.-->
<!ENTITY % avt "CDATA">

<!-- Used for the type of an attribute value that is a QName; the prefix
     gets expanded by the XSLT processor. -->
<!ENTITY % qname "NMTOKEN">

<!-- Like qname but a whitespace-separated list of QNames. -->
<!ENTITY % qnames "NMTOKENS">

<!-- Used for the type of an attribute value that is an expression.-->
<!ENTITY % expr "CDATA">

<!-- Used for the type of an attribute value that consists
     of a single character.-->
<!ENTITY % char "CDATA">

<!-- Used for the type of an attribute value that is a priority. -->
<!ENTITY % priority "NMTOKEN">

<!ENTITY % space-att "xml:space (default|preserve) #IMPLIED">

<!-- This may be overridden to customize the set of elements allowed
at the top-level. -->

<!ENTITY % non-xsl-top-level "">

<!ENTITY % top-level "
 (xsl:import*,
  (xsl:include
  | xsl:strip-space
  | xsl:preserve-space
  | xsl:output
  | xsl:key
  | xsl:decimal-format
  | xsl:attribute-set
  | xsl:variable
  | xsl:param
  | xsl:template
  | xsl:namespace-alias
  %non-xsl-top-level;)*)
">

<!ENTITY % top-level-atts '
  extension-element-prefixes CDATA #IMPLIED
  exclude-result-prefixes CDATA #IMPLIED
  id ID #IMPLIED
  version NMTOKEN #REQUIRED
  xmlns:xsl CDATA #FIXED "http://www.w3.org/1999/XSL/Transform"
  %space-att;
'>

<!-- This entity is defined for use in the ATTLIST declaration
for result elements. -->

<!ENTITY % result-element-atts '
  xsl:extension-element-prefixes CDATA #IMPLIED
  xsl:exclude-result-prefixes CDATA #IMPLIED
  xsl:use-attribute-sets %qnames; #IMPLIED
  xsl:version NMTOKEN #IMPLIED
'>

<!ELEMENT xsl:stylesheet %top-level;>
<!ATTLIST xsl:stylesheet %top-level-atts;>

<!ELEMENT xsl:transform %top-level;>
<!ATTLIST xsl:transform %top-level-atts;>

<!ELEMENT xsl:import EMPTY>
<!ATTLIST xsl:import href %URI; #REQUIRED>

<!ELEMENT xsl:include EMPTY>
<!ATTLIST xsl:include href %URI; #REQUIRED>

<!ELEMENT xsl:strip-space EMPTY>
<!ATTLIST xsl:strip-space elements CDATA #REQUIRED>

<!ELEMENT xsl:preserve-space EMPTY>
<!ATTLIST xsl:preserve-space elements CDATA #REQUIRED>

<!ELEMENT xsl:output EMPTY>
<!ATTLIST xsl:output
  method %qname; #IMPLIED
  version NMTOKEN #IMPLIED
  encoding CDATA #IMPLIED
  omit-xml-declaration (yes|no) #IMPLIED
  standalone (yes|no) #IMPLIED
  doctype-public CDATA #IMPLIED
  doctype-system CDATA #IMPLIED
  cdata-section-elements %qnames; #IMPLIED
  indent (yes|no) #IMPLIED
  media-type CDATA #IMPLIED
>

<!ELEMENT xsl:key EMPTY>
<!ATTLIST xsl:key
  name %qname; #REQUIRED
  match %pattern; #REQUIRED
  use %expr; #REQUIRED
>

<!ELEMENT xsl:decimal-format EMPTY>
<!ATTLIST xsl:decimal-format
  name %qname; #IMPLIED
  decimal-separator %char; "."
  grouping-separator %char; ","
  infinity CDATA "Infinity"
  minus-sign %char; "-"
  NaN CDATA "NaN"
  percent %char; "%"
  per-mille %char; "&#x2030;"
  zero-digit %char; "0"
  digit %char; "#"
  pattern-separator %char; ";"
>

<!ELEMENT xsl:namespace-alias EMPTY>
<!ATTLIST xsl:namespace-alias
  stylesheet-prefix CDATA #REQUIRED
  result-prefix CDATA #REQUIRED
>

<!ELEMENT xsl:template
 (#PCDATA
  %instructions;
  %result-elements;
  | xsl:param)*
>

<!ATTLIST xsl:template
  match %pattern; #IMPLIED
  name %qname; #IMPLIED
  priority %priority; #IMPLIED
  mode %qname; #IMPLIED
  %space-att;
>

<!ELEMENT xsl:value-of EMPTY>
<!ATTLIST xsl:value-of
  select %expr; #REQUIRED
  disable-output-escaping (yes|no) "no"
>

<!ELEMENT xsl:copy-of EMPTY>
<!ATTLIST xsl:copy-of select %expr; #REQUIRED>

<!ELEMENT xsl:number EMPTY>
<!ATTLIST xsl:number
   level (single|multiple|any) "single"
   count %pattern; #IMPLIED
   from %pattern; #IMPLIED
   value %expr; #IMPLIED
   format %avt; '1'
   lang %avt; #IMPLIED
   letter-value %avt; #IMPLIED
   grouping-separator %avt; #IMPLIED
   grouping-size %avt; #IMPLIED
>

<!ELEMENT xsl:apply-templates (xsl:sort|xsl:with-param)*>
<!ATTLIST xsl:apply-templates
  select %expr; "node()"
  mode %qname; #IMPLIED
>

<!ELEMENT xsl:apply-imports EMPTY>

<!-- xsl:sort cannot occur after any other elements or
any non-whitespace character -->

<!ELEMENT xsl:for-each
 (#PCDATA
  %instructions;
  %result-elements;
  | xsl:sort)*
>

<!ATTLIST xsl:for-each
  select %expr; #REQUIRED
  %space-att;
>

<!ELEMENT xsl:sort EMPTY>
<!ATTLIST xsl:sort
  select %expr; "."
  lang %avt; #IMPLIED
  data-type %avt; "text"
  order %avt; "ascending"
  case-order %avt; #IMPLIED
>

<!ELEMENT xsl:if %template;>
<!ATTLIST xsl:if
  test %expr; #REQUIRED
  %space-att;
>

<!ELEMENT xsl:choose (xsl:when+, xsl:otherwise?)>
<!ATTLIST xsl:choose %space-att;>

<!ELEMENT xsl:when %template;>
<!ATTLIST xsl:when
  test %expr; #REQUIRED
  %space-att;
>

<!ELEMENT xsl:otherwise %template;>
<!ATTLIST xsl:otherwise %space-att;>

<!ELEMENT xsl:attribute-set (xsl:attribute)*>
<!ATTLIST xsl:attribute-set
  name %qname; #REQUIRED
  use-attribute-sets %qnames; #IMPLIED
>

<!ELEMENT xsl:call-template (xsl:with-param)*>
<!ATTLIST xsl:call-template
  name %qname; #REQUIRED
>

<!ELEMENT xsl:with-param %template;>
<!ATTLIST xsl:with-param
  name %qname; #REQUIRED
  select %expr; #IMPLIED
>

<!ELEMENT xsl:variable %template;>
<!ATTLIST xsl:variable 
  name %qname; #REQUIRED
  select %expr; #IMPLIED
>

<!ELEMENT xsl:param %template;>
<!ATTLIST xsl:param 
  name %qname; #REQUIRED
  select %expr; #IMPLIED
>

<!ELEMENT xsl:text (#PCDATA)>
<!ATTLIST xsl:text
  disable-output-escaping (yes|no) "no"
>

<!ELEMENT xsl:processing-instruction %char-template;>
<!ATTLIST xsl:processing-instruction 
  name %avt; #REQUIRED
  %space-att;
>

<!ELEMENT xsl:element %template;>
<!ATTLIST xsl:element 
  name %avt; #REQUIRED
  namespace %avt; #IMPLIED
  use-attribute-sets %qnames; #IMPLIED
  %space-att;
>

<!ELEMENT xsl:attribute %char-template;>
<!ATTLIST xsl:attribute 
  name %avt; #REQUIRED
  namespace %avt; #IMPLIED
  %space-att;
>

<!ELEMENT xsl:comment %char-template;>
<!ATTLIST xsl:comment %space-att;>

<!ELEMENT xsl:copy %template;>
<!ATTLIST xsl:copy
  %space-att;
  use-attribute-sets %qnames; #IMPLIED
>

<!ELEMENT xsl:message %template;>
<!ATTLIST xsl:message
  %space-att;
  terminate (yes|no) "no"
>

<!ELEMENT xsl:fallback %template;>
<!ATTLIST xsl:fallback %space-att;>

D 例(規定外)

D.1 文書例

この例は単純な DTD に適合する文書を XHTML [XHTML] へ変換するスタイルシートである。 DTD は: This example is a stylesheet for transforming documents that conform to a simple DTD into XHTML [XHTML]. The DTD is:

<!ELEMENT doc (title, chapter*)>
<!ELEMENT chapter (title, (para|note)*, section*)>
<!ELEMENT section (title, (para|note)*)>
<!ELEMENT title (#PCDATA|emph)*>
<!ELEMENT para (#PCDATA|emph)*>
<!ELEMENT note (#PCDATA|emph)*>
<!ELEMENT emph (#PCDATA|emph)*>

スタイルシートは: The stylesheet is:

<xsl:stylesheet version="1.0"
                xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
                xmlns="http://www.w3.org/TR/xhtml1/strict">

<xsl:strip-space elements="doc chapter section"/>
<xsl:output
   method="xml"
   indent="yes"
   encoding="iso-8859-1"
/>

<xsl:template match="doc">
 <html>
   <head>
     <title>
       <xsl:value-of select="title"/>
     </title>
   </head>
   <body>
     <xsl:apply-templates/>
   </body>
 </html>
</xsl:template>

<xsl:template match="doc/title">
  <h1>
    <xsl:apply-templates/>
  </h1>
</xsl:template>

<xsl:template match="chapter/title">
  <h2>
    <xsl:apply-templates/>
  </h2>
</xsl:template>

<xsl:template match="section/title">
  <h3>
    <xsl:apply-templates/>
  </h3>
</xsl:template>

<xsl:template match="para">
  <p>
    <xsl:apply-templates/>
  </p>
</xsl:template>

<xsl:template match="note">
  <p class="note">
    <b>NOTE: </b>
    <xsl:apply-templates/>
  </p>
</xsl:template>

<xsl:template match="emph">
  <em>
    <xsl:apply-templates/>
  </em>
</xsl:template>

</xsl:stylesheet>

次の入力の文書: With the following input document

<!DOCTYPE doc SYSTEM "doc.dtd">
<doc>
<title>Document Title</title>
<chapter>
<title>Chapter Title</title>
<section>
<title>Section Title</title>
<para>This is a test.</para>
<note>This is a note.</note>
</section>
<section>
<title>Another Section Title</title>
<para>This is <emph>another</emph> test.</para>
<note>This is another note.</note>
</section>
</chapter>
</doc>

から、次の結果が生成される: it would produce the following result

<?xml version="1.0" encoding="iso-8859-1"?>
<html xmlns="http://www.w3.org/TR/xhtml1/strict">
<head>
<title>Document Title</title>
</head>
<body>
<h1>Document Title</h1>
<h2>Chapter Title</h2>
<h3>Section Title</h3>
<p>This is a test.</p>
<p class="note">
<b>NOTE: </b>This is a note.</p>
<h3>Another Section Title</h3>
<p>This is <em>another</em> test.</p>
<p class="note">
<b>NOTE: </b>This is another note.</p>
</body>
</html>

D.2 データ例

この節では XML で表現されているデータを異なる3つの XSLT スタイルシートを用いて変換し、異なる3つのデータ表現 HTML, SVG, VRML を生成する例を示す。 This is an example of transforming some data represented in XML using three different XSLT stylesheets to produce three different representations of the data, HTML, SVG and VRML.

入力データは: The input data is:

<sales>

        <division id="North">
                <revenue>10</revenue>
                <growth>9</growth>
                <bonus>7</bonus>
        </division>

        <division id="South">
                <revenue>4</revenue>
                <growth>3</growth>
                <bonus>4</bonus>
        </division>

        <division id="West">
                <revenue>6</revenue>
                <growth>-1.5</growth>
                <bonus>2</bonus>
        </division>

</sales>

次のスタイルシートは [2.3 スタイルシートとしてのリテラル結果要素] で述べられた簡略構文を用いてデータを HTML に変換する: The following stylesheet, which uses the simplified syntax described in [2.3 Literal Result Element as Stylesheet], transforms the data into HTML:

<html xsl:version="1.0"
      xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
      lang="en">
    <head>
        <title>Sales Results By Division</title>
    </head>
    <body>
        <table border="1">
            <tr>
                <th>Division</th>
                <th>Revenue</th>
                <th>Growth</th>
                <th>Bonus</th>
            </tr>
            <xsl:for-each select="sales/division">
                <!-- order the result by revenue -->
                <xsl:sort select="revenue"
                          data-type="number"
                          order="descending"/>
                <tr>
                    <td>
                        <em><xsl:value-of select="@id"/></em>
                    </td>
                    <td>
                        <xsl:value-of select="revenue"/>
                    </td>
                    <td>
                        <!-- highlight negative growth in red -->
                        <xsl:if test="growth &lt; 0">
                             <xsl:attribute name="style">
                                 <xsl:text>color:red</xsl:text>
                             </xsl:attribute>
                        </xsl:if>
                        <xsl:value-of select="growth"/>
                    </td>
                    <td>
                        <xsl:value-of select="bonus"/>
                    </td>
                </tr>
            </xsl:for-each>
        </table>
    </body>
</html>

出力される HTML は: The HTML output is:

<html lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>Sales Results By Division</title>
</head>
<body>
<table border="1">
<tr>
<th>Division</th><th>Revenue</th><th>Growth</th><th>Bonus</th>
</tr>
<tr>
<td><em>North</em></td><td>10</td><td>9</td><td>7</td>
</tr>
<tr>
<td><em>West</em></td><td>6</td><td style="color:red">-1.5</td><td>2</td>
</tr>
<tr>
<td><em>South</em></td><td>4</td><td>3</td><td>4</td>
</tr>
</table>
</body>
</html>

次のスタイルシートはデータを SVG に変換する: The following stylesheet transforms the data into SVG:

<xsl:stylesheet version="1.0"
                xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
                xmlns="http://www.w3.org/Graphics/SVG/SVG-19990812.dtd">

<xsl:output method="xml" indent="yes" media-type="image/svg"/>

<xsl:template match="/">

<svg width = "3in" height="3in">
    <g style = "stroke: #000000"> 
        <!-- draw the axes -->
        <line x1="0" x2="150" y1="150" y2="150"/>
        <line x1="0" x2="0" y1="0" y2="150"/>
        <text x="0" y="10">Revenue</text>
        <text x="150" y="165">Division</text>
        <xsl:for-each select="sales/division">
            <!-- define some useful variables -->

            <!-- the bar's x position -->
            <xsl:variable name="pos"
                          select="(position()*40)-30"/>

            <!-- the bar's height -->
            <xsl:variable name="height"
                          select="revenue*10"/>

            <!-- the rectangle -->
            <rect x="{$pos}" y="{150-$height}"
                  width="20" height="{$height}"/>

            <!-- the text label -->
            <text x="{$pos}" y="165">
                <xsl:value-of select="@id"/>
            </text> 

            <!-- the bar value -->
            <text x="{$pos}" y="{145-$height}">
                <xsl:value-of select="revenue"/>
            </text>
        </xsl:for-each>
    </g>
</svg>

</xsl:template>
</xsl:stylesheet>

出力される SVG は: The SVG output is:

<svg width="3in" height="3in"
     xmlns="http://www.w3.org/Graphics/SVG/svg-19990412.dtd">
    <g style="stroke: #000000">
        <line x1="0" x2="150" y1="150" y2="150"/>
        <line x1="0" x2="0" y1="0" y2="150"/>
        <text x="0" y="10">Revenue</text>
        <text x="150" y="165">Division</text>
        <rect x="10" y="50" width="20" height="100"/>
        <text x="10" y="165">North</text>
        <text x="10" y="45">10</text>
        <rect x="50" y="110" width="20" height="40"/>
        <text x="50" y="165">South</text>
        <text x="50" y="105">4</text>
        <rect x="90" y="90" width="20" height="60"/>
        <text x="90" y="165">West</text>
        <text x="90" y="85">6</text>
    </g>
</svg>

次のスタイルシートはデータを VRML に変換する: The following stylesheet transforms the data into VRML:

<xsl:stylesheet version="1.0"
                xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

<!-- generate text output as mime type model/vrml, using default charset -->
<xsl:output method="text" encoding="UTF-8" media-type="model/vrml"/>  

        <xsl:template match="/">#VRML V2.0 utf8 
 
# externproto definition of a single bar element 
EXTERNPROTO bar [ 
  field SFInt32 x  
  field SFInt32 y  
  field SFInt32 z  
  field SFString name  
  ] 
  "http://www.vrml.org/WorkingGroups/dbwork/barProto.wrl" 
 
# inline containing the graph axes 
Inline {  
        url "http://www.vrml.org/WorkingGroups/dbwork/barAxes.wrl" 
        } 
        
                <xsl:for-each select="sales/division">
bar {
        x <xsl:value-of select="revenue"/>
        y <xsl:value-of select="growth"/>
        z <xsl:value-of select="bonus"/>
        name "<xsl:value-of select="@id"/>" 
        }
                </xsl:for-each>
        
        </xsl:template> 
 
</xsl:stylesheet>

出力される VRML は: The VRML output is:

#VRML V2.0 utf8 
 
# externproto definition of a single bar element 
EXTERNPROTO bar [ 
  field SFInt32 x  
  field SFInt32 y  
  field SFInt32 z  
  field SFString name  
  ] 
  "http://www.vrml.org/WorkingGroups/dbwork/barProto.wrl" 
 
# inline containing the graph axes 
Inline {  
        url "http://www.vrml.org/WorkingGroups/dbwork/barAxes.wrl" 
        } 
        
                
bar {
        x 10
        y 9
        z 7
        name "North" 
        }
                
bar {
        x 4
        y 3
        z 4
        name "South" 
        }
                
bar {
        x 6
        y -1.5
        z 2
        name "West" 
        }

E 謝辞(規定外)

The following have contributed to authoring this draft:

  • Daniel Lipkin, Saba
  • Jonathan Marsh, Microsoft
  • Henry Thompson, University of Edinburgh
  • Norman Walsh, Arbortext
  • Steve Zilles, Adobe

This specification was developed and approved for publication by the W3C XSL Working Group (WG). WG approval of this specification does not necessarily imply that all WG members voted for its approval. The current members of the XSL WG are:

Sharon Adler, IBM (Co-Chair); Anders Berglund, IBM; Perin Blanchard, Novell; Scott Boag, Lotus; Larry Cable, Sun; Jeff Caruso, Bitstream; James Clark; Peter Danielsen, Bell Labs; Don Day, IBM; Stephen Deach, Adobe; Dwayne Dicks, SoftQuad; Andrew Greene, Bitstream; Paul Grosso, Arbortext; Eduardo Gutentag, Sun; Juliane Harbarth, Software AG; Mickey Kimchi, Enigma; Chris Lilley, W3C; Chris Maden, Exemplary Technologies; Jonathan Marsh, Microsoft; Alex Milowski, Lexica; Steve Muench, Oracle; Scott Parnell, Xerox; Vincent Quint, W3C; Dan Rapp, Novell; Gregg Reynolds, Datalogics; Jonathan Robie, Software AG; Mark Scardina, Oracle; Henry Thompson, University of Edinburgh; Philip Wadler, Bell Labs; Norman Walsh, Arbortext; Sanjiva Weerawarana, IBM; Steve Zilles, Adobe (Co-Chair) , Boris Moore, RivCom

F 勧告案からの変更点(規定外)

The following are the changes since the Proposed Recommendation:

G XSLT の将来版に検討中の機能(規定外)

The following features are under consideration for versions of XSLT after XSLT 1.0:

  • a conditional expression;

  • support for XML Schema datatypes and archetypes;

  • support for something like style rules in the original XSL submission;

  • an attribute to control the default namespace for names occurring in XSLT attributes;

  • support for entity references;

  • support for DTDs in the data model;

  • support for notations in the data model;

  • a way to get back from an element to the elements that reference it (e.g. by IDREF attributes);

  • an easier way to get an ID or key in another document;

  • support for regular expressions for matching against any or all of text nodes, attribute values, attribute names, element type names;

  • case-insensitive comparisons;

  • normalization of strings before comparison, for example for compatibility characters;

  • a function string resolve(node-set) function that treats the value of the argument as a relative URI and turns it into an absolute URI using the base URI of the node;

  • multiple result documents;

  • defaulting the select attribute on xsl:value-of to the current node;

  • an attribute on xsl:attribute to control how the attribute value is normalized;

  • additional attributes on xsl:sort to provide further control over sorting, such as relative order of scripts;

  • a way to put the text of a resource identified by a URI into the result tree;

  • allow unions in steps (e.g. foo/(bar|baz));

  • allow for result tree fragments all operations that are allowed for node-sets;

  • a way to group together consecutive nodes having duplicate subelements or attributes;

  • features to make handling of the HTML style attribute more convenient.