The Lumber Mill Xslt For Your Templates

3,217
-1

Published on

Published in: Technology
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total Views
3,217
On Slideshare
0
From Embeds
0
Number of Embeds
5
Actions
Shares
0
Downloads
18
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

The Lumber Mill Xslt For Your Templates

  1. 1. IPC09 Spring Edition Thomas Weinert quot;The Lumber Millquot; Using XSLT For Your Templates
  2. 2. About Me ● Application Developer – PHP – XSLT/XPath – (some) JavaScript ● papaya CMS – PHP based Content Management System – uses XSLT for Templates
  3. 3. About You ● Who are you? ● Do you use XSLT? ● How often do you use XSLT? ● Do you use other template systems/languages? ● Smarty? ● TypoScript? ● ...?
  4. 4. Template Systems ● Bind variables ● Layout logic – Placeholders – Conditions – Loops – Callbacks ● Formatting ● Data loading
  5. 5. XSL ● XML – Semantic variable tree ● XPath – Query language for XML trees ● XSLT – Transforming XML ● Conditions ● Loops ● …
  6. 6. Comparison ● PHP based ● XSLT – Individual syntax – Standardized – Individual tools syntax – Individual – Free and documentation commercial tools – Different flavors – Documentation of for different the standard and purpose the implementations – Easy Syntax? – One to rule them all
  7. 7. Nodes ● texts/text[@ident='foo']/* ● texts/text[@ident='foo']/text() ● texts/text[@ident='foo']/node() ● texts/text[@ident='foo']/@value Elements Text nodes Attributes * text() @* node()
  8. 8. Template call/apply ● <xsl:call-template/> – Call templates by name ● <xsl:apply-templates/> – Template matching – Most exact pattern wins ● Current node ● Parameters ● Modes
  9. 9. 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
  10. 10. Collecting Output Page (HTML) Page (XML) Part 1 (HTML) Part 2 (HTML) Main (XML) Part 1 (XML) Part 2 (XML)
  11. 11. Caching Output Page (HTML) Page (XML) Cache Part 1 (HTML) Part 2 (HTML) Main (XML) Part 1 (XML) Part 2 (XML)
  12. 12. Embedding Output ● Escaping and CDATA-Sections – CDATA is for readability and whitespaces ● <xsl:copy-of select=“...“/> ● disable-output-escaping=“yes“ ● Dangers – HTML Injection
  13. 13. Import templates ● Generic ● Reusable ● Encapsulation ● Inheritance
  14. 14. 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
  15. 15. XML Data Files ● Wellformed XML ● XPath: document() ● URI – Single loading
  16. 16. Language Templates ● Phrases – quot;layout textsquot; ● Numbers ● Date and Time
  17. 17. EXSLT ● Community initiative to provide extensions to XSLT – Common – Functions – Math, Random – Strings, Regular Expressions – Dates and Times – Sets – Dynamic
  18. 18. EXSLT: functions module ● Make templates to functions – func:function – func:result ● Namespace required – func – Own
  19. 19. PHP ● Streamwrapper – return XML data for document() ● Callbacks – call php source
  20. 20. 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!
  21. 21. Callbacks ● Register PHP functions for xsl – registerPHPFunctions($restrict) – php::function('function', parameter, ...) – php::functionString('function', ...)
  22. 22. RTF Problem ● Result Tree Fragment – XML created in XSL – No CDATA – No node set ● XSLT 2.0 ● EXSLT – node-set()
  23. 23. Other Templates ● Repeat String ● JavaScript Escaping
  24. 24. 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
  25. 25. Administration ● Single template ● About 25% saved
  26. 26. Output ● Several template ● About 90% saved
  27. 27. 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/
  1. A particular slide catching your eye?

    Clipping is a handy way to collect important slides you want to go back to later.

×