SlideShare uma empresa Scribd logo
1 de 27
Baixar para ler offline
IPC09 Spring Edition



        Thomas Weinert
     quot;The Lumber Millquot;
Using XSLT For Your Templates
About Me
●   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
       –   quot;layout textsquot;
●   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/

Mais conteúdo relacionado

Mais procurados

PhD Presentation
PhD PresentationPhD Presentation
PhD Presentation
mskayed
 

Mais procurados (20)

DOM and SAX
DOM and SAXDOM and SAX
DOM and SAX
 
XML
XMLXML
XML
 
XML and XSLT
XML and XSLTXML and XSLT
XML and XSLT
 
26xslt
26xslt26xslt
26xslt
 
Object Relational Mapping in PHP
Object Relational Mapping in PHPObject Relational Mapping in PHP
Object Relational Mapping in PHP
 
XSLT for Web Developers
XSLT for Web DevelopersXSLT for Web Developers
XSLT for Web Developers
 
Java JDBC
Java JDBCJava JDBC
Java JDBC
 
XSLT presentation
XSLT presentationXSLT presentation
XSLT presentation
 
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 ...
 
php
phpphp
php
 
Xslt tutorial
Xslt tutorialXslt tutorial
Xslt tutorial
 
PhD Presentation
PhD PresentationPhD Presentation
PhD Presentation
 
Xml p5 Lecture Notes
Xml p5 Lecture NotesXml p5 Lecture Notes
Xml p5 Lecture Notes
 
XSLT. Basic.
XSLT. Basic.XSLT. Basic.
XSLT. Basic.
 
Web Service Workshop - 3 days
Web Service Workshop - 3 daysWeb Service Workshop - 3 days
Web Service Workshop - 3 days
 
Xml and DTD's
Xml and DTD'sXml and DTD's
Xml and DTD's
 
Xml processors
Xml processorsXml processors
Xml processors
 
XSLT
XSLTXSLT
XSLT
 
Transforming xml with XSLT
Transforming  xml with XSLTTransforming  xml with XSLT
Transforming xml with XSLT
 
SAX, DOM & JDOM parsers for beginners
SAX, DOM & JDOM parsers for beginnersSAX, DOM & JDOM parsers for beginners
SAX, DOM & JDOM parsers for beginners
 

Semelhante a The Lumber Mill Xslt For Your Templates

SXML: S-expression eXtensible Markup Language
SXML: S-expression eXtensible Markup LanguageSXML: S-expression eXtensible Markup Language
SXML: S-expression eXtensible Markup Language
elliando dias
 
Nuxeo JavaOne 2007
Nuxeo JavaOne 2007Nuxeo JavaOne 2007
Nuxeo JavaOne 2007
Stefane Fermigier
 

Semelhante a The Lumber Mill Xslt For Your Templates (20)

XML Schema Patterns for Databinding
XML Schema Patterns for DatabindingXML Schema Patterns for Databinding
XML Schema Patterns for Databinding
 
Using Stratego/XT for generation of software connectors.
Using Stratego/XT for generation of software connectors.Using Stratego/XT for generation of software connectors.
Using Stratego/XT for generation of software connectors.
 
Developing web apps using Erlang-Web
Developing web apps using Erlang-WebDeveloping web apps using Erlang-Web
Developing web apps using Erlang-Web
 
Inroduction to XSLT with PHP4
Inroduction to XSLT with PHP4Inroduction to XSLT with PHP4
Inroduction to XSLT with PHP4
 
Mashups with Drupal and QueryPath
Mashups with Drupal and QueryPathMashups with Drupal and QueryPath
Mashups with Drupal and QueryPath
 
XML Tools for Perl
XML Tools for PerlXML Tools for Perl
XML Tools for Perl
 
SXML: S-expression eXtensible Markup Language
SXML: S-expression eXtensible Markup LanguageSXML: S-expression eXtensible Markup Language
SXML: S-expression eXtensible Markup Language
 
Nuxeo JavaOne 2007
Nuxeo JavaOne 2007Nuxeo JavaOne 2007
Nuxeo JavaOne 2007
 
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
 
eXtensible Markup Language (XML)
eXtensible Markup Language (XML)eXtensible Markup Language (XML)
eXtensible Markup Language (XML)
 
Black Hat: XML Out-Of-Band Data Retrieval
Black Hat: XML Out-Of-Band Data RetrievalBlack Hat: XML Out-Of-Band Data Retrieval
Black Hat: XML Out-Of-Band Data Retrieval
 
Introduction to JavaScript
Introduction to JavaScriptIntroduction to JavaScript
Introduction to JavaScript
 
Extensible markup language attacks
Extensible markup language attacksExtensible markup language attacks
Extensible markup language attacks
 
Kommons
KommonsKommons
Kommons
 
Open Standards for the Semantic Web: XML / RDF(S) / OWL / SOAP
Open Standards for the Semantic Web: XML / RDF(S) / OWL / SOAPOpen Standards for the Semantic Web: XML / RDF(S) / OWL / SOAP
Open Standards for the Semantic Web: XML / RDF(S) / OWL / SOAP
 
XML - State of the Art
XML - State of the ArtXML - State of the Art
XML - State of the Art
 
Project Automation
Project AutomationProject Automation
Project Automation
 
Xml
XmlXml
Xml
 
Using existing language skillsets to create large-scale, cloud-based analytics
Using existing language skillsets to create large-scale, cloud-based analyticsUsing existing language skillsets to create large-scale, cloud-based analytics
Using existing language skillsets to create large-scale, cloud-based analytics
 
The Ebook Developer's Toolbox - ebookcraft 2016 - Sanders Kleinfeld
The Ebook Developer's Toolbox - ebookcraft 2016 - Sanders Kleinfeld The Ebook Developer's Toolbox - ebookcraft 2016 - Sanders Kleinfeld
The Ebook Developer's Toolbox - ebookcraft 2016 - Sanders Kleinfeld
 

Mais de 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
 

Último

Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
Joaquim Jorge
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
vu2urc
 
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
 

Último (20)

Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivity
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
 
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
 
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...
 
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?
 
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
 
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
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreter
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed texts
 
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
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
 
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
 
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
 
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
 
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
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonets
 
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
 

The Lumber Mill Xslt For Your Templates

  • 1. IPC09 Spring Edition Thomas Weinert quot;The Lumber Millquot; Using XSLT For Your Templates
  • 2. About Me ● 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 – quot;layout textsquot; ● 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/