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

CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Service
giselly40
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
Enterprise Knowledge
 

Recently uploaded (20)

Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men
 
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
 
Evaluating the top large language models.pdf
Evaluating the top large language models.pdfEvaluating the top large language models.pdf
Evaluating the top large language models.pdf
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Service
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
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...
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men
 

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/