SlideShare a Scribd company logo
1 of 27
Download to read offline
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

What's hot

Got bored by the relational database? Switch to a RDF store!
Got bored by the relational database? Switch to a RDF store!Got bored by the relational database? Switch to a RDF store!
Got bored by the relational database? Switch to a RDF store!
benfante
 

What's hot (20)

Understanding XML DOM
Understanding XML DOMUnderstanding XML DOM
Understanding XML DOM
 
Got bored by the relational database? Switch to a RDF store!
Got bored by the relational database? Switch to a RDF store!Got bored by the relational database? Switch to a RDF store!
Got bored by the relational database? Switch to a RDF store!
 
Querring xml with xpath
Querring xml with xpath Querring xml with xpath
Querring xml with xpath
 
Unit3wt
Unit3wtUnit3wt
Unit3wt
 
Dom parser
Dom parserDom parser
Dom parser
 
Programming the Semantic Web
Programming the Semantic WebProgramming the Semantic Web
Programming the Semantic Web
 
Publishing xml
Publishing xmlPublishing xml
Publishing xml
 
DOM-XML
DOM-XMLDOM-XML
DOM-XML
 
Xml
XmlXml
Xml
 
XML - SAX
XML - SAXXML - SAX
XML - SAX
 
Xml databases
Xml databasesXml databases
Xml databases
 
Xml
XmlXml
Xml
 
Persentation on c language
Persentation on c languagePersentation on c language
Persentation on c language
 
XSL - XML STYLE SHEET
XSL - XML STYLE SHEETXSL - XML STYLE SHEET
XSL - XML STYLE SHEET
 
Data exchange over internet (XML vs JSON)
Data exchange over internet (XML vs JSON)Data exchange over internet (XML vs JSON)
Data exchange over internet (XML vs JSON)
 
Slide
SlideSlide
Slide
 
Introduction to XML
Introduction to XMLIntroduction to XML
Introduction to XML
 
SMWCon Fall 2015 FForms
SMWCon Fall 2015 FFormsSMWCon Fall 2015 FForms
SMWCon Fall 2015 FForms
 
PostgreSQL, Extensible to the Nth Degree: Functions, Languages, Types, Rules,...
PostgreSQL, Extensible to the Nth Degree: Functions, Languages, Types, Rules,...PostgreSQL, Extensible to the Nth Degree: Functions, Languages, Types, Rules,...
PostgreSQL, Extensible to the Nth Degree: Functions, Languages, Types, Rules,...
 
XSLT 3 for EPUB and Print - Liam R.E. Quin (Barefoot Computing) - ebookcraft ...
XSLT 3 for EPUB and Print - Liam R.E. Quin (Barefoot Computing) - ebookcraft ...XSLT 3 for EPUB and Print - Liam R.E. Quin (Barefoot Computing) - ebookcraft ...
XSLT 3 for EPUB and Print - Liam R.E. Quin (Barefoot Computing) - ebookcraft ...
 

Similar to The Lumber Mill - XSLT For Your Templates

Balisage - EXPath - A practical introduction
Balisage - EXPath - A practical introductionBalisage - EXPath - A practical introduction
Balisage - EXPath - A practical introduction
Florent Georges
 

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

Find it, possibly also near you!
Find it, possibly also near you!Find it, possibly also near you!
Find it, possibly also near you!
 
Syntax Reuse: XSLT as a Metalanguage for Knowledge Representation Languages
Syntax Reuse: XSLT as a Metalanguage for Knowledge Representation LanguagesSyntax Reuse: XSLT as a Metalanguage for Knowledge Representation Languages
Syntax Reuse: XSLT as a Metalanguage for Knowledge Representation Languages
 
Get the most out of Solr search with PHP
Get the most out of Solr search with PHPGet the most out of Solr search with PHP
Get the most out of Solr search with PHP
 
XML Tools for Perl
XML Tools for PerlXML Tools for Perl
XML Tools for Perl
 
Java Course 12: XML & XSL, Web & Servlets
Java Course 12: XML & XSL, Web & ServletsJava Course 12: XML & XSL, Web & Servlets
Java Course 12: XML & XSL, Web & Servlets
 
Tips and Tricks for Increased Development Efficiency
Tips and Tricks for Increased Development EfficiencyTips and Tricks for Increased Development Efficiency
Tips and Tricks for Increased Development Efficiency
 
The XML Forms Architecture
The XML Forms ArchitectureThe XML Forms Architecture
The XML Forms Architecture
 
Protocol Buffers
Protocol BuffersProtocol Buffers
Protocol Buffers
 
Papyrus for Real Time at the OMG TC
Papyrus for Real Time  at the OMG TCPapyrus for Real Time  at the OMG TC
Papyrus for Real Time at the OMG TC
 
Extensible markup language attacks
Extensible markup language attacksExtensible markup language attacks
Extensible markup language attacks
 
Formal machines for Streaming XML Querying
Formal machines for Streaming XML QueryingFormal machines for Streaming XML Querying
Formal machines for Streaming XML Querying
 
Cmsc 100 (web content)
Cmsc 100  (web content)Cmsc 100  (web content)
Cmsc 100 (web content)
 
XML-athon with Don and Dean
XML-athon with Don and DeanXML-athon with Don and Dean
XML-athon with Don and Dean
 
Balisage - EXPath - A practical introduction
Balisage - EXPath - A practical introductionBalisage - EXPath - A practical introduction
Balisage - EXPath - A practical introduction
 
Developing web apps using Erlang-Web
Developing web apps using Erlang-WebDeveloping web apps using Erlang-Web
Developing web apps using Erlang-Web
 
Lightweight web frameworks
Lightweight web frameworksLightweight web frameworks
Lightweight web frameworks
 
Php
PhpPhp
Php
 
Php
PhpPhp
Php
 
Php
PhpPhp
Php
 
Extensible stylesheet language (Transformation) or XSLT
Extensible stylesheet language (Transformation) or XSLTExtensible stylesheet language (Transformation) or XSLT
Extensible stylesheet language (Transformation) or XSLT
 

More from Thomas Weinert (13)

PHPUG CGN: Controlling Arduino With PHP
PHPUG CGN: Controlling Arduino With PHPPHPUG CGN: Controlling Arduino With PHP
PHPUG CGN: Controlling Arduino With PHP
 
Controlling Arduino With PHP
Controlling Arduino With PHPControlling Arduino With PHP
Controlling Arduino With PHP
 
Decoupling Objects With Standard Interfaces
Decoupling Objects With Standard InterfacesDecoupling Objects With Standard Interfaces
Decoupling Objects With Standard Interfaces
 
Asynchronous I/O in PHP
Asynchronous I/O in PHPAsynchronous I/O in PHP
Asynchronous I/O in PHP
 
Lumberjack XPath 101
Lumberjack XPath 101Lumberjack XPath 101
Lumberjack XPath 101
 
FluentDom
FluentDomFluentDom
FluentDom
 
Optimizing Your Frontend Performance
Optimizing Your Frontend PerformanceOptimizing Your Frontend Performance
Optimizing Your Frontend Performance
 
Experiences With Pre Commit Hooks
Experiences With Pre Commit HooksExperiences With Pre Commit Hooks
Experiences With Pre Commit Hooks
 
SVN Hook
SVN HookSVN Hook
SVN Hook
 
Deliver Files With PHP
Deliver Files With PHPDeliver Files With PHP
Deliver Files With PHP
 
Optimizing Your Frontend Performance
Optimizing Your Frontend PerformanceOptimizing Your Frontend Performance
Optimizing Your Frontend Performance
 
PHP 5.3/6
PHP 5.3/6PHP 5.3/6
PHP 5.3/6
 
Optimizing Your Frontend Performance
Optimizing Your Frontend PerformanceOptimizing Your Frontend Performance
Optimizing Your Frontend Performance
 

Recently uploaded

Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Victor Rentea
 
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Victor Rentea
 

Recently uploaded (20)

MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024
 
Manulife - Insurer Transformation Award 2024
Manulife - Insurer Transformation Award 2024Manulife - Insurer Transformation Award 2024
Manulife - Insurer Transformation Award 2024
 
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
 
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
 
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ..."I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a Fresher
 
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024
 
DBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor Presentation
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
 
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
 
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdfRising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
 
[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...
 

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/