Скачать презентацию Copyright 2001 Active State XSLT and Scripting Скачать презентацию Copyright 2001 Active State XSLT and Scripting

48f4cfe685c44b996bf1e4ff9ac43445.ppt

  • Количество слайдов: 51

Copyright 2001, Active. State Copyright 2001, Active. State

XSLT and Scripting Languages or…XSLT: what is everyone so hot and bothered about? Copyright XSLT and Scripting Languages or…XSLT: what is everyone so hot and bothered about? Copyright 2001, Active. State

Background: Active. State • Active. State creates tools for open source and standards-based high-level Background: Active. State • Active. State creates tools for open source and standards-based high-level languages: – Perl – Python – PHP – XSLT – Tcl Copyright 2001, Active. State

What is XSLT? • A language for transforming between XML vocabularies. • Standardized by What is XSLT? • A language for transforming between XML vocabularies. • Standardized by the World Wide Web Consortium • Integrated with. NET, Apache, IE, Java, Oracle, Perl, Python, … Copyright 2001, Active. State

XSLT • XSLT is a slightly new twist: – Not a scripting language – XSLT • XSLT is a slightly new twist: – Not a scripting language – Not, strictly-speaking, “open source” • But not radically different: – Typically interpreted – Open source implementations – Not vendor dominated Copyright 2001, Active. State

Programming Language? – XSLT has • looping constructs • function calling • variables • Programming Language? – XSLT has • looping constructs • function calling • variables • parameters • math functions • module combination • … Copyright 2001, Active. State

Looping in XSLT • xsl: for-each lets us do the same thing for many Looping in XSLT • xsl: for-each lets us do the same thing for many nodes • The body of the xsl: for-each is a full template • It is instantiated once for each match • Each time a different node is the "current" node Copyright 2001, Active. State

Example of Iterating: XML <people> <person><name>Paul Prescod</name> <role>Snake Charmer</role> </person> <person><name>Gisle Aas</name> <role>Camel Herder</role> Example of Iterating: XML Paul Prescod Snake Charmer Gisle Aas Camel Herder Copyright 2001, Active. State

Example of Iterating: XSLT
Copyright 2001, Active. State

Copyright 2001, Active. State Copyright 2001, Active. State

HTML Output <TABLE> <TR><TD>Paul Prescod</TD> <TD>Snake Charmer</TD> </TR> <TR><TD>Gisle Aas</TD> <TD>Camel Herder</TD> </TR> </TABLE> HTML Output

Paul Prescod Snake Charmer
Gisle Aas Camel Herder
Copyright 2001, Active. State

Calling Functions • What if you wanted to do this in XSLT: func myfunction(arg Calling Functions • What if you wanted to do this in XSLT: func myfunction(arg 1, arg 2){ …do something with params… } myfunction(“ 54”, “ 42”) Copyright 2001, Active. State

Functions, Parameters, Variables Copyright 2001, Active. State

Template Call Copyright 2001, Active. State

Copyright 2001, Active. State Copyright 2001, Active. State

Bottom Line • XSLT can be used to compute anything that can be computed Bottom Line • XSLT can be used to compute anything that can be computed • It is “Turing complete” • But…. – Certain coding paradigms are VERY awkward – Non-textual Input/Output is typically not possible Copyright 2001, Active. State

Scripting Languages • Scripting languages are designed to be general purpose • “Modern” scripting Scripting Languages • Scripting languages are designed to be general purpose • “Modern” scripting languages go well beyond “scripting” • They are general purpose multiparadigm languages – But XSLT wins for specificity Copyright 2001, Active. State

XSLT XML Support • XSLT has deep native support for XML • “Built-in”, highly XSLT XML Support • XSLT has deep native support for XML • “Built-in”, highly consistent parser • “XPath” XML navigation (“query”) language • Special syntax for working with elements Copyright 2001, Active. State

XML Recursion • XSLT makes input-based recursion easy: – Sections within sections within … XML Recursion • XSLT makes input-based recursion easy: – Sections within sections within … – Part descriptions within part descriptions … • XSLT automatically selects the right rule to go with the right element in the input document Copyright 2001, Active. State

Context • XSLT keeps track of context: namespaces, current node list etc. • Relevant Context • XSLT keeps track of context: namespaces, current node list etc. • Relevant contexts are in both the stylesheet and the document. • In most traditional programming languages, the programmer would have to be explicit. Copyright 2001, Active. State

… XSLT Example Copyright 2001, Active. State

“) nodes" src="https://present5.com/presentation/48f4cfe685c44b996bf1e4ff9ac43445/image-22.jpg" alt="Explicit Code Equivalent class my_template{ XPath match = "section" method action(context){ output("“) nodes" /> Explicit Code Equivalent class my_template{ XPath match = "section" method action(context){ output("“) nodes = XPath. Engine. evaluate( "paragraph", context) for(node in nodes){ template = rules. lookup(node) template. evaluate(node) } output("“) } }rules. addrule(new my_template()) Copyright 2001, Active. State

With a little detail-hiding class my_template{ XPath match = With a little detail-hiding class my_template{ XPath match = "section“ method action(context){ start_tag(“h 1”) apply. Templates(“paragraph”, context) end_tag(“/h 1”) } } rules. addrule(new my_template()) Copyright 2001, Active. State

Bottom line • Given a good OO language, you can emulate XSLT • But Bottom line • Given a good OO language, you can emulate XSLT • But it requires a lot of infrastructure • And it still requires you to take care of a lot of details… Copyright 2001, Active. State

How do you choose? • • Spoon! Fork! Copyright 2001, Active. State How do you choose? • • Spoon! Fork! Copyright 2001, Active. State

Connectivity • XSLT is only good at talking to “XML systems” • Scripting languages Connectivity • XSLT is only good at talking to “XML systems” • Scripting languages can talk to anything • This is typically the deciding factor. • If you need to build a GUI, you need to do it in a language with a GUI library! Copyright 2001, Active. State

Navigation • XSLT is really good at walking around the document tree. • Scripting Navigation • XSLT is really good at walking around the document tree. • Scripting languages are typically not as concise at navigation – but very flexible. • XSLT strongly “encourages” you to walk the tree top-down, front to back. Copyright 2001, Active. State

Data Structures • XSLT makes it very difficult to create structured data containers • Data Structures • XSLT makes it very difficult to create structured data containers • The idea is that the only data you need is in the input document: it already has a data structure! • But some computations are much easier if you can restructure the information yourself. Copyright 2001, Active. State

Community • • There are dozens of APIs for processing XML. Popular ones are Community • • There are dozens of APIs for processing XML. Popular ones are not as powerful as XSLT. Powerful ones are not as popular as XSLT. Nobody gets fired for using XSLT – but you can get fired for inventing your own XML API. Copyright 2001, Active. State

Implementations: XSLT • XSLT presents a lot of opportunity for optimization • Smart implementers Implementations: XSLT • XSLT presents a lot of opportunity for optimization • Smart implementers pre-compile XPaths and some even compile templates. • There are many different XSLT implementations with different tradeoffs. Copyright 2001, Active. State

Implementations: Scripting • Scripting code is hard to optimize. • On the other hand, Implementations: Scripting • Scripting code is hard to optimize. • On the other hand, the programmer can choose algorithms and datastructures! • Plus you could write a SAX application that does not use an in-memory tree at all. • This is efficient but difficult. Copyright 2001, Active. State

Standardization • XSLT is installed in – browsers, – database engines, – directory engines, Standardization • XSLT is installed in – browsers, – database engines, – directory engines, – programming languages, – and operating systems! – Java. Script is the only language that even comes close. Copyright 2001, Active. State

Best of Both Worlds? • The easy way to split work is to use Best of Both Worlds? • The easy way to split work is to use general purpose languages to generate or consume XML used by XSLT tempfile. write("") run("xslttrans conv. xsl tempfile outfile") data = outfile. read() Copyright 2001, Active. State

More Sophisticated Approach • XSLT has a concept of “extension functions” <xsl: value-of select=“myns: More Sophisticated Approach • XSLT has a concept of “extension functions” • If the implementation is smart enough, functions can be defined in any scripting language Copyright 2001, Active. State

Example Extension Functions function getdate(numdays) { var d = new Date(); var total. Days Example Extension Functions function getdate(numdays) { var d = new Date(); var total. Days = parse. Int(numdays) * multiplier; d. set. Date(d. get. Date() + total. Days); return d. to. Locale. String(); } Copyright 2001, Active. State

We have logged your enquiry and will" src="https://present5.com/presentation/48f4cfe685c44b996bf1e4ff9ac43445/image-36.jpg" alt="Using an Extension Function

We have logged your enquiry and will" /> Using an Extension Function

We have logged your enquiry and will respond by .

Copyright 2001, Active. State

Extension Elements in Xalan-J • “Xalan-Java uses the Bean Scripting Framework (BSF), an architecture Extension Elements in Xalan-J • “Xalan-Java uses the Bean Scripting Framework (BSF), an architecture for incorporating scripting into Java applications and applets. ” http: //oss. software. ibm. com/developerworks/project s/bsf Copyright 2001, Active. State

BSF-compatible Languages • • • Rhino (ECMAScript/Java. Script) Jython (Python) Jacl (TCL) Net. Rexx BSF-compatible Languages • • • Rhino (ECMAScript/Java. Script) Jython (Python) Jacl (TCL) Net. Rexx (REXX) Perl. Script (Perl – from Active. State) VBScript/Jscript through Active. Scripting Copyright 2001, Active. State

function getdate(numdays){ var d =" src="https://present5.com/presentation/48f4cfe685c44b996bf1e4ff9ac43445/image-39.jpg" alt="Inline Extensions function getdate(numdays){ var d =" /> Inline Extensions function getdate(numdays){ var d = new Date(); … return d. to. Locale. String(); } Copyright 2001, Active. State

In the Microsoft Universe • Microsoft has a concept of “Active. Scripting Host” – In the Microsoft Universe • Microsoft has a concept of “Active. Scripting Host” – used by MSXSL – – – VBScript JScript Python (Active. Python) Perl. Script (Active. Perl) REXX Tcl Copyright 2001, Active. State

In the Linux/C world? • Nothing yet…but maybe some day: Active. Scripting for XPCOM In the Linux/C world? • Nothing yet…but maybe some day: Active. Scripting for XPCOM • XPCOM is a portable variant of COM from the Mozilla project • Active. Scripting for XPCOM would allow languages to be embedded in Linux/C apps like Xalan-C Copyright 2001, Active. State

" src="https://present5.com/presentation/48f4cfe685c44b996bf1e4ff9ac43445/image-42.jpg" alt="What about Standardization? • XSLT 1. 1 defines " /> What about Standardization? • XSLT 1. 1 defines function f(x) {. . . } function g(y, z) {. . . } Copyright 2001, Active. State

Supported Languages • Out of the box, XSLT 1. 1 has explicit support for Supported Languages • Out of the box, XSLT 1. 1 has explicit support for ECMAScript (Java. Script) and Java • Other languages are allowed but not predefined. Copyright 2001, Active. State

“From the spec” • XSLT processors are not required to support any particular language “From the spec” • XSLT processors are not required to support any particular language binding. • xsl: script elements with language values not supported by the processor are ignored. Copyright 2001, Active. State

Active. State and XSLT • Active. State is the leading vendor of Visual Studio. Active. State and XSLT • Active. State is the leading vendor of Visual Studio. NET plugins: – Visual Perl – Visual Python – Visual XSLT Copyright 2001, Active. State

Visual XSLT • Visual XSLT brings the features of Visual Studio to XSLT stylesheet Visual XSLT • Visual XSLT brings the features of Visual Studio to XSLT stylesheet and transformation development • Improved productivity in creating XSLT transformations Copyright 2001, Active. State

Komodo XSLT • Komodo is a multi-language IDE for Windows and Linux • Komodo Komodo XSLT • Komodo is a multi-language IDE for Windows and Linux • Komodo has the same XSLT feature set as Visual XSLT. • Visual XSLT is appropriate for “Visual Studio” shops. • Komodo is best for cross-platform shops. Copyright 2001, Active. State

Summary • XSLT and scripting languages work together. • XSLT engines can integrate them Summary • XSLT and scripting languages work together. • XSLT engines can integrate them through extension functions (inline or out of line). • Our debuggers and IDEs can bring them into a common development interface. Copyright 2001, Active. State

Resources paulp@activestate. com http: //aspn. activestate. com/ASPN/XSLT http: //www. w 3. org/TR/xslt http: //www. Resources paulp@activestate. com http: //aspn. activestate. com/ASPN/XSLT http: //www. w 3. org/TR/xslt http: //www. xslt. com/ Copyright 2001, Active. State

Copyright 2001, Active. State Copyright 2001, Active. State

Copyright 2001, Active. State Copyright 2001, Active. State