SlideShare a Scribd company logo
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 based Content Management System
    –   uses XSLT for Templates
About You
●   Who are you?
●   Do you use XSLT?
●   How often do you use XSLT?
●   Do you use other template systems/languages?
●   Smarty?
●   TypoScript?
●   ...?
Template Systems
●   Bind variables
●   Layout logic
       –   Placeholders
       –   Conditions
       –   Loops
       –   Callbacks
               ●   Formatting
               ●   Data loading
XSL
●   XML
       –   Semantic variable tree
●   XPath
       –   Query language for XML trees
●   XSLT
       –   Transforming XML
               ●   Conditions
               ●   Loops
               ●   …
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
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()
Template call/apply
●   <xsl:call-template/>
        –   Call templates by name
●   <xsl:apply-templates/>
        –   Template matching
        –   Most exact pattern wins
●   Current node
●   Parameters
●   Modes
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
Collecting Output
              Page (HTML)


              Page (XML)




             Part 1 (HTML)   Part 2 (HTML)


Main (XML)    Part 1 (XML)   Part 2 (XML)
Caching Output
                Page (HTML)


                 Page (XML)


                   Cache

                Part 1 (HTML)   Part 2 (HTML)


Main (XML)       Part 1 (XML)   Part 2 (XML)
Embedding Output
●   Escaping and CDATA-Sections
        –   CDATA is for readability and whitespaces
●   <xsl:copy-of select=“...“/>
●   disable-output-escaping=“yes“
●   Dangers
        –   HTML Injection
Import templates
●   Generic
●   Reusable
●   Encapsulation
●   Inheritance
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
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, Random
        –   Strings, Regular Expressions
        –   Dates and Times
        –   Sets
        –   Dynamic
EXSLT: functions module
●   Make templates to functions
       –   func:function
       –   func:result
●   Namespace required
       –   func
       –   Own
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 wrappers
       –   PHP class
       –   Basic functions
                ●   stream_open(), stream_read(), stream_tell(),
                      stream_seek(), stream_eof(),
       –   url_stat()
●   No php source!
Callbacks
●   Register PHP functions for xsl
        –   registerPHPFunctions($restrict)
        –   php::function('function', parameter, ...)
        –   php::functionString('function', ...)
RTF Problem
●   Result Tree Fragment
       –   XML created in XSL
       –   No CDATA
       –   No node set
●   XSLT 2.0
●   EXSLT
       –   node-set()
Other Templates
●   Repeat String
●   JavaScript Escaping
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
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://www.dpawson.co.uk/xsl/sect2/sect21.html

●   http://code.nytimes.com/projects/xslcache/

More Related Content

PDF
The Lumber Mill Xslt For Your Templates
PPTX
Xml processors
PPTX
Xml dom
PDF
Extensible Stylesheet Language
PPT
Xml and DTD's
PPTX
Introductionto xslt
PPT
Intro to XML in libraries
PPT
DOM and SAX
The Lumber Mill Xslt For Your Templates
Xml processors
Xml dom
Extensible Stylesheet Language
Xml and DTD's
Introductionto xslt
Intro to XML in libraries
DOM and SAX

What's hot (20)

PPT
Understanding XML DOM
PDF
Got bored by the relational database? Switch to a RDF store!
PDF
Querring xml with xpath
PPTX
Unit3wt
PPTX
Dom parser
PDF
Programming the Semantic Web
PPTX
Publishing xml
PPTX
PDF
Xml databases
PPT
PPTX
Persentation on c language
PPTX
XSL - XML STYLE SHEET
PPTX
Data exchange over internet (XML vs JSON)
PDF
Slide
PPTX
Introduction to XML
PPTX
SMWCon Fall 2015 FForms
PDF
PostgreSQL, Extensible to the Nth Degree: Functions, Languages, Types, Rules,...
PDF
XSLT 3 for EPUB and Print - Liam R.E. Quin (Barefoot Computing) - ebookcraft ...
Understanding XML DOM
Got bored by the relational database? Switch to a RDF store!
Querring xml with xpath
Unit3wt
Dom parser
Programming the Semantic Web
Publishing xml
Xml databases
Persentation on c language
XSL - XML STYLE SHEET
Data exchange over internet (XML vs JSON)
Slide
Introduction to XML
SMWCon Fall 2015 FForms
PostgreSQL, Extensible to the Nth Degree: Functions, Languages, Types, Rules,...
XSLT 3 for EPUB and Print - Liam R.E. Quin (Barefoot Computing) - ebookcraft ...
Ad

Similar to The Lumber Mill - XSLT For Your Templates (20)

PDF
Find it, possibly also near you!
PDF
Syntax Reuse: XSLT as a Metalanguage for Knowledge Representation Languages
PDF
Get the most out of Solr search with PHP
PDF
XML Tools for Perl
PDF
Java Course 12: XML & XSL, Web & Servlets
PDF
Tips and Tricks for Increased Development Efficiency
PDF
The XML Forms Architecture
PPTX
Protocol Buffers
PPTX
Papyrus for Real Time at the OMG TC
PDF
Extensible markup language attacks
PPT
Formal machines for Streaming XML Querying
PDF
Cmsc 100 (web content)
PDF
XML-athon with Don and Dean
PDF
Balisage - EXPath - A practical introduction
ODP
Developing web apps using Erlang-Web
PDF
Lightweight web frameworks
PPT
Extensible stylesheet language (Transformation) or XSLT
Find it, possibly also near you!
Syntax Reuse: XSLT as a Metalanguage for Knowledge Representation Languages
Get the most out of Solr search with PHP
XML Tools for Perl
Java Course 12: XML & XSL, Web & Servlets
Tips and Tricks for Increased Development Efficiency
The XML Forms Architecture
Protocol Buffers
Papyrus for Real Time at the OMG TC
Extensible markup language attacks
Formal machines for Streaming XML Querying
Cmsc 100 (web content)
XML-athon with Don and Dean
Balisage - EXPath - A practical introduction
Developing web apps using Erlang-Web
Lightweight web frameworks
Extensible stylesheet language (Transformation) or XSLT
Ad

More from Thomas Weinert (13)

PDF
PHPUG CGN: Controlling Arduino With PHP
PDF
Controlling Arduino With PHP
PDF
Decoupling Objects With Standard Interfaces
PDF
Asynchronous I/O in PHP
PDF
Lumberjack XPath 101
PDF
FluentDom
PDF
Optimizing Your Frontend Performance
PDF
Experiences With Pre Commit Hooks
PDF
SVN Hook
PDF
Deliver Files With PHP
PDF
Optimizing Your Frontend Performance
PDF
PHP 5.3/6
PDF
Optimizing Your Frontend Performance
PHPUG CGN: Controlling Arduino With PHP
Controlling Arduino With PHP
Decoupling Objects With Standard Interfaces
Asynchronous I/O in PHP
Lumberjack XPath 101
FluentDom
Optimizing Your Frontend Performance
Experiences With Pre Commit Hooks
SVN Hook
Deliver Files With PHP
Optimizing Your Frontend Performance
PHP 5.3/6
Optimizing Your Frontend Performance

Recently uploaded (20)

PDF
CIFDAQ's Market Insight: SEC Turns Pro Crypto
PPT
Teaching material agriculture food technology
PDF
Encapsulation_ Review paper, used for researhc scholars
PDF
Shreyas Phanse Resume: Experienced Backend Engineer | Java • Spring Boot • Ka...
PPTX
Detection-First SIEM: Rule Types, Dashboards, and Threat-Informed Strategy
PDF
cuic standard and advanced reporting.pdf
PPTX
Big Data Technologies - Introduction.pptx
PDF
NewMind AI Monthly Chronicles - July 2025
PDF
Network Security Unit 5.pdf for BCA BBA.
PPTX
MYSQL Presentation for SQL database connectivity
PPTX
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
PPTX
PA Analog/Digital System: The Backbone of Modern Surveillance and Communication
PDF
Chapter 3 Spatial Domain Image Processing.pdf
PDF
Mobile App Security Testing_ A Comprehensive Guide.pdf
PDF
Electronic commerce courselecture one. Pdf
PPTX
Cloud computing and distributed systems.
PDF
Bridging biosciences and deep learning for revolutionary discoveries: a compr...
PDF
Diabetes mellitus diagnosis method based random forest with bat algorithm
PDF
Dropbox Q2 2025 Financial Results & Investor Presentation
PDF
Empathic Computing: Creating Shared Understanding
CIFDAQ's Market Insight: SEC Turns Pro Crypto
Teaching material agriculture food technology
Encapsulation_ Review paper, used for researhc scholars
Shreyas Phanse Resume: Experienced Backend Engineer | Java • Spring Boot • Ka...
Detection-First SIEM: Rule Types, Dashboards, and Threat-Informed Strategy
cuic standard and advanced reporting.pdf
Big Data Technologies - Introduction.pptx
NewMind AI Monthly Chronicles - July 2025
Network Security Unit 5.pdf for BCA BBA.
MYSQL Presentation for SQL database connectivity
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
PA Analog/Digital System: The Backbone of Modern Surveillance and Communication
Chapter 3 Spatial Domain Image Processing.pdf
Mobile App Security Testing_ A Comprehensive Guide.pdf
Electronic commerce courselecture one. Pdf
Cloud computing and distributed systems.
Bridging biosciences and deep learning for revolutionary discoveries: a compr...
Diabetes mellitus diagnosis method based random forest with bat algorithm
Dropbox Q2 2025 Financial Results & Investor Presentation
Empathic Computing: Creating Shared Understanding

The Lumber Mill - XSLT For Your Templates

  • 1. FrOSCon Bastian Feder, Thomas Weinert "The Lumber Mill" Using XSLT For Your Templates
  • 2. About Us ● Application Developer – PHP – XSLT/XPath – (some) JavaScript ● papaya CMS – PHP based Content Management System – uses XSLT for Templates
  • 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. Template Systems ● Bind variables ● Layout logic – Placeholders – Conditions – Loops – Callbacks ● Formatting ● Data loading
  • 5. XSL ● XML – Semantic variable tree ● XPath – Query language for XML trees ● XSLT – Transforming XML ● Conditions ● Loops ● …
  • 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. 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. Template call/apply ● <xsl:call-template/> – Call templates by name ● <xsl:apply-templates/> – Template matching – Most exact pattern wins ● Current node ● Parameters ● Modes
  • 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. Collecting Output Page (HTML) Page (XML) Part 1 (HTML) Part 2 (HTML) Main (XML) Part 1 (XML) Part 2 (XML)
  • 11. Caching Output Page (HTML) Page (XML) Cache Part 1 (HTML) Part 2 (HTML) Main (XML) Part 1 (XML) Part 2 (XML)
  • 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. Import templates ● Generic ● Reusable ● Encapsulation ● Inheritance
  • 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. XML Data Files ● Wellformed XML ● XPath: document() ● URI – Single loading
  • 16. Language Templates ● Phrases – "layout texts" ● Numbers ● Date and Time
  • 17. EXSLT ● Community initiative to provide extensions to XSLT – Common – Functions – Math, Random – Strings, Regular Expressions – Dates and Times – Sets – Dynamic
  • 18. EXSLT: functions module ● Make templates to functions – func:function – func:result ● Namespace required – func – Own
  • 19. PHP ● Streamwrapper – return XML data for document() ● Callbacks – call php source
  • 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. Callbacks ● Register PHP functions for xsl – registerPHPFunctions($restrict) – php::function('function', parameter, ...) – php::functionString('function', ...)
  • 22. RTF Problem ● Result Tree Fragment – XML created in XSL – No CDATA – No node set ● XSLT 2.0 ● EXSLT – node-set()
  • 23. Other Templates ● Repeat String ● JavaScript Escaping
  • 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. Administration ● Single template ● About 25% saved
  • 26. Output ● Several template ● About 90% saved
  • 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/