SlideShare a Scribd company logo
Introduction to XSLT with PHP4 PHPCon 2002 10/25/2002, Millbrae California USA Stephan Schmidt
Table of Contents About the speaker Structuring content XML basics Introduction to XSLT Using PHP‘s XSLT functions Advanced XSLT Drawbacks of XSLT Transforming XML without XSLT patXMLRenderer Similar applications
Stephan Schmidt Web application developer since 1999 Working for Metrix Internet Design GmbH in Germany Maintainer of  www.php-tools.net Author of patTemplate, patXMLRenderer, patUser and others Focussing on the combination of XML and PHP and the separation of content and layout
Separation of content and layout Why? Modify layout without accessing content Modify content without accessing layout Different views for different devices (Browser, mobile phone,…) Different views for different user types (visitor, client, administrator) How? Different approaches…
Structuring content Classic websites and the use of HTML: » no structure at all » not readable by machines Classic software-development uses RDBMs: » hardly readable by humans Use of relations to implement structure Use of several table (normalization) Use of cryptic IDs
Using XML for structured data Readable by humans: » complete data in one file » self-explaining tag names » self-explaining attribute names » structured by indentation Readable by machines: » Well-formed document » only ASCII data » Validation with DTD or schema Separation of content and layout
Building a content structure 1 Split content into logical elements navigation Sections and parargraphs Lists and list elements Tags should describe their content, e.g. use <important> for important parts in you page No layout-elements like <br>, use <p>...</p> instead Define and write down page structure XML Schema DTD
Building a content structure 2
Building a content structure 3
Building a content structure 4
Basic XML Rules Each document needs a root element Each tag has to be closed, i.e. <p>…</p> instead of just <p> Use trailing slash to indicate an empty element (<br/> instead of <br>) Elements may not overlap (<p>…<b>…</b>…</p> instead of <p>…<b>…</p>…</b>) Attribute values have to be enclosed in double quotes Entities for <, >, &, “ and ‘ have to be used
XML Example <page> <headline> Introduction to XSLT </headline> <section title=&quot;Abstract&quot;> <para> The presentation includes </para> <list> <listelement> Examples </listelement> <listelement> Some PHP code </listelement> </list> </section> <section title=&quot;About the author&quot;> <para> Web developer from Germany </para> </section> </page>
Tree view of a document Each piece of information in an XML document is referred  to as a node: Element Nodes (tags) Attribute Nodes (attributes of a tag) Text Nodes (text and Cdata sections) Comment Nodes (<!-- ... -->) Processing Instruction Nodes (<?PHP ... ?>) Namespace Nodes (xmlns:myns=“...“)
Tree view of a document (example)
XML Transformations Each tag has to be transformed into an HTML representation: <headline> Introduction to XSLT </headline> … is transformed to: <font size=&quot;+1&quot;> <br><b> Introduction to XSLT </b><br><br> </font>
Introduction to XSLT Stylesheet must be an XML document (well-formed and valid) Based on pattern-matching („When you see something that looks like this, do something else“) Free of sideeffects (One rule may not influence or modify others) Use of iteration and recursion
„ Hello World“ Example (XML) Sample Document: <?xml version=&quot;1.0&quot;?> <greetings> <greeting> Hello World! </greeting> </greetings>
„ Hello World“ Example (XSL) <xsl:stylesheet xmlns:xsl= &quot;http://www.w3.org/1999/XSL/Transform&quot;  version= &quot;1.0&quot; > <xsl:output method= &quot;html&quot; /> <xsl:template match= &quot;/&quot; > <html> <body> <xsl:apply-templates select= &quot;greetings/greeting&quot; /> </body> </html> </xsl:template> <xsl:template match= &quot;greeting&quot; > <h1> <xsl:value-of select= &quot;.&quot; /> </h1> </xsl:template> </xsl:stylesheet>
„ Hello World“ Example (Output)
Closer look at the XSL template <xsl:stylesheet>  root element and its attributes are mandatory <xsl:output/>  defines output format (sets some properties in the XSLT processor ) Two  <xsl:template>  tags define how XML elements are transformed <xsl:apply-templates>  invokes other templates
Transformation Workflow Read stylesheet, so that each part may be easily accessed Read the XML document and build tree view of the document Transform the document Check for nodes to process („the context“) Get the next node from the context Get transformation rule and transform the node As a rule may invoke other rules, the document is  processed recursively.
Using PHP‘s XSLT functions Run configure with the --enable-xslt --with-xslt-sablot  options. Create XSLT processor with xslt_create() Apply stylesheet to XML document with xslt_process() (Strings or Files may be used) Free memory with xslt_free() Take a look at the example.
Using PHP‘s XSLT functions $xmlFile =  &quot;xml/helloworld.xml&quot; ; $xslFile =  &quot;xsl/helloworld.xsl&quot; ; if ( !$xp =  xslt_create () ) die (  &quot;XSLT processor could not be created.&quot;  ); if ( $result =  @xslt_process ( $xp, $xmlFile, $xslFile ) ) { echo $result; } else { echo   &quot;An error occured: &quot;  . xslt_error ( $xp ). &quot; (error code &quot; .  xslt_errno ( $xp ). &quot;)&quot; ; } xslt_free ( $xp );
xslt_process() Accepts six parameters: A handle, representing the XSLT processor The name of the file or buffer containing the XML data The name of the file or buffer containing the XSL data The name of the file to save the result to (optional) An associative array of argument buffers (for transforming strings on-the-fly) An associative array of XSLT parameters (may be used as $paramName in stylesheet)
Other XSLT functions xslt_error () and  xslt_errno () to retrieve the last error xslt_set_error_handler () to define a custom error handler (not stable in PHP 4.3) xslt_set_log () to log processor messages to a logfile Too complicated? »  use patXSLT...
patXSLT Soon available for download at  http://www.php-tools.net Simple interface for all  xslt_*  functions: require_once (  &quot;include/patXSLT.php&quot;  ); $proc =  new  patXSLT(); $proc->setXMLFile(  &quot;xml/helloworld.xml&quot;  ); $proc->setXSLFile(  &quot;xsl/helloworld.xsl&quot;  ); $proc->enableLogging(  &quot;logs/xslt.log&quot;  ); $proc->addParam(  &quot;pagetitle &quot; , $pageTitle ); $proc->transform();
XPath expressions Describe parts of an XML document (elements, attributes, text, ...) May be used in select and match attributes of various elements Melting pot of programming languages ($x*4) and Unix-like path expressions (like /page/section/para) Works with the parsed version of XML documents, which means no access to entities and no possibility to decide whether a text node was text or Cdata Example XPath expressions:  „/“ ,  „greetings/greeting“  and  „greeting“
Location Paths One of the most common uses of XPath Always in respect of the context („the current directory“) Relative and absolute expressions (always evaluated from the root node) Simple location paths: <xsl:template match= “/“ >  (root node) <xsl:value-of select= “.“ />  (context node) <xsl:value-of select= “..“ />  (parent node) <xsl:apply-templates select= “greeting“ /> <xsl:apply-templates select= “/page/section“ />
Selecting Things Besides Elements Selecting attributes /page/section/@title Selecting text nodes /page/title/text() Selecting comments and processing instructions /page/comment()  and  /page/processing-instruction()
Example: The World Answers (1) Sample document: <?xml version=&quot;1.0&quot;?> <greetings> <greeting author= &quot;Stephan&quot; > Hello World! </greeting> <greeting author= &quot;World&quot; > Hello Stephan! </greeting> </greetings>
Example: The World Answers (2) <xsl:stylesheet xmlns:xsl =&quot;http://www.w3.org/1999/XSL/Transform&quot;  version= &quot;1.0&quot; > <xsl:output method= &quot;html&quot; /> <xsl:template match= &quot;/&quot; > <html> <body> <xsl:apply-templates select= &quot;greetings/greeting&quot; /> </body> </html> </xsl:template> <xsl:template match= &quot;greeting&quot; > <h1> <xsl:value-of select= &quot;@author&quot; /> <xsl:text>  says:  </xsl:text> <xsl:value-of select= &quot;.&quot; /> </h1> </xsl:template> </xsl:stylesheet>
Example: The World Answers (3)
Axes in a document By  default child axis is used, but there are several axes: Child axis (default) Parent axis (..) Self axis (.) Attribute axis (@) Ancestor axis (ancestor::) Descendant axis (descendant::) Preceding-sibling axis (preceding-sibling::) Following-sibling axis (following-sibling::)
Control Elements <xsl:if test= “...“ >  implements an if statement   The expression in test attribute is converted to a boolean  value. Examples: <xsl:if test= “count(section)&gt;3“ > <xsl:if test= “@title“ > <xsl:choose> ,  <xsl:when>  and  <xsl:otherwise>  implement a switch/case statement. Also used to implement an if-then-else statement. Example needed?
Example: A conversation (2) Sample document: <?xml version=&quot;1.0&quot;?> <greetings> <greeting author= &quot;Stephan&quot; > Hello World! </greeting> <greeting author= &quot;World&quot; > Hello Stephan! </greeting> <greeting> Hello both of you! </greeting> </greetings>
Example: A conversation (1) <xsl:template match= &quot;greeting&quot; > <h1> <xsl:choose> <xsl:when test= &quot;@author&quot; > <xsl:value-of select= &quot;@author&quot; /> <xsl:text>  says:  </xsl:text> <xsl:value-of select= &quot;.&quot; /> </xsl:when> <xsl:otherwise> <xsl:text> Somebody says:  </xsl:text> <xsl:value-of select= &quot;.&quot; /> </xsl:otherwise> </xsl:choose> </h1> </xsl:template>
Example: A conversation (3)
Additional XSLT Features Wildcards (*, @*, //) Predicates (line[3], entry[position() mod 2 = 0]) <xsl:for-each>  to process several nodes <xsl:template mode= “...“ >  and  <xsl:apply-templates mode= “...“ > Parameters, that may be passed with  <xsl:apply-templates>  or  from PHP Variables (may not be changed!) Sorting and grouping
Drawbacks of XSLT Needs to be installed (requires Sablotron) Designer needs to learn XSLT tags The XSLT-processor is a black-box: No possibilty to pause or influence the process once it has started It is not possible to include dynamic content into an XML file while processing.
Transforming XML with PHP HTML Template for each XML element Attribute values are used as template variables The content of an element is a special template variable:  {CONTENT} The XML document is parsed recursively using SAX-based parser
Example <section title= &quot;XML Transformation&quot; > <para> XML may be transformed using PHP. </para> </section> XML Template for  <section> Template for  <para> <table border= &quot;0&quot;  cellpadding= &quot;0&quot;  cellspacing= &quot;2&quot;  width= &quot;500&quot; > <tr><td><b> {TITLE} </b></td><tr> <tr><td> {CONTENT} </td></tr> </table> <font face= &quot; Arial &quot;  size= &quot; 2 &quot; > {CONTENT} <br> </font>
Including Dynamic Content By using callbacks, each PHP function may be used at any time. Simple Example:  <time:current/>  should insert current time. Solution:   switch/case statement in element handler that executes PHP code instead  of replacing the tag with its template. »  code is hard to maintain Improvement:   extensible parser, that invokes callbacks for specific namespaces.
Randy - patXMLRenderer Open source (LGPL License) Uses the template class patTemplate Supports external entities („XML includes“) Unlimited amount of extensions. Tags will be passed to an extension according to namespaces The renderer only transforms static content and content returned by extensions Unlimited amount of designs Other features: caching, logging, etc...
Architecture RENDERER HTML / XML /LaTEX /usw... Any extension XML TEMPLATES Time: Extension Dbc: Extension Ext. Entities
Existing Extensions Repository on  http://www.php-tools.de Documentation is generated automatically Examples: <time:...>  date and time functions <dbc:...>  database interface <var:...>  access to variables <control:...>  control structures <randy:...>  XML-API for patXMLRenderer <file:...>  file operations and many more...
Similar Applications At least two more applications: PEAR::XML_Transformer http:// pear.php.net Only overloads tags with functions and methods. phpTagLib http://chocobot.d2g.com Only transforms XML to HTML.
Comparison - - X Parameters Only with PHP code - X „ Intelligent“ Templates - All in one package X Ext. Repository - - X Administration X - X <?PHP ?> - - X External Entities - Yes, infinite Yes, infinite Recursion - X X Namespaces - Yes, objects and functions Yes, only object Dynamic Content (Callbacks) yes, plain HTML - yes, patTemplate Templates phpTagLib PEAR patXMLRenderer
XSLT vs PHP Transformers Pro XSLT: Much faster than PHP transformers W3C Standard (works with any XSLT Processor) Pro PHP Transfomers: Easily extendable Easier to learn Script has complete control during the transformation process
The End Thank you! More information: http://www.php-tools.net [email_address] Thanks to: Sebastian Mordziol, Gerd Schaufelberger, Stephan Eisler,  Metrix Internet Design GmbH

More Related Content

What's hot (20)

PDF Localization
PDF  LocalizationPDF  Localization
PDF Localization
Suite Solutions
 
AdvancedXPath
AdvancedXPathAdvancedXPath
AdvancedXPath
Suite Solutions
 
ImplementingChangeTrackingAndFlagging
ImplementingChangeTrackingAndFlaggingImplementingChangeTrackingAndFlagging
ImplementingChangeTrackingAndFlagging
Suite Solutions
 
Debugging and Error handling
Debugging and Error handlingDebugging and Error handling
Debugging and Error handling
Suite Solutions
 
LocalizingStyleSheetsForHTMLOutputs
LocalizingStyleSheetsForHTMLOutputsLocalizingStyleSheetsForHTMLOutputs
LocalizingStyleSheetsForHTMLOutputs
Suite Solutions
 
Ot performance webinar
Ot performance webinarOt performance webinar
Ot performance webinar
Suite Solutions
 
C:\Users\User\Desktop\Eclipse Infocenter
C:\Users\User\Desktop\Eclipse InfocenterC:\Users\User\Desktop\Eclipse Infocenter
C:\Users\User\Desktop\Eclipse Infocenter
Suite Solutions
 
Open Source Package Php Mysql 1228203701094763 9
Open Source Package Php Mysql 1228203701094763 9Open Source Package Php Mysql 1228203701094763 9
Open Source Package Php Mysql 1228203701094763 9
isadorta
 
Dost.jar and fo.jar
Dost.jar and fo.jarDost.jar and fo.jar
Dost.jar and fo.jar
Suite Solutions
 
PHP MySQL
PHP MySQLPHP MySQL
PHP MySQL
Md. Sirajus Salayhin
 
Php and MySQL
Php and MySQLPhp and MySQL
Php and MySQL
Tiji Thomas
 
lf-2003_01-0269
lf-2003_01-0269lf-2003_01-0269
lf-2003_01-0269
tutorialsruby
 
Phpwebdev
PhpwebdevPhpwebdev
Phpwebdev
Luv'k Verma
 
Architecting Web Services
Architecting Web ServicesArchitecting Web Services
Architecting Web Services
Lorna Mitchell
 
Overview of PHP and MYSQL
Overview of PHP and MYSQLOverview of PHP and MYSQL
Overview of PHP and MYSQL
Deblina Chowdhury
 
Web Development Course: PHP lecture 1
Web Development Course: PHP lecture 1Web Development Course: PHP lecture 1
Web Development Course: PHP lecture 1
Gheyath M. Othman
 
Php Simple Xml
Php Simple XmlPhp Simple Xml
Php Simple Xml
mussawir20
 
PHP Presentation
PHP PresentationPHP Presentation
PHP Presentation
Nikhil Jain
 
PHP NOTES FOR BEGGINERS
PHP NOTES FOR BEGGINERSPHP NOTES FOR BEGGINERS
PHP NOTES FOR BEGGINERS
Aminiel Michael
 
Php mysql
Php mysqlPhp mysql
Php mysql
Abu Bakar
 
ImplementingChangeTrackingAndFlagging
ImplementingChangeTrackingAndFlaggingImplementingChangeTrackingAndFlagging
ImplementingChangeTrackingAndFlagging
Suite Solutions
 
Debugging and Error handling
Debugging and Error handlingDebugging and Error handling
Debugging and Error handling
Suite Solutions
 
LocalizingStyleSheetsForHTMLOutputs
LocalizingStyleSheetsForHTMLOutputsLocalizingStyleSheetsForHTMLOutputs
LocalizingStyleSheetsForHTMLOutputs
Suite Solutions
 
C:\Users\User\Desktop\Eclipse Infocenter
C:\Users\User\Desktop\Eclipse InfocenterC:\Users\User\Desktop\Eclipse Infocenter
C:\Users\User\Desktop\Eclipse Infocenter
Suite Solutions
 
Open Source Package Php Mysql 1228203701094763 9
Open Source Package Php Mysql 1228203701094763 9Open Source Package Php Mysql 1228203701094763 9
Open Source Package Php Mysql 1228203701094763 9
isadorta
 
Architecting Web Services
Architecting Web ServicesArchitecting Web Services
Architecting Web Services
Lorna Mitchell
 
Web Development Course: PHP lecture 1
Web Development Course: PHP lecture 1Web Development Course: PHP lecture 1
Web Development Course: PHP lecture 1
Gheyath M. Othman
 
Php Simple Xml
Php Simple XmlPhp Simple Xml
Php Simple Xml
mussawir20
 
PHP Presentation
PHP PresentationPHP Presentation
PHP Presentation
Nikhil Jain
 

Similar to Inroduction to XSLT with PHP4 (20)

Xml
XmlXml
Xml
guestcacd813
 
C:\fakepath\xsl final
C:\fakepath\xsl finalC:\fakepath\xsl final
C:\fakepath\xsl final
shivpriya
 
5 xsl (formatting xml documents)
5   xsl (formatting xml documents)5   xsl (formatting xml documents)
5 xsl (formatting xml documents)
gauravashq
 
Learning XSLT
Learning XSLTLearning XSLT
Learning XSLT
Overdue Books LLC
 
Xml
XmlXml
Xml
Sudharsan S
 
Session 4
Session 4Session 4
Session 4
Lại Đức Chung
 
XML and XSLT
XML and XSLTXML and XSLT
XML and XSLT
Andrew Savory
 
Xml and Co.
Xml and Co.Xml and Co.
Xml and Co.
Findik Dervis
 
XPATH_XSLT-1.pptx
XPATH_XSLT-1.pptxXPATH_XSLT-1.pptx
XPATH_XSLT-1.pptx
BalasundaramSr
 
Introduction to XSLT
Introduction to XSLTIntroduction to XSLT
Introduction to XSLT
Mahmoud Allam
 
Extensible Stylesheet Language
Extensible Stylesheet LanguageExtensible Stylesheet Language
Extensible Stylesheet Language
Jussi Pohjolainen
 
Notes from the Library Juice Academy courses on XPath, XSLT, and XQuery: Univ...
Notes from the Library Juice Academy courses on XPath, XSLT, and XQuery: Univ...Notes from the Library Juice Academy courses on XPath, XSLT, and XQuery: Univ...
Notes from the Library Juice Academy courses on XPath, XSLT, and XQuery: Univ...
Allison Jai O'Dell
 
XMLT
XMLTXMLT
XMLT
Kunal Gaind
 
XSLT
XSLTXSLT
XSLT
Kamal Acharya
 
XML XSLT
XML XSLTXML XSLT
XML XSLT
Vijay Kumar Verma
 
transforming xml using xsl and xslt
transforming xml using xsl and xslttransforming xml using xsl and xslt
transforming xml using xsl and xslt
Hemant Suthar
 
Week 12 xml and xsl
Week 12 xml and xslWeek 12 xml and xsl
Week 12 xml and xsl
hapy
 
Xslt
XsltXslt
Xslt
Manav Prasad
 
Xml part5
Xml part5Xml part5
Xml part5
NOHA AW
 
Rendering XML Documents
Rendering XML DocumentsRendering XML Documents
Rendering XML Documents
yht4ever
 
Ad

More from Stephan Schmidt (17)

Das Web Wird Mobil - Geolocation und Location Based Services
Das Web Wird Mobil - Geolocation und Location Based ServicesDas Web Wird Mobil - Geolocation und Location Based Services
Das Web Wird Mobil - Geolocation und Location Based Services
Stephan Schmidt
 
23 Dinge, die Sie über Software Entwicklung in Teams wissen sollten
23 Dinge, die Sie über Software Entwicklung in Teams wissen sollten23 Dinge, die Sie über Software Entwicklung in Teams wissen sollten
23 Dinge, die Sie über Software Entwicklung in Teams wissen sollten
Stephan Schmidt
 
23 Dinge, die Sie über Software-Entwicklung in Teams wissen sollten
23 Dinge, die Sie über Software-Entwicklung in Teams wissen sollten23 Dinge, die Sie über Software-Entwicklung in Teams wissen sollten
23 Dinge, die Sie über Software-Entwicklung in Teams wissen sollten
Stephan Schmidt
 
Continuous Integration mit Jenkins
Continuous Integration mit JenkinsContinuous Integration mit Jenkins
Continuous Integration mit Jenkins
Stephan Schmidt
 
Die Kunst des Software Design - Java
Die Kunst des Software Design - JavaDie Kunst des Software Design - Java
Die Kunst des Software Design - Java
Stephan Schmidt
 
PHP mit Paul Bocuse
PHP mit Paul BocusePHP mit Paul Bocuse
PHP mit Paul Bocuse
Stephan Schmidt
 
Der Erfolgreiche Programmierer
Der Erfolgreiche ProgrammiererDer Erfolgreiche Programmierer
Der Erfolgreiche Programmierer
Stephan Schmidt
 
23 Dinge, die Sie über Software-Entwicklung in Teams wissen sollten.
23 Dinge, die Sie über Software-Entwicklung in Teams wissen sollten.23 Dinge, die Sie über Software-Entwicklung in Teams wissen sollten.
23 Dinge, die Sie über Software-Entwicklung in Teams wissen sollten.
Stephan Schmidt
 
Die Kunst Des Software Design
Die Kunst Des Software DesignDie Kunst Des Software Design
Die Kunst Des Software Design
Stephan Schmidt
 
Software-Entwicklung Im Team
Software-Entwicklung Im TeamSoftware-Entwicklung Im Team
Software-Entwicklung Im Team
Stephan Schmidt
 
JSON-RPC Proxy Generation with PHP 5
JSON-RPC Proxy Generation with PHP 5JSON-RPC Proxy Generation with PHP 5
JSON-RPC Proxy Generation with PHP 5
Stephan Schmidt
 
Declarative Development Using Annotations In PHP
Declarative Development Using Annotations In PHPDeclarative Development Using Annotations In PHP
Declarative Development Using Annotations In PHP
Stephan Schmidt
 
XML-Socket-Server zur Kommunikation mit Flash
XML-Socket-Server zur Kommunikation mit FlashXML-Socket-Server zur Kommunikation mit Flash
XML-Socket-Server zur Kommunikation mit Flash
Stephan Schmidt
 
Interprozesskommunikation mit PHP
Interprozesskommunikation mit PHPInterprozesskommunikation mit PHP
Interprozesskommunikation mit PHP
Stephan Schmidt
 
PHP im High End
PHP im High EndPHP im High End
PHP im High End
Stephan Schmidt
 
Dynamische Websites mit XML
Dynamische Websites mit XMLDynamische Websites mit XML
Dynamische Websites mit XML
Stephan Schmidt
 
Web 2.0 Mit Der Yahoo User Interface Library
Web 2.0 Mit Der Yahoo User Interface LibraryWeb 2.0 Mit Der Yahoo User Interface Library
Web 2.0 Mit Der Yahoo User Interface Library
Stephan Schmidt
 
Das Web Wird Mobil - Geolocation und Location Based Services
Das Web Wird Mobil - Geolocation und Location Based ServicesDas Web Wird Mobil - Geolocation und Location Based Services
Das Web Wird Mobil - Geolocation und Location Based Services
Stephan Schmidt
 
23 Dinge, die Sie über Software Entwicklung in Teams wissen sollten
23 Dinge, die Sie über Software Entwicklung in Teams wissen sollten23 Dinge, die Sie über Software Entwicklung in Teams wissen sollten
23 Dinge, die Sie über Software Entwicklung in Teams wissen sollten
Stephan Schmidt
 
23 Dinge, die Sie über Software-Entwicklung in Teams wissen sollten
23 Dinge, die Sie über Software-Entwicklung in Teams wissen sollten23 Dinge, die Sie über Software-Entwicklung in Teams wissen sollten
23 Dinge, die Sie über Software-Entwicklung in Teams wissen sollten
Stephan Schmidt
 
Continuous Integration mit Jenkins
Continuous Integration mit JenkinsContinuous Integration mit Jenkins
Continuous Integration mit Jenkins
Stephan Schmidt
 
Die Kunst des Software Design - Java
Die Kunst des Software Design - JavaDie Kunst des Software Design - Java
Die Kunst des Software Design - Java
Stephan Schmidt
 
Der Erfolgreiche Programmierer
Der Erfolgreiche ProgrammiererDer Erfolgreiche Programmierer
Der Erfolgreiche Programmierer
Stephan Schmidt
 
23 Dinge, die Sie über Software-Entwicklung in Teams wissen sollten.
23 Dinge, die Sie über Software-Entwicklung in Teams wissen sollten.23 Dinge, die Sie über Software-Entwicklung in Teams wissen sollten.
23 Dinge, die Sie über Software-Entwicklung in Teams wissen sollten.
Stephan Schmidt
 
Die Kunst Des Software Design
Die Kunst Des Software DesignDie Kunst Des Software Design
Die Kunst Des Software Design
Stephan Schmidt
 
Software-Entwicklung Im Team
Software-Entwicklung Im TeamSoftware-Entwicklung Im Team
Software-Entwicklung Im Team
Stephan Schmidt
 
JSON-RPC Proxy Generation with PHP 5
JSON-RPC Proxy Generation with PHP 5JSON-RPC Proxy Generation with PHP 5
JSON-RPC Proxy Generation with PHP 5
Stephan Schmidt
 
Declarative Development Using Annotations In PHP
Declarative Development Using Annotations In PHPDeclarative Development Using Annotations In PHP
Declarative Development Using Annotations In PHP
Stephan Schmidt
 
XML-Socket-Server zur Kommunikation mit Flash
XML-Socket-Server zur Kommunikation mit FlashXML-Socket-Server zur Kommunikation mit Flash
XML-Socket-Server zur Kommunikation mit Flash
Stephan Schmidt
 
Interprozesskommunikation mit PHP
Interprozesskommunikation mit PHPInterprozesskommunikation mit PHP
Interprozesskommunikation mit PHP
Stephan Schmidt
 
Dynamische Websites mit XML
Dynamische Websites mit XMLDynamische Websites mit XML
Dynamische Websites mit XML
Stephan Schmidt
 
Web 2.0 Mit Der Yahoo User Interface Library
Web 2.0 Mit Der Yahoo User Interface LibraryWeb 2.0 Mit Der Yahoo User Interface Library
Web 2.0 Mit Der Yahoo User Interface Library
Stephan Schmidt
 
Ad

Recently uploaded (20)

Developing Schemas with FME and Excel - Peak of Data & AI 2025
Developing Schemas with FME and Excel - Peak of Data & AI 2025Developing Schemas with FME and Excel - Peak of Data & AI 2025
Developing Schemas with FME and Excel - Peak of Data & AI 2025
Safe Software
 
Establish Visibility and Manage Risk in the Supply Chain with Anchore SBOM
Establish Visibility and Manage Risk in the Supply Chain with Anchore SBOMEstablish Visibility and Manage Risk in the Supply Chain with Anchore SBOM
Establish Visibility and Manage Risk in the Supply Chain with Anchore SBOM
Anchore
 
Scaling GenAI Inference From Prototype to Production: Real-World Lessons in S...
Scaling GenAI Inference From Prototype to Production: Real-World Lessons in S...Scaling GenAI Inference From Prototype to Production: Real-World Lessons in S...
Scaling GenAI Inference From Prototype to Production: Real-World Lessons in S...
Anish Kumar
 
Domino IQ – Was Sie erwartet, erste Schritte und Anwendungsfälle
Domino IQ – Was Sie erwartet, erste Schritte und AnwendungsfälleDomino IQ – Was Sie erwartet, erste Schritte und Anwendungsfälle
Domino IQ – Was Sie erwartet, erste Schritte und Anwendungsfälle
panagenda
 
Jira Administration Training – Day 1 : Introduction
Jira Administration Training – Day 1 : IntroductionJira Administration Training – Day 1 : Introduction
Jira Administration Training – Day 1 : Introduction
Ravi Teja
 
ELNL2025 - Unlocking the Power of Sensitivity Labels - A Comprehensive Guide....
ELNL2025 - Unlocking the Power of Sensitivity Labels - A Comprehensive Guide....ELNL2025 - Unlocking the Power of Sensitivity Labels - A Comprehensive Guide....
ELNL2025 - Unlocking the Power of Sensitivity Labels - A Comprehensive Guide....
Jasper Oosterveld
 
7 Salesforce Data Cloud Best Practices.pdf
7 Salesforce Data Cloud Best Practices.pdf7 Salesforce Data Cloud Best Practices.pdf
7 Salesforce Data Cloud Best Practices.pdf
Minuscule Technologies
 
“State-space Models vs. Transformers for Ultra-low-power Edge AI,” a Presenta...
“State-space Models vs. Transformers for Ultra-low-power Edge AI,” a Presenta...“State-space Models vs. Transformers for Ultra-low-power Edge AI,” a Presenta...
“State-space Models vs. Transformers for Ultra-low-power Edge AI,” a Presenta...
Edge AI and Vision Alliance
 
Your startup on AWS - How to architect and maintain a Lean and Mean account
Your startup on AWS - How to architect and maintain a Lean and Mean accountYour startup on AWS - How to architect and maintain a Lean and Mean account
Your startup on AWS - How to architect and maintain a Lean and Mean account
angelo60207
 
IntroSlides-May-BuildWithAi-EarthEngine.pdf
IntroSlides-May-BuildWithAi-EarthEngine.pdfIntroSlides-May-BuildWithAi-EarthEngine.pdf
IntroSlides-May-BuildWithAi-EarthEngine.pdf
Luiz Carneiro
 
Introduction to Internet of things .ppt.
Introduction to Internet of things .ppt.Introduction to Internet of things .ppt.
Introduction to Internet of things .ppt.
hok12341073
 
Securiport - A Border Security Company
Securiport  -  A Border Security CompanySecuriport  -  A Border Security Company
Securiport - A Border Security Company
Securiport
 
Boosting MySQL with Vector Search -THE VECTOR SEARCH CONFERENCE 2025 .pdf
Boosting MySQL with Vector Search -THE VECTOR SEARCH CONFERENCE 2025 .pdfBoosting MySQL with Vector Search -THE VECTOR SEARCH CONFERENCE 2025 .pdf
Boosting MySQL with Vector Search -THE VECTOR SEARCH CONFERENCE 2025 .pdf
Alkin Tezuysal
 
Introduction to Typescript - GDG On Campus EUE
Introduction to Typescript - GDG On Campus EUEIntroduction to Typescript - GDG On Campus EUE
Introduction to Typescript - GDG On Campus EUE
Google Developer Group On Campus European Universities in Egypt
 
Agentic AI: Beyond the Buzz- LangGraph Studio V2
Agentic AI: Beyond the Buzz- LangGraph Studio V2Agentic AI: Beyond the Buzz- LangGraph Studio V2
Agentic AI: Beyond the Buzz- LangGraph Studio V2
Shashikant Jagtap
 
What is Oracle EPM A Guide to Oracle EPM Cloud Everything You Need to Know
What is Oracle EPM A Guide to Oracle EPM Cloud Everything You Need to KnowWhat is Oracle EPM A Guide to Oracle EPM Cloud Everything You Need to Know
What is Oracle EPM A Guide to Oracle EPM Cloud Everything You Need to Know
SMACT Works
 
Data Virtualization: Bringing the Power of FME to Any Application
Data Virtualization: Bringing the Power of FME to Any ApplicationData Virtualization: Bringing the Power of FME to Any Application
Data Virtualization: Bringing the Power of FME to Any Application
Safe Software
 
AI Creative Generates You Passive Income Like Never Before
AI Creative Generates You Passive Income Like Never BeforeAI Creative Generates You Passive Income Like Never Before
AI Creative Generates You Passive Income Like Never Before
SivaRajan47
 
Cybersecurity Fundamentals: Apprentice - Palo Alto Certificate
Cybersecurity Fundamentals: Apprentice - Palo Alto CertificateCybersecurity Fundamentals: Apprentice - Palo Alto Certificate
Cybersecurity Fundamentals: Apprentice - Palo Alto Certificate
VICTOR MAESTRE RAMIREZ
 
If You Use Databricks, You Definitely Need FME
If You Use Databricks, You Definitely Need FMEIf You Use Databricks, You Definitely Need FME
If You Use Databricks, You Definitely Need FME
Safe Software
 
Developing Schemas with FME and Excel - Peak of Data & AI 2025
Developing Schemas with FME and Excel - Peak of Data & AI 2025Developing Schemas with FME and Excel - Peak of Data & AI 2025
Developing Schemas with FME and Excel - Peak of Data & AI 2025
Safe Software
 
Establish Visibility and Manage Risk in the Supply Chain with Anchore SBOM
Establish Visibility and Manage Risk in the Supply Chain with Anchore SBOMEstablish Visibility and Manage Risk in the Supply Chain with Anchore SBOM
Establish Visibility and Manage Risk in the Supply Chain with Anchore SBOM
Anchore
 
Scaling GenAI Inference From Prototype to Production: Real-World Lessons in S...
Scaling GenAI Inference From Prototype to Production: Real-World Lessons in S...Scaling GenAI Inference From Prototype to Production: Real-World Lessons in S...
Scaling GenAI Inference From Prototype to Production: Real-World Lessons in S...
Anish Kumar
 
Domino IQ – Was Sie erwartet, erste Schritte und Anwendungsfälle
Domino IQ – Was Sie erwartet, erste Schritte und AnwendungsfälleDomino IQ – Was Sie erwartet, erste Schritte und Anwendungsfälle
Domino IQ – Was Sie erwartet, erste Schritte und Anwendungsfälle
panagenda
 
Jira Administration Training – Day 1 : Introduction
Jira Administration Training – Day 1 : IntroductionJira Administration Training – Day 1 : Introduction
Jira Administration Training – Day 1 : Introduction
Ravi Teja
 
ELNL2025 - Unlocking the Power of Sensitivity Labels - A Comprehensive Guide....
ELNL2025 - Unlocking the Power of Sensitivity Labels - A Comprehensive Guide....ELNL2025 - Unlocking the Power of Sensitivity Labels - A Comprehensive Guide....
ELNL2025 - Unlocking the Power of Sensitivity Labels - A Comprehensive Guide....
Jasper Oosterveld
 
7 Salesforce Data Cloud Best Practices.pdf
7 Salesforce Data Cloud Best Practices.pdf7 Salesforce Data Cloud Best Practices.pdf
7 Salesforce Data Cloud Best Practices.pdf
Minuscule Technologies
 
“State-space Models vs. Transformers for Ultra-low-power Edge AI,” a Presenta...
“State-space Models vs. Transformers for Ultra-low-power Edge AI,” a Presenta...“State-space Models vs. Transformers for Ultra-low-power Edge AI,” a Presenta...
“State-space Models vs. Transformers for Ultra-low-power Edge AI,” a Presenta...
Edge AI and Vision Alliance
 
Your startup on AWS - How to architect and maintain a Lean and Mean account
Your startup on AWS - How to architect and maintain a Lean and Mean accountYour startup on AWS - How to architect and maintain a Lean and Mean account
Your startup on AWS - How to architect and maintain a Lean and Mean account
angelo60207
 
IntroSlides-May-BuildWithAi-EarthEngine.pdf
IntroSlides-May-BuildWithAi-EarthEngine.pdfIntroSlides-May-BuildWithAi-EarthEngine.pdf
IntroSlides-May-BuildWithAi-EarthEngine.pdf
Luiz Carneiro
 
Introduction to Internet of things .ppt.
Introduction to Internet of things .ppt.Introduction to Internet of things .ppt.
Introduction to Internet of things .ppt.
hok12341073
 
Securiport - A Border Security Company
Securiport  -  A Border Security CompanySecuriport  -  A Border Security Company
Securiport - A Border Security Company
Securiport
 
Boosting MySQL with Vector Search -THE VECTOR SEARCH CONFERENCE 2025 .pdf
Boosting MySQL with Vector Search -THE VECTOR SEARCH CONFERENCE 2025 .pdfBoosting MySQL with Vector Search -THE VECTOR SEARCH CONFERENCE 2025 .pdf
Boosting MySQL with Vector Search -THE VECTOR SEARCH CONFERENCE 2025 .pdf
Alkin Tezuysal
 
Agentic AI: Beyond the Buzz- LangGraph Studio V2
Agentic AI: Beyond the Buzz- LangGraph Studio V2Agentic AI: Beyond the Buzz- LangGraph Studio V2
Agentic AI: Beyond the Buzz- LangGraph Studio V2
Shashikant Jagtap
 
What is Oracle EPM A Guide to Oracle EPM Cloud Everything You Need to Know
What is Oracle EPM A Guide to Oracle EPM Cloud Everything You Need to KnowWhat is Oracle EPM A Guide to Oracle EPM Cloud Everything You Need to Know
What is Oracle EPM A Guide to Oracle EPM Cloud Everything You Need to Know
SMACT Works
 
Data Virtualization: Bringing the Power of FME to Any Application
Data Virtualization: Bringing the Power of FME to Any ApplicationData Virtualization: Bringing the Power of FME to Any Application
Data Virtualization: Bringing the Power of FME to Any Application
Safe Software
 
AI Creative Generates You Passive Income Like Never Before
AI Creative Generates You Passive Income Like Never BeforeAI Creative Generates You Passive Income Like Never Before
AI Creative Generates You Passive Income Like Never Before
SivaRajan47
 
Cybersecurity Fundamentals: Apprentice - Palo Alto Certificate
Cybersecurity Fundamentals: Apprentice - Palo Alto CertificateCybersecurity Fundamentals: Apprentice - Palo Alto Certificate
Cybersecurity Fundamentals: Apprentice - Palo Alto Certificate
VICTOR MAESTRE RAMIREZ
 
If You Use Databricks, You Definitely Need FME
If You Use Databricks, You Definitely Need FMEIf You Use Databricks, You Definitely Need FME
If You Use Databricks, You Definitely Need FME
Safe Software
 

Inroduction to XSLT with PHP4

  • 1. Introduction to XSLT with PHP4 PHPCon 2002 10/25/2002, Millbrae California USA Stephan Schmidt
  • 2. Table of Contents About the speaker Structuring content XML basics Introduction to XSLT Using PHP‘s XSLT functions Advanced XSLT Drawbacks of XSLT Transforming XML without XSLT patXMLRenderer Similar applications
  • 3. Stephan Schmidt Web application developer since 1999 Working for Metrix Internet Design GmbH in Germany Maintainer of www.php-tools.net Author of patTemplate, patXMLRenderer, patUser and others Focussing on the combination of XML and PHP and the separation of content and layout
  • 4. Separation of content and layout Why? Modify layout without accessing content Modify content without accessing layout Different views for different devices (Browser, mobile phone,…) Different views for different user types (visitor, client, administrator) How? Different approaches…
  • 5. Structuring content Classic websites and the use of HTML: » no structure at all » not readable by machines Classic software-development uses RDBMs: » hardly readable by humans Use of relations to implement structure Use of several table (normalization) Use of cryptic IDs
  • 6. Using XML for structured data Readable by humans: » complete data in one file » self-explaining tag names » self-explaining attribute names » structured by indentation Readable by machines: » Well-formed document » only ASCII data » Validation with DTD or schema Separation of content and layout
  • 7. Building a content structure 1 Split content into logical elements navigation Sections and parargraphs Lists and list elements Tags should describe their content, e.g. use <important> for important parts in you page No layout-elements like <br>, use <p>...</p> instead Define and write down page structure XML Schema DTD
  • 8. Building a content structure 2
  • 9. Building a content structure 3
  • 10. Building a content structure 4
  • 11. Basic XML Rules Each document needs a root element Each tag has to be closed, i.e. <p>…</p> instead of just <p> Use trailing slash to indicate an empty element (<br/> instead of <br>) Elements may not overlap (<p>…<b>…</b>…</p> instead of <p>…<b>…</p>…</b>) Attribute values have to be enclosed in double quotes Entities for <, >, &, “ and ‘ have to be used
  • 12. XML Example <page> <headline> Introduction to XSLT </headline> <section title=&quot;Abstract&quot;> <para> The presentation includes </para> <list> <listelement> Examples </listelement> <listelement> Some PHP code </listelement> </list> </section> <section title=&quot;About the author&quot;> <para> Web developer from Germany </para> </section> </page>
  • 13. Tree view of a document Each piece of information in an XML document is referred to as a node: Element Nodes (tags) Attribute Nodes (attributes of a tag) Text Nodes (text and Cdata sections) Comment Nodes (<!-- ... -->) Processing Instruction Nodes (<?PHP ... ?>) Namespace Nodes (xmlns:myns=“...“)
  • 14. Tree view of a document (example)
  • 15. XML Transformations Each tag has to be transformed into an HTML representation: <headline> Introduction to XSLT </headline> … is transformed to: <font size=&quot;+1&quot;> <br><b> Introduction to XSLT </b><br><br> </font>
  • 16. Introduction to XSLT Stylesheet must be an XML document (well-formed and valid) Based on pattern-matching („When you see something that looks like this, do something else“) Free of sideeffects (One rule may not influence or modify others) Use of iteration and recursion
  • 17. „ Hello World“ Example (XML) Sample Document: <?xml version=&quot;1.0&quot;?> <greetings> <greeting> Hello World! </greeting> </greetings>
  • 18. „ Hello World“ Example (XSL) <xsl:stylesheet xmlns:xsl= &quot;http://www.w3.org/1999/XSL/Transform&quot; version= &quot;1.0&quot; > <xsl:output method= &quot;html&quot; /> <xsl:template match= &quot;/&quot; > <html> <body> <xsl:apply-templates select= &quot;greetings/greeting&quot; /> </body> </html> </xsl:template> <xsl:template match= &quot;greeting&quot; > <h1> <xsl:value-of select= &quot;.&quot; /> </h1> </xsl:template> </xsl:stylesheet>
  • 19. „ Hello World“ Example (Output)
  • 20. Closer look at the XSL template <xsl:stylesheet> root element and its attributes are mandatory <xsl:output/> defines output format (sets some properties in the XSLT processor ) Two <xsl:template> tags define how XML elements are transformed <xsl:apply-templates> invokes other templates
  • 21. Transformation Workflow Read stylesheet, so that each part may be easily accessed Read the XML document and build tree view of the document Transform the document Check for nodes to process („the context“) Get the next node from the context Get transformation rule and transform the node As a rule may invoke other rules, the document is processed recursively.
  • 22. Using PHP‘s XSLT functions Run configure with the --enable-xslt --with-xslt-sablot options. Create XSLT processor with xslt_create() Apply stylesheet to XML document with xslt_process() (Strings or Files may be used) Free memory with xslt_free() Take a look at the example.
  • 23. Using PHP‘s XSLT functions $xmlFile = &quot;xml/helloworld.xml&quot; ; $xslFile = &quot;xsl/helloworld.xsl&quot; ; if ( !$xp = xslt_create () ) die ( &quot;XSLT processor could not be created.&quot; ); if ( $result = @xslt_process ( $xp, $xmlFile, $xslFile ) ) { echo $result; } else { echo &quot;An error occured: &quot; . xslt_error ( $xp ). &quot; (error code &quot; . xslt_errno ( $xp ). &quot;)&quot; ; } xslt_free ( $xp );
  • 24. xslt_process() Accepts six parameters: A handle, representing the XSLT processor The name of the file or buffer containing the XML data The name of the file or buffer containing the XSL data The name of the file to save the result to (optional) An associative array of argument buffers (for transforming strings on-the-fly) An associative array of XSLT parameters (may be used as $paramName in stylesheet)
  • 25. Other XSLT functions xslt_error () and xslt_errno () to retrieve the last error xslt_set_error_handler () to define a custom error handler (not stable in PHP 4.3) xslt_set_log () to log processor messages to a logfile Too complicated? » use patXSLT...
  • 26. patXSLT Soon available for download at http://www.php-tools.net Simple interface for all xslt_* functions: require_once ( &quot;include/patXSLT.php&quot; ); $proc = new patXSLT(); $proc->setXMLFile( &quot;xml/helloworld.xml&quot; ); $proc->setXSLFile( &quot;xsl/helloworld.xsl&quot; ); $proc->enableLogging( &quot;logs/xslt.log&quot; ); $proc->addParam( &quot;pagetitle &quot; , $pageTitle ); $proc->transform();
  • 27. XPath expressions Describe parts of an XML document (elements, attributes, text, ...) May be used in select and match attributes of various elements Melting pot of programming languages ($x*4) and Unix-like path expressions (like /page/section/para) Works with the parsed version of XML documents, which means no access to entities and no possibility to decide whether a text node was text or Cdata Example XPath expressions: „/“ , „greetings/greeting“ and „greeting“
  • 28. Location Paths One of the most common uses of XPath Always in respect of the context („the current directory“) Relative and absolute expressions (always evaluated from the root node) Simple location paths: <xsl:template match= “/“ > (root node) <xsl:value-of select= “.“ /> (context node) <xsl:value-of select= “..“ /> (parent node) <xsl:apply-templates select= “greeting“ /> <xsl:apply-templates select= “/page/section“ />
  • 29. Selecting Things Besides Elements Selecting attributes /page/section/@title Selecting text nodes /page/title/text() Selecting comments and processing instructions /page/comment() and /page/processing-instruction()
  • 30. Example: The World Answers (1) Sample document: <?xml version=&quot;1.0&quot;?> <greetings> <greeting author= &quot;Stephan&quot; > Hello World! </greeting> <greeting author= &quot;World&quot; > Hello Stephan! </greeting> </greetings>
  • 31. Example: The World Answers (2) <xsl:stylesheet xmlns:xsl =&quot;http://www.w3.org/1999/XSL/Transform&quot; version= &quot;1.0&quot; > <xsl:output method= &quot;html&quot; /> <xsl:template match= &quot;/&quot; > <html> <body> <xsl:apply-templates select= &quot;greetings/greeting&quot; /> </body> </html> </xsl:template> <xsl:template match= &quot;greeting&quot; > <h1> <xsl:value-of select= &quot;@author&quot; /> <xsl:text> says: </xsl:text> <xsl:value-of select= &quot;.&quot; /> </h1> </xsl:template> </xsl:stylesheet>
  • 32. Example: The World Answers (3)
  • 33. Axes in a document By default child axis is used, but there are several axes: Child axis (default) Parent axis (..) Self axis (.) Attribute axis (@) Ancestor axis (ancestor::) Descendant axis (descendant::) Preceding-sibling axis (preceding-sibling::) Following-sibling axis (following-sibling::)
  • 34. Control Elements <xsl:if test= “...“ > implements an if statement  The expression in test attribute is converted to a boolean value. Examples: <xsl:if test= “count(section)&gt;3“ > <xsl:if test= “@title“ > <xsl:choose> , <xsl:when> and <xsl:otherwise> implement a switch/case statement. Also used to implement an if-then-else statement. Example needed?
  • 35. Example: A conversation (2) Sample document: <?xml version=&quot;1.0&quot;?> <greetings> <greeting author= &quot;Stephan&quot; > Hello World! </greeting> <greeting author= &quot;World&quot; > Hello Stephan! </greeting> <greeting> Hello both of you! </greeting> </greetings>
  • 36. Example: A conversation (1) <xsl:template match= &quot;greeting&quot; > <h1> <xsl:choose> <xsl:when test= &quot;@author&quot; > <xsl:value-of select= &quot;@author&quot; /> <xsl:text> says: </xsl:text> <xsl:value-of select= &quot;.&quot; /> </xsl:when> <xsl:otherwise> <xsl:text> Somebody says: </xsl:text> <xsl:value-of select= &quot;.&quot; /> </xsl:otherwise> </xsl:choose> </h1> </xsl:template>
  • 38. Additional XSLT Features Wildcards (*, @*, //) Predicates (line[3], entry[position() mod 2 = 0]) <xsl:for-each> to process several nodes <xsl:template mode= “...“ > and <xsl:apply-templates mode= “...“ > Parameters, that may be passed with <xsl:apply-templates> or from PHP Variables (may not be changed!) Sorting and grouping
  • 39. Drawbacks of XSLT Needs to be installed (requires Sablotron) Designer needs to learn XSLT tags The XSLT-processor is a black-box: No possibilty to pause or influence the process once it has started It is not possible to include dynamic content into an XML file while processing.
  • 40. Transforming XML with PHP HTML Template for each XML element Attribute values are used as template variables The content of an element is a special template variable: {CONTENT} The XML document is parsed recursively using SAX-based parser
  • 41. Example <section title= &quot;XML Transformation&quot; > <para> XML may be transformed using PHP. </para> </section> XML Template for <section> Template for <para> <table border= &quot;0&quot; cellpadding= &quot;0&quot; cellspacing= &quot;2&quot; width= &quot;500&quot; > <tr><td><b> {TITLE} </b></td><tr> <tr><td> {CONTENT} </td></tr> </table> <font face= &quot; Arial &quot; size= &quot; 2 &quot; > {CONTENT} <br> </font>
  • 42. Including Dynamic Content By using callbacks, each PHP function may be used at any time. Simple Example: <time:current/> should insert current time. Solution: switch/case statement in element handler that executes PHP code instead of replacing the tag with its template. » code is hard to maintain Improvement: extensible parser, that invokes callbacks for specific namespaces.
  • 43. Randy - patXMLRenderer Open source (LGPL License) Uses the template class patTemplate Supports external entities („XML includes“) Unlimited amount of extensions. Tags will be passed to an extension according to namespaces The renderer only transforms static content and content returned by extensions Unlimited amount of designs Other features: caching, logging, etc...
  • 44. Architecture RENDERER HTML / XML /LaTEX /usw... Any extension XML TEMPLATES Time: Extension Dbc: Extension Ext. Entities
  • 45. Existing Extensions Repository on http://www.php-tools.de Documentation is generated automatically Examples: <time:...> date and time functions <dbc:...> database interface <var:...> access to variables <control:...> control structures <randy:...> XML-API for patXMLRenderer <file:...> file operations and many more...
  • 46. Similar Applications At least two more applications: PEAR::XML_Transformer http:// pear.php.net Only overloads tags with functions and methods. phpTagLib http://chocobot.d2g.com Only transforms XML to HTML.
  • 47. Comparison - - X Parameters Only with PHP code - X „ Intelligent“ Templates - All in one package X Ext. Repository - - X Administration X - X <?PHP ?> - - X External Entities - Yes, infinite Yes, infinite Recursion - X X Namespaces - Yes, objects and functions Yes, only object Dynamic Content (Callbacks) yes, plain HTML - yes, patTemplate Templates phpTagLib PEAR patXMLRenderer
  • 48. XSLT vs PHP Transformers Pro XSLT: Much faster than PHP transformers W3C Standard (works with any XSLT Processor) Pro PHP Transfomers: Easily extendable Easier to learn Script has complete control during the transformation process
  • 49. The End Thank you! More information: http://www.php-tools.net [email_address] Thanks to: Sebastian Mordziol, Gerd Schaufelberger, Stephan Eisler, Metrix Internet Design GmbH