プログラミング言語処理系論 (7) Design and Implementation of Programming Language Processors 佐藤周行 ( 情報基盤センター / 電気系専攻融合情報学コース ) 1
Why XSLT? この時間 ( と次の時間 ) は Formal な言語仕様を読めるようになる ための 直感的な理解を助けるために割かれます Formal な定義はここ http://www.w3.org/tr/xslt20/ XML 技術の中で XSLT がどのような位置を占めるかについては少し解説します 2
Motivation XML 処理の重要性は飛躍的に高まっている よくみるプログラミング言語をターゲットにしても面白くないので 変わった ものを解析してみよう 処理ターゲット プログラミングの仕方 プログラムの書き方 最適化 実行モデルの理解が必要 最初は手で書き換えてかまわない ( 職人プログラマのやり方 ) 3
SOA and Web Services SOA (Service Oriented Architecture) では XMLが流通データ XMLを中心として 今までの技術が再構成されている ( 別に新たに発明されているわけではない ) Describe XML Doc. Search transform XSD XQuery XPath XSLT 4
WS-* on XML Web Services SOAP UDDI WSDL XML 5
XSLT とは 以下の意味で XML プログラミング処理系 XSL スタイルシート as プログラム XML XML への 変換 系 見栄えをよくするためのフォーマット情報の埋め込み 人が関与する ドキュメントの構造の変換 マシンどうしのデータのやりとりに必須 情報の抽出 情報の組み立て 6
XSL and XSLT Very Simple to Parse (just XML) XMLのパーサを書いてみよう それで言語のパースは終わり A Programming Language on XML Informal Semantics, but well Described. XSLT Processors at Hand! No Need of Installation. (MSXML) 7
Examples inp.xml table.xml books.xml 8
9
References XSLT 2.0 and XPath 2.0 Michael Kay, WROX Press, 2008 XSLT (2 nd Ed.) Doug Tidwell, O Reilly, 2008 XSLT Cookbook (2 nd Ed.) Sal Mangano, O Reilly, 2005 10
What is XSLT? extensible Stylesheet Language Transformation A transformation expressed in XSLT describes rules for transforming a source tree into a result tree. Show by Example: 11
12
13
14
Why XSLT Designed? Requirements of XML o Data とその表現を分離する o Data は プログラムどうしで受け渡されることのほうが多い XML Fixed, and Transformer Designed XSLT (to HTML, PDF, ) 15
Systems for XML Handling XSLT XQuery XML as Semi-Structured DataBase Rigid Formal Semantics is Given with Type System. XPath Navigation in XML 16
How XSLT Works A transformation expressed in XSLT = a source XML tree a result tree への変換 扱う対象 (object) は XML Tree XML XML 17
How XSLT Works? (2) 変換 は XML のパターンを特定して そこに別のパターンを当てはめることで行なう 変換パターン を記述するものを template という 18
Template Match 19
How XSLT Works (3) A pattern matches against elements in the source tree. A template is instantiated to create part of the result tree. 20
21
22
StyleSheet A Key Idea A transformation expressed in XSLT is called a stylesheet. ( プログラム!) A stylesheet contains a set of template rules. A template rule has two parts: (1) a pattern which matches against nodes in the source tree and (2) a template which can be instantiated to form part of the result tree. 23
Execution Model The result tree is constructed by (1) finding the template rule for the root node and (2) instantiating its template. 24
Instantiating a Template When a template is instantiated, each instruction is executed and replaced by the result tree fragment that it creates. contents of template = Instructions (explained later) Literal Result Element(Data) 25
26
Instantiating a Template (2) 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. 27
Programming Style (Digression) Push Processing -- Just call <xsl:apply-templates/> Execution (1) Select All Children, (2) Push Them to the Stylesheet, and (3) Let the Stylesheet Select Appropriate Templates 28
29
Programming Style (2) Pull Processing -- Select a Class of Specific Nodes as <xsl:apply-templates select= /> Execution (1) Select Specific Nodes, (2) Pull a Specific Template for their Processing 30
31
Key Ideas in Execution Template Instantiation により実行される Elements are only processed when they have been selected by execution of an instruction. Selection Schema is Critical XPathの実行効率が非常に重要 32
Templates, Expressions, Datatypes So much for Templates Templates = Functions in Traditional Sense. Remaining Part of Programming Languages Expressions and Datatypes 33
続きは次回 次回の予告 XSLT における変数 XPATH Details of XSLT Control Structure 34