XSLT3.0への道(28) パッケージとは何なのか?..

そもそもパッケージとは何なのでしょうか? Saxonのメーリングリストなんかを見ているとMichael Kay博士はまずXSLT 3.0の記述を読んでほしいといっています.という訳で、2.8 Packages and Modulesを自分なりに訳してみました.

In previous versions of the XSLT language,it has been possible to structure a stylesheet as a collection of modules,using the xsl:include and xsl:import declarations to express the dependency ofon module on others.

 

以前のバージョンのXSLTスタイルシートでは、スタイルシートをモジュールの集まりとして構成することができました.それにはxsl:includexsl:import宣言を使い、他のモジュールに対する依存性を表現することができたのです.

 

In XSLT 3.0 an additional layer ofmodularization of stylesheet code is enabled through the introduction ofpackages. A package is a collection of stylesheet modules with a controlledinterface to the packages that use it: for example, it defines which functionsand templates defined in the package are visible to callers, which are purelyinternal, and which are not only public but capable of being overridden byother functions and templates supplied by the using package.

 

XSLT 3.0ではパッケージの導入により更なる階層のモジュール化が可能となりました.パッケージはスタイルシートモジュールの集合であり、それを使うのにパッケージに対する管理されたインタフェースを併せ持ちます.例えば、(パッケージは)どのパッケージの中の関数、テンプレートが呼び出し側に対して見えるのか、どれが純粋に内部的なのか、そしてどれがパブリックであるだけでなく、他のそれを使用するパッケージの側の関数やテンプレートでオーバライド可能であるかを規定します.

 

Packages are introduced with severalmotivations, which broadly divide into two categories:

 

パッケージはいくつかの理由により導入されています、それらは大きくいって2つのカテゴリに分類されます.


1. Software engineering benefits:greater re-use of code, greater robustness through ease of testing, controlledevolution of code in response to new requirements, ability to deliver code thatusers cannot see or modify.


2. Efficiency benefits: theability to avoid compiling libraries repeatedly when they are used in multiplestylesheets, and to avoid holding multiple copies of the same library in memorysimultaneously.

 

1. ソフトウェアエンジニアリングにおける利点:コードの再利用性を増し、テストの容易さにおける強固さ、新たな要求に対する回答としてのコントロールされた進化、コードをユーザーが中身を見ることができたり改変されることなく配布する能力


2.効率の利点: 複数のスタイルシートで使用される場合、ライブラリを繰り返しコンパイルすることを避け、またメモリー中に同じライブラリのコピーを保持することを避ける能力
 

Packages are designed to allow separatecompilation: that is, a package can be compiled independently of the packagesthat use it. This specification does not define a process model forcompilation, or expand on what it means to compile different packagesindependently. Nor does it mandate that implementations offer any feature alongthese lines. It merely defines language features that are designed to makeseparate compilation of packages possible.

 

パッケージは分割コンパイルできるように設計されています: これはパッケージがそれを使うパッケージとは独立してコンパイルできることを意味します.この仕様はコンパイルの過程も、また更に、異なったパッケージを独立してコンパイルすることが意味することも規定していません.またインプリメンテーションがこれらの指針に対してどのような特徴を提供すべきことも指示していません.仕様はただパッケージの分割コンパイルをできるように言語の特徴を規定しているだけです.

 
To achieve this, packages (unlike modules):

これを実現するため、モジュールと異なりパッケージは

・ Must not contain unresolved references to functions, templates, orvariables declared in other packages;

・ Have strict rules governing the ability to override declarations ina library package with declarations in a package that uses the library;

・ Constrain the visibility of component names and of contextdeclarations such as the declarations of keys and decimal formats;

・ Can declare a mode (a collection of template rules) as final, whichdisallows the addition of new overriding template rules in a using package;

・ Require explicit disambiguation where naming conflicts arise, forexample when a package uses two other packages that both export like-namedcomponents;

・ Allow multiple specializations of library components to coexist inthe same application.

 

・ 他のパッケージで宣言された、未解決の関数、テンプレート、変数を含んでいてはなりません.

・ ライブラリパッケージの中で、それを使用するパッケージの宣言と共に、宣言をオーバーライドするための厳格な規則を持っていなければなりません.

・ キーの宣言や、decimalformatのようにコンポーネント名や、コンテキストの宣言で可視性に制約を加えられなければなりません.

・ パッケージを使用する際、追加や新規のオーバーライドを不可とするfinalモードを宣言できなければなりません.

・ 名前付けの競合が発生した場合、あいまいなく解決する明確さが必要です.例えば、パッケージが同じ名前付けをされたエキスポートを持った他のパッケージを使用する場合です.

・ 同じアプリケーションの中で、複数のライブラリコンポーネントの特殊化を許すことができなければなりません.

 

A package is defined in XSLT by means of anXML document whose outermost element is an xsl:package element. This isreferred to as the package manifest. The xsl:package element has optional childelements xsl:use-package and xsl:expose describing properties of the package.The package manifest may refer to an external top-level stylesheet module usingan xsl:include or xsl:import declaration, or it may contain the body of astylesheet module inline (the two approaches can also be mixed).

 

パッケージはXSLTにより、最上位がxsl:package要素であるXMLドキュメントとして定義されています.これはパッケージマニフェストとして参照されます.xsl:package要素は、パッケージのプロパティを記述するオプションの子要素として、xsl:use-packagexsl:exposeを持ちます.パッケージマニフェストは他のスタイルシートモジュールを、xsl:includexsl:import宣言で参照するかもしれません.またスタイルシート本体のを内部に持つかもしれません.(これらの方法は混在して使用できます)

 

Although this specification definespackages as constructs written using a defined XSLT syntax, implementations mayprovide mechanisms that allow packages to be written using other languages (forexample, XQuery).

 

この仕様はパッケージがXSLTの文法で書かれていることとして構成されています.インプリメンテーションはXQueryなど他の言語で書かれているパッケージの提供を許す構造を提供することがあるかもしれません.

 

When no packages are explicitly defined,the entire stylesheet is treated as a single package; the effect is as if thexsl:stylesheet or xsl:transform element of the principal stylesheet module werereplaced by an xsl:package element with no other information in the packagemanifest.

 

パッケージが明示的に定義されない場合、すべてのスタイルシートは単一のパッケージとして扱われます.これは大本のxsl:stylesheetxsl:transform要素が他のパッケージマニフェストの情報を持たないxsl:packageとして置き換えられたものとして扱われます.

 
 ウーム、読めば読むほどなかなか奥深いのですが、やはり実際にやってみないといまいちここに書かれていることも身をもってわかることはできないようです.