The Lumber Mill Xslt For Your Templates
-
Upload
thomas-weinert -
Category
Technology
-
view
4.216 -
download
1
description
Transcript of The Lumber Mill Xslt For Your Templates
![Page 1: The Lumber Mill Xslt For Your Templates](https://reader033.fdocuments.in/reader033/viewer/2022051609/546fad69af79599f0a8b4644/html5/thumbnails/1.jpg)
IPC09 Spring Edition
Thomas Weinert"The Lumber Mill"
Using XSLT For Your Templates
![Page 2: The Lumber Mill Xslt For Your Templates](https://reader033.fdocuments.in/reader033/viewer/2022051609/546fad69af79599f0a8b4644/html5/thumbnails/2.jpg)
About Me● Application Developer
– PHP– XSLT/XPath– (some) JavaScript
● papaya CMS– PHP based Content Management System– uses XSLT for Templates
![Page 3: The Lumber Mill Xslt For Your Templates](https://reader033.fdocuments.in/reader033/viewer/2022051609/546fad69af79599f0a8b4644/html5/thumbnails/3.jpg)
About You● Who are you?● Do you use XSLT?● How often do you use XSLT?● Do you use other template systems/languages?● Smarty?● TypoScript?● ...?
![Page 4: The Lumber Mill Xslt For Your Templates](https://reader033.fdocuments.in/reader033/viewer/2022051609/546fad69af79599f0a8b4644/html5/thumbnails/4.jpg)
Template Systems● Bind variables● Layout logic
– Placeholders– Conditions– Loops– Callbacks
● Formatting● Data loading
![Page 5: The Lumber Mill Xslt For Your Templates](https://reader033.fdocuments.in/reader033/viewer/2022051609/546fad69af79599f0a8b4644/html5/thumbnails/5.jpg)
XSL● XML
– Semantic variable tree● XPath
– Query language for XML trees● XSLT
– Transforming XML● Conditions● Loops● …
![Page 6: The Lumber Mill Xslt For Your Templates](https://reader033.fdocuments.in/reader033/viewer/2022051609/546fad69af79599f0a8b4644/html5/thumbnails/6.jpg)
Comparison● PHP based
– Individual syntax– Individual tools– Individual
documentation– Different flavors
for different purpose
– Easy Syntax?
● XSLT– Standardized
syntax– Free and
commercial tools– Documentation of
the standard and the implementations
– One to rule them all
![Page 7: The Lumber Mill Xslt For Your Templates](https://reader033.fdocuments.in/reader033/viewer/2022051609/546fad69af79599f0a8b4644/html5/thumbnails/7.jpg)
Nodes
Elements Text nodes Attributes
* text() @*
node()
● texts/text[@ident='foo']/*● texts/text[@ident='foo']/text()● texts/text[@ident='foo']/node()● texts/text[@ident='foo']/@value
![Page 8: The Lumber Mill Xslt For Your Templates](https://reader033.fdocuments.in/reader033/viewer/2022051609/546fad69af79599f0a8b4644/html5/thumbnails/8.jpg)
Template call/apply● <xsl:call-template/>
– Call templates by name● <xsl:apply-templates/>
– Template matching– Most exact pattern wins
● Current node● Parameters● Modes
![Page 9: The Lumber Mill Xslt For Your Templates](https://reader033.fdocuments.in/reader033/viewer/2022051609/546fad69af79599f0a8b4644/html5/thumbnails/9.jpg)
Static Templates Files● Template files should not be writable by the
web server– Security– Tools
● Template files should not be generated from PHP
– Same reasons– Context
![Page 10: The Lumber Mill Xslt For Your Templates](https://reader033.fdocuments.in/reader033/viewer/2022051609/546fad69af79599f0a8b4644/html5/thumbnails/10.jpg)
Collecting Output
Main (XML)
Part 1 (HTML)
Part 2 (XML)Part 1 (XML)
Part 2 (HTML)
Page (XML)
Page (HTML)
![Page 11: The Lumber Mill Xslt For Your Templates](https://reader033.fdocuments.in/reader033/viewer/2022051609/546fad69af79599f0a8b4644/html5/thumbnails/11.jpg)
Caching Output
Main (XML)
Part 1 (HTML)
Part 2 (XML)Part 1 (XML)
Part 2 (HTML)
Page (XML)
Page (HTML)
Cache
![Page 12: The Lumber Mill Xslt For Your Templates](https://reader033.fdocuments.in/reader033/viewer/2022051609/546fad69af79599f0a8b4644/html5/thumbnails/12.jpg)
Embedding Output● Escaping and CDATA-Sections
– CDATA is for readability and whitespaces● <xsl:copy-of select=“...“/>● disable-output-escaping=“yes“● Dangers
– HTML Injection
![Page 13: The Lumber Mill Xslt For Your Templates](https://reader033.fdocuments.in/reader033/viewer/2022051609/546fad69af79599f0a8b4644/html5/thumbnails/13.jpg)
Import templates● Generic● Reusable● Encapsulation● Inheritance
![Page 14: The Lumber Mill Xslt For Your Templates](https://reader033.fdocuments.in/reader033/viewer/2022051609/546fad69af79599f0a8b4644/html5/thumbnails/14.jpg)
Multiple Columns Template● Group items
– Calculate positions● Call item group templates● Call item generic template● Use itemType parameter to identify item
template● Call type specific template for item
![Page 15: The Lumber Mill Xslt For Your Templates](https://reader033.fdocuments.in/reader033/viewer/2022051609/546fad69af79599f0a8b4644/html5/thumbnails/15.jpg)
XML Data Files● Wellformed XML● XPath: document()● URI
– Single loading
![Page 16: The Lumber Mill Xslt For Your Templates](https://reader033.fdocuments.in/reader033/viewer/2022051609/546fad69af79599f0a8b4644/html5/thumbnails/16.jpg)
Language Templates● Phrases
– "layout texts"● Numbers● Date and Time
![Page 17: The Lumber Mill Xslt For Your Templates](https://reader033.fdocuments.in/reader033/viewer/2022051609/546fad69af79599f0a8b4644/html5/thumbnails/17.jpg)
EXSLT● Community initiative to provide extensions to
XSLT– Common– Functions– Math, Random– Strings, Regular Expressions– Dates and Times– Sets– Dynamic
![Page 18: The Lumber Mill Xslt For Your Templates](https://reader033.fdocuments.in/reader033/viewer/2022051609/546fad69af79599f0a8b4644/html5/thumbnails/18.jpg)
EXSLT: functions module● Make templates to functions
– func:function– func:result
● Namespace required– func– Own
![Page 19: The Lumber Mill Xslt For Your Templates](https://reader033.fdocuments.in/reader033/viewer/2022051609/546fad69af79599f0a8b4644/html5/thumbnails/19.jpg)
PHP● Streamwrapper
– return XML data for document()● Callbacks
– call php source
![Page 20: The Lumber Mill Xslt For Your Templates](https://reader033.fdocuments.in/reader033/viewer/2022051609/546fad69af79599f0a8b4644/html5/thumbnails/20.jpg)
Streamwrapper● PHP file functions use stream wrappers
– Internal: http, ftp, phar, …● Register own stream wrappers
– PHP class– Basic functions
● stream_open(), stream_read(), stream_tell(), stream_seek(), stream_eof(),
– url_stat()● No php source!
![Page 21: The Lumber Mill Xslt For Your Templates](https://reader033.fdocuments.in/reader033/viewer/2022051609/546fad69af79599f0a8b4644/html5/thumbnails/21.jpg)
Callbacks● Register PHP functions for xsl
– registerPHPFunctions($restrict)– php::function('function', parameter, ...)– php::functionString('function', ...)
![Page 22: The Lumber Mill Xslt For Your Templates](https://reader033.fdocuments.in/reader033/viewer/2022051609/546fad69af79599f0a8b4644/html5/thumbnails/22.jpg)
RTF Problem● Result Tree Fragment
– XML created in XSL– No CDATA– No node set
● XSLT 2.0● EXSLT
– node-set()
![Page 23: The Lumber Mill Xslt For Your Templates](https://reader033.fdocuments.in/reader033/viewer/2022051609/546fad69af79599f0a8b4644/html5/thumbnails/23.jpg)
Other Templates● Repeat String● JavaScript Escaping
![Page 24: The Lumber Mill Xslt For Your Templates](https://reader033.fdocuments.in/reader033/viewer/2022051609/546fad69af79599f0a8b4644/html5/thumbnails/24.jpg)
ext/xslcache● Process cache● Performance increase● Still evaluating
– Only some checks in php requests● Only static XSLT● Same library like ext/xsl
– eXSLT– PHP callbacks
![Page 25: The Lumber Mill Xslt For Your Templates](https://reader033.fdocuments.in/reader033/viewer/2022051609/546fad69af79599f0a8b4644/html5/thumbnails/25.jpg)
Administration
● Single template● About 25% saved
![Page 26: The Lumber Mill Xslt For Your Templates](https://reader033.fdocuments.in/reader033/viewer/2022051609/546fad69af79599f0a8b4644/html5/thumbnails/26.jpg)
Output
● Several template● About 90% saved
![Page 27: The Lumber Mill Xslt For Your Templates](https://reader033.fdocuments.in/reader033/viewer/2022051609/546fad69af79599f0a8b4644/html5/thumbnails/27.jpg)
Links● http://www.a-basketful-of-papayas.net/
● http://www.w3.org/TR/xpath● http://www.w3.org/TR/xslt● http://www.dpawson.co.uk/xsl/sect2/sect21.html
● http://code.nytimes.com/projects/xslcache/