FrOSCon



  Bastian Feder, Thomas Weinert
     "The Lumber Mill"
Using XSLT For Your Templates
About Us
●   Application Developer
    –   PHP
    –   XSLT/XPath
    –   (some) JavaScript
●   papaya CMS
    –   PHP bas...
About You
●   Who are you?
●   Do you use XSLT?
●   How often do you use XSLT?
●   Do you use other template systems/langu...
Template Systems
●   Bind variables
●   Layout logic
       –   Placeholders
       –   Conditions
       –   Loops
      ...
XSL
●   XML
       –   Semantic variable tree
●   XPath
       –   Query language for XML trees
●   XSLT
       –   Transf...
Comparison
●   PHP based                  ●   XSLT
       –   Individual syntax         –   Standardized
       –   Indivi...
Nodes
●   texts/text[@ident='foo']/*
●   texts/text[@ident='foo']/text()
●   texts/text[@ident='foo']/node()
●   texts/tex...
Template call/apply
●   <xsl:call-template/>
        –   Call templates by name
●   <xsl:apply-templates/>
        –   Tem...
Static Templates Files
●   Template files should not be writable by the
    web server
        –   Security
        –   To...
Collecting Output
              Page (HTML)


              Page (XML)




             Part 1 (HTML)   Part 2 (HTML)


Ma...
Caching Output
                Page (HTML)


                 Page (XML)


                   Cache

                Part ...
Embedding Output
●   Escaping and CDATA-Sections
        –   CDATA is for readability and whitespaces
●   <xsl:copy-of sel...
Import templates
●   Generic
●   Reusable
●   Encapsulation
●   Inheritance
Multiple Columns Template
●   Group items
        –   Calculate positions
●   Call item group templates
●   Call item gene...
XML Data Files
●   Wellformed XML
●   XPath: document()
●   URI
          –   Single loading
Language Templates
●   Phrases
       –   "layout texts"
●   Numbers
●   Date and Time
EXSLT
●   Community initiative to provide extensions to
    XSLT
        –   Common
        –   Functions
        –   Math...
EXSLT: functions module
●   Make templates to functions
       –   func:function
       –   func:result
●   Namespace requ...
PHP
●   Streamwrapper
       –   return XML data for document()
●   Callbacks
       –   call php source
Streamwrapper
●   PHP file functions use stream wrappers
       –   Internal: http, ftp, phar, …
●   Register own stream w...
Callbacks
●   Register PHP functions for xsl
        –   registerPHPFunctions($restrict)
        –   php::function('functi...
RTF Problem
●   Result Tree Fragment
       –   XML created in XSL
       –   No CDATA
       –   No node set
●   XSLT 2.0...
Other Templates
●   Repeat String
●   JavaScript Escaping
ext/xslcache
●   Process cache
●   Performance increase
●   Still evaluating
        –   Only some checks in php requests
...
Administration


        ●   Single template
        ●   About 25% saved
Output


   ●   Several template
   ●   About 90% saved
Links
●   http://www.a-basketful-of-papayas.net/

●   http://www.w3.org/TR/xpath
●   http://www.w3.org/TR/xslt
●   http://...
Upcoming SlideShare
Loading in …5
×

The Lumber Mill - XSLT For Your Templates

1,106 views
1,036 views

Published on

Ideas and Solutions for XSLT Templating, FrOSCon 2009

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
1,106
On SlideShare
0
From Embeds
0
Number of Embeds
63
Actions
Shares
0
Downloads
4
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

The Lumber Mill - XSLT For Your Templates

  1. 1. FrOSCon Bastian Feder, Thomas Weinert "The Lumber Mill" Using XSLT For Your Templates
  2. 2. About Us ● 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 – "layout texts" ● 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/

×