SlideShare ist ein Scribd-Unternehmen logo
1 von 41
Extensible	
  Stylesheet	
  Language	
  

             Jussi	
  Pohjolainen	
  
  TAMK	
  University	
  of	
  Applied	
  Sciences	
  
XSL	
  
•  Extensible	
  Stylesheet	
  Language	
  (XSL)	
  
    –  family	
  of	
  transforma-on	
  languages	
  
•  To	
  format	
  and	
  /	
  or	
  transform	
  XML	
  –	
  
   documents	
  
•  XSL	
  Family	
  consists	
  of	
  three	
  languages	
  
    –  XSL	
  TransformaHons	
  (XSLT)	
  
    –  XSL	
  FormaIng	
  Objects	
  (XSL-­‐FO)	
  
    –  XML	
  Path	
  Language	
  (XPath)	
  
•  All	
  languages	
  are	
  W3C	
  recommendaHons	
  
RelaHonships	
  with	
  the	
  Languages	
  

  Extensible	
  Stylesheet	
  Language	
  


       XSL	
  TransformaHons	
                     XSL	
  FormaIng	
  Objects	
  

                                   uses	
  


                             XML	
  Path	
  Language	
  
Languages	
  
1.  XSL	
  Transforma0ons	
  (XSLT)	
  
   –  XML	
  language	
  for	
  transforming	
  XML	
  documents	
  
2.  XSL	
  Forma8ng	
  Objects	
  
   –  XML	
  language	
  for	
  specifying	
  visual	
  forma8ng	
  
3.  XML	
  Path	
  Language	
  
   –  A	
  non-­‐XML	
  language	
  used	
  by	
  XSLT,	
  addressing	
  the	
  
      parts	
  of	
  an	
  XML	
  document.	
  Also	
  available	
  for	
  use	
  
      in	
  non-­‐XSLT	
  contexts	
  
Main	
  Idea	
  of	
  XSLT	
  



             XSLT	
  
           Processor	
  




                            The	
  XSLT	
  Processor	
  can	
  be	
  client-­‐
                           side	
  (browser)	
  or	
  server-­‐side	
  (php,	
  
                                               java..)	
  
Without	
  XSLT	
  -­‐	
  link	
  
With	
  XSLT	
  -­‐	
  link	
  
                                                               Now	
  the	
  XML	
  
                                                               document	
  is	
  
                                                                linked	
  to	
  an	
  
                                                               external	
  xslt	
  
                                                                 document	
  




 Browser	
  is	
  used	
  
   as	
  an	
  XSLT	
  
processor.	
  (client-­‐
         side)	
  	
  
XSLT	
  
•  XSLT	
  is	
  an	
  transforma0on	
  language.	
  
•  With	
  XSLT	
  you	
  can	
  make	
  transformaHons:	
  
    –  XML	
  -­‐>	
  XML	
  in	
  General:	
  
         •  XML	
  -­‐>	
  XHTML	
  
         •  XML	
  -­‐>	
  SVG	
  
         •  ...	
  
    –  XML	
  -­‐>	
  HTML	
  
    –  XML	
  -­‐>	
  TEXT	
  
•  With	
  XSLT	
  you	
  can	
  transform	
  a	
  XML	
  document	
  to	
  
   other	
  text	
  format	
  (can	
  be	
  any).	
  
XSL-­‐FO	
  
•  XSL-­‐FO	
  is	
  a	
  W3C	
  Specified	
  XML	
  language	
  for	
  
   defining	
  visual	
  presentaHon.	
  
•  Unified	
  presentaHon	
  language	
  
•  No	
  semanHc	
  markup	
  
Example	
  of	
  an	
  XSL-­‐FO	
  Document	
  
<?xml version="1.0"?>!
<fo:root xmlns:fo="http://www.w3.org/1999/XSL/Format">!
  <fo:layout-master-set>!
    <fo:simple-page-master master-name="only">!
    <fo:region-body/>!
    </fo:simple-page-master>!
  </fo:layout-master-set>!
  <fo:page-sequence master-reference="only">!
    <fo:flow flow-name="xsl-region-body">!
      <fo:block font-size="20pt" font-family="serif" line-
   height="30pt">!
      Jussi Pohjolainen!
      </fo:block>!
      <fo:block color="red" font-size="30pt" font-family="serif">!
      jussi.pohjolainen(at)tamk.fi!
      </fo:block>!
    </fo:flow>!
  </fo:page-sequence>!
</fo:root>!
!
Transforming	
  XSL-­‐FO	
  -­‐	
  document	
  
•  Once	
  XSL-­‐FO	
  document	
  is	
  generated,	
  it	
  is	
  
   passed	
  to	
  a	
  FO	
  processor.	
  
•  FO	
  Processor	
  converts	
  the	
  document	
  into	
  
   something	
  that	
  is	
  readible,	
  printable	
  or	
  both.	
  
    –  Most	
  common	
  output	
  is	
  PDF,	
  PS,	
  RTF.	
  
•  FO	
  Processors?	
  
    –  XEP,	
  XSLForma_er,	
  XINC	
  and	
  FOP	
  
Example:	
  XSL-­‐FO	
  and	
  Processor	
  



                                                          XS	
  Processor	
  




   The	
  possible	
  output	
  formats	
  
depends	
  of	
  the	
  features	
  of	
  the	
  XS	
  
 processor.	
  For	
  example,	
  Apache	
  
     FOP	
  supports	
  only	
  PDF	
  
GeneraHng	
  FO	
  documents	
  
•  XSL-­‐FO	
  Documents	
  are	
  not	
  meant	
  to	
  be	
  
   implemented	
  by	
  the	
  programmer.	
  
•  XSL-­‐FO	
  Documents	
  are	
  generated	
  
•  Well	
  Who	
  /	
  What	
  generates	
  XSL	
  FO	
  
   Documents?	
  
    –  It's	
  result	
  of	
  an	
  XSLT	
  –	
  transformaHon	
  
Main	
  Idea	
  of	
  XSLT:	
  
 XML	
  -­‐>	
  XHTML	
  



             XSLT	
  
           Processor	
  




                            The	
  XSLT	
  Processor	
  can	
  be	
  client-­‐
                           side	
  (browser)	
  or	
  server-­‐side	
  (php,	
  
                                               java..)	
  
Main	
  Idea	
  of	
  XSLT:	
  
   XML	
  -­‐>	
  FO	
  



             XSLT	
  
           Processor	
  




                           Now	
  the	
  books.xml	
  is	
  transformed	
  
                                  into	
  XSL	
  FO	
  language...	
  
Example:	
  XSL-­‐FO	
  and	
  Processor	
  



                                                          XS	
  Processor	
  




And	
  if	
  you	
  have	
  an	
  fo-­‐document,	
  
 you	
  can	
  transform	
  it	
  to	
  pdf	
  (for	
  
                     example)	
  	
  
XSL-­‐FO	
  Process	
  in	
  Whole	
  

         XSLT	
  
       Processor	
  




                       XS	
  Processor	
  
Example	
  
•  ConverHng	
  XML	
  to	
  PDF	
  using	
  PHP	
  and	
  Apache	
  
   FOP	
  
•  Apache	
  FOP	
  
    –  h_p://xmlgraphics.apache.org/fop/	
  
•  Must	
  be	
  installed	
  in	
  your	
  server	
  
    –  It	
  is	
  NOT	
  installed	
  in	
  TAMK	
  Environment	
  
XSL-­‐FO	
  Process	
  in	
  Whole	
  

         PHP	
  




                          FOP	
  
PHP	
  Code	
  
<?php!
// load xslt-file!
$xslDoc = new DOMDocument();!
$xslDoc->load("books_to_fo.xslt");!
!
// load source xml-file!
$xmlDoc = new DOMDocument();!
$xmlDoc->load("books.xml");!
!
// Make transformation!
$proc = new XSLTProcessor();!
$proc->importStylesheet($xslDoc);!
$booksFo = $proc->transformToXML($xmlDoc);!
!
// Save the fo document to a file!
file_put_contents("books.fo", $booksFo);!
!
// Use fop to create the pdf!
shell_exec("fop books.fo books.pdf");!
?>!
XSLT	
  AND	
  XPATH	
  
RelaHonships	
  with	
  the	
  Languages	
  

  Extensible	
  Stylesheet	
  Language	
  


       XSL	
  TransformaHons	
                     XSL	
  FormaIng	
  Objects	
  

                                   uses	
  


                             XML	
  Path	
  Language	
  
XPath	
  
•  Before	
  learning	
  the	
  basics	
  of	
  XSLT,	
  let's	
  look	
  at	
  
   XPath	
  
    –  XPath	
  is	
  a	
  non-­‐XML	
  language	
  that	
  is	
  used	
  with	
  
       XSLT.	
  
    –  XPath	
  is	
  used	
  also	
  in	
  other	
  languages,	
  like	
  
       XPointer	
  
•  XPath	
  is	
  a	
  language	
  for	
  selec0ng	
  elements,	
  or	
  
     nodes,	
  from	
  an	
  XML	
  –	
  document	
  
	
  
SelecHng	
  Nodes?	
  
<?xml version="1.0"?>!
<A>!
   <B>!
      <C></C>!
  </B>!
</A>!
!
<!-- Let's select C -->!
/A/B/C!
!
            XPath	
  
SelecHng	
  Nodes	
  (W3schools)	
  
Expression	
     Descrip0on	
  
nodename	
       Selects	
  all	
  child	
  nodes	
  of	
  the	
  named	
  node	
  
/	
              Selects	
  from	
  the	
  root	
  node	
  
//	
             Selects	
  nodes	
  in	
  the	
  document	
  from	
  the	
  current	
  node	
  that	
  match	
  
                 the	
  selecHon	
  no	
  ma_er	
  where	
  they	
  are	
  	
  
.	
              Selects	
  the	
  current	
  node	
  
..	
             Selects	
  the	
  parent	
  of	
  the	
  current	
  node	
  
@	
              Selects	
  a_ributes	
  
Examples	
  (W3schools)	
  
Expression	
              Descrip0on	
  
/bookstore	
              Selects	
  the	
  root	
  element	
  bookstore	
  
bookstore/book	
          Selects	
  all	
  book	
  elements	
  that	
  are	
  children	
  of	
  bookstore	
  
//book	
                  Selects	
  all	
  book	
  elements	
  no	
  ma_er	
  where	
  they	
  are	
  in	
  the	
  
                          document	
  
bookstore//book	
   Selects	
  all	
  book	
  elements	
  that	
  are	
  descendant	
  of	
  the	
  bookstore	
  
                    element,	
  no	
  ma_er	
  where	
  they	
  are	
  under	
  the	
  bookstore	
  element	
  
//@lang	
                 Selects	
  all	
  a_ributes	
  that	
  are	
  named	
  lang	
  
More	
  Examples	
  
/bookstore/book[1] !
/bookstore/book[last()]!
/bookstore/book[last()-1]!
/bookstore/book[position()<3]!
//title[@lang]!
//title[@lang='eng']!
/bookstore/book[price>35.00]!
/bookstore/book[price>35.00]/title!
Example	
  of	
  an	
  XSLT-­‐transformaHon:	
  
                    XML-­‐file	
  
<?xml version="1.0" encoding="utf-8"?>!
<?xml-stylesheet type="text/xsl"
  href="transform.xslt"?>!
<book>!
  <title>Programming with Java</title>!
</book>!
Example	
  of	
  an	
  XSLT-­‐transformaHon:	
  
                     XSLT-­‐file	
  
<?xml version="1.0"?>!
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/
   XSL/Transform">!
!
    <xsl:output method="text" indent="yes" encoding="utf-8"/>!
    !
    <xsl:template match="/">!
        Title: <xsl:value-of select="/book/title"/>!
    </xsl:template>!
!
</xsl:stylesheet> !
Result:	
  
       Simple	
  text	
  –	
  file..	
  
Title: Programming with Java!
Making	
  the	
  TransformaHon	
  
1.     Implement	
  a	
  xml-­‐document	
  
2.     Implement	
  a	
  xslt-­‐document	
  
3.     Link	
  these	
  two	
  together	
  
4.     Output	
  the	
  result	
  with	
  some	
  processor	
  
      –  Browser,	
  XML-­‐editor,	
  PHP,	
  Java..	
  
XSLT-­‐transformaHon	
  with	
  PHP	
  5	
  
<?php!
// Load the transformation file!
$xslt = new domDocument();!
$xslt->load("transformation.xslt");!
!
// Load the source xml file!
$myXML = new DomDocument();!
$myXML->load("original.xml");!
!
// Add the transformation file to XSLTProcessor!
$proc = new XSLTProcessor();!
$proc->importStylesheet($xslt);!
!
// Transform the xml and output the result!
print $proc->transformToXml($myXML);!
?>!
Examples	
  of	
  XSLT	
  
<?xml version="1.0"?>!
<xsl:stylesheet version="1.0" xmlns:xsl="http://
  www.w3.org/1999/XSL/Transform">!
!
    <xsl:output method="text" indent="yes"
  encoding="utf-8"/>!
    !
    <xsl:template match="/">!
        Title: <xsl:value-of select="/book/title"/>!
    </xsl:template>!
!
</xsl:stylesheet> !
Examples	
  of	
  XSLT	
  
<?xml version="1.0"?>!
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/
   XSL/Transform">!
!
    <xsl:output method="html" indent="yes" encoding="utf-8"/>!
    !
    <xsl:template match="/">!
        <html><head><title></title></head>!
          <body>       !
             <h1>Title: <xsl:value-of select="/book/title"/></h1>!
          </body>!
        </html>!
    </xsl:template>!
</xsl:stylesheet> !
Result	
  of	
  Previous	
  XSLT	
  
<html><head><title></title></head>!
         <body>       !
            <h1>Title: Programming with Java</h1>!
         </body>!
       </html>	
  




 Is	
  this	
  valid	
  xhtml?	
  
Be_er	
  Version	
  
<?xml version="1.0" encoding="iso-8859-1"?>!
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/
   Transform">!
<xsl:output method="xml" indent="yes" encoding="utf-8"!
    doctype-system="http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"!
    doctype-public="-//W3C//DTD XHTML 1.0 Strict//EN" />!
 !
    <xsl:template match="/">!
        <html><head><title>Example</title></head>!
        <body>!
             <h1>Title: <xsl:value-of select="/book/title"/></h1>!
        </body>!
        </html>!
    </xsl:template>!
</xsl:stylesheet>!
<xsl:value-­‐of	
  select="XPath"/>	
  
•  With	
  <xsl:value-­‐of>	
  you	
  can	
  select	
  an	
  element	
  
   from	
  the	
  source	
  file	
  
•  The	
  value	
  of	
  the	
  select	
  a_ribute	
  is	
  XPath	
  
   expression	
  
    –  <xsl:value-­‐of	
  select="books/book/name"/>	
  
for-­‐each	
  
<?xml version="1.0" encoding="iso-8859-1"?>!
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/
   Transform">!
<xsl:output method="xml" indent="yes" encoding="utf-8"!
    doctype-system="http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"!
    doctype-public="-//W3C//DTD XHTML 1.0 Strict//EN" />!
 !
    <xsl:template match="/">!
        <html><head><title>Example</title></head>!
        <body>!
          <xsl:for-each select="/books/book">!
             <p><xsl:value-of select="title"/></p>!        Repeat	
  for	
  every	
  
          </xsl:for-each>!                                     book..	
  
        </body>!
        </html>!
    </xsl:template>!
</xsl:stylesheet>!
sort	
  
<?xml version="1.0" encoding="iso-8859-1"?>!
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/
   Transform">!
<xsl:output method="xml" indent="yes" encoding="utf-8"!
    doctype-system="http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"!
    doctype-public="-//W3C//DTD XHTML 1.0 Strict//EN" />!
 !
    <xsl:template match="/">!
        <html><head><title>Example</title></head>!         Repeat	
  for	
  every	
  
        <body>!                                                    book..	
  
          <xsl:for-each select="/books/book">!
             <xsl:sort select="price" order="ascending"/>!
             <p><xsl:value-of select="title"/></p>!
          </xsl:for-each>!
        </body>!                                          ..and	
  sort	
  them	
  by	
  
        </html>!                                                    price	
  
    </xsl:template>!
</xsl:stylesheet>!
Why	
  this	
  doesn't	
  work?	
  
<?xml version="1.0" encoding="iso-8859-1"?>!
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/
   Transform">!
<xsl:output method="xml" indent="yes" encoding="utf-8"!
    doctype-system="http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"!
    doctype-public="-//W3C//DTD XHTML 1.0 Strict//EN" />!
 !
    <xsl:template match="/">!
        <html><head><title>Example</title></head>!
        <body>!
          <img src="<xsl:value-of select="books/book/url"/>" />!
       </body>!
        </html>!
    </xsl:template>!
                                                          What's	
  wrong	
  with	
  
</xsl:stylesheet>!
                                                                      this	
  line?	
  
Using	
  a_ribute	
  
<?xml version="1.0" encoding="iso-8859-1"?>!
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/
   Transform">!
<xsl:output method="xml" indent="yes" encoding="utf-8"!
    doctype-system="http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"!
    doctype-public="-//W3C//DTD XHTML 1.0 Strict//EN" />!
 !
    <xsl:template match="/">!
        <html><head><title>Example</title></head>!
        <body>!
          <img>!
            <xsl:attribute name="src">!
                 <xsl:value-of select="books/book/url"/>!
            </xsl:attribute>!
          </img>          !
          </body>!
        </html>!
    </xsl:template>!
</xsl:stylesheet>!

Weitere ähnliche Inhalte

Was ist angesagt? (20)

The Lumber Mill - XSLT For Your Templates
The Lumber Mill  - XSLT For Your TemplatesThe Lumber Mill  - XSLT For Your Templates
The Lumber Mill - XSLT For Your Templates
 
DOM and SAX
DOM and SAXDOM and SAX
DOM and SAX
 
Xmll
XmllXmll
Xmll
 
SMWCon Fall 2015 FForms
SMWCon Fall 2015 FFormsSMWCon Fall 2015 FForms
SMWCon Fall 2015 FForms
 
XML and XPath details
XML and XPath detailsXML and XPath details
XML and XPath details
 
From Ontology to Wiki: Automating Generation of Semantic Wiki Interfaces from...
From Ontology to Wiki: Automating Generation of Semantic Wiki Interfaces from...From Ontology to Wiki: Automating Generation of Semantic Wiki Interfaces from...
From Ontology to Wiki: Automating Generation of Semantic Wiki Interfaces from...
 
Xpath presentation
Xpath presentationXpath presentation
Xpath presentation
 
Hotsos 2013 - Creating Structure in Unstructured Data
Hotsos 2013 - Creating Structure in Unstructured DataHotsos 2013 - Creating Structure in Unstructured Data
Hotsos 2013 - Creating Structure in Unstructured Data
 
BGOUG 2012 - XML Index Strategies
BGOUG 2012 - XML Index StrategiesBGOUG 2012 - XML Index Strategies
BGOUG 2012 - XML Index Strategies
 
Xml dom
Xml domXml dom
Xml dom
 
Xml
XmlXml
Xml
 
XML Bible
XML BibleXML Bible
XML Bible
 
XML Document Object Model (DOM)
XML Document Object Model (DOM)XML Document Object Model (DOM)
XML Document Object Model (DOM)
 
Unit 4 - HTTP and the Web Services - IT
Unit 4 - HTTP and the Web Services - ITUnit 4 - HTTP and the Web Services - IT
Unit 4 - HTTP and the Web Services - IT
 
Jaxp Xmltutorial 11 200108
Jaxp Xmltutorial 11 200108Jaxp Xmltutorial 11 200108
Jaxp Xmltutorial 11 200108
 
Xml data transformation
Xml data transformationXml data transformation
Xml data transformation
 
Understanding XML DOM
Understanding XML DOMUnderstanding XML DOM
Understanding XML DOM
 
XPATH
XPATHXPATH
XPATH
 
XML.ppt
XML.pptXML.ppt
XML.ppt
 
XPath Introduction
XPath IntroductionXPath Introduction
XPath Introduction
 

Ähnlich wie Extensible Stylesheet Language

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 ...BookNet Canada
 
Extensible Stylesheet Language
Extensible Stylesheet LanguageExtensible Stylesheet Language
Extensible Stylesheet LanguageJussi Pohjolainen
 
Introduction to XSLT
Introduction to XSLTIntroduction to XSLT
Introduction to XSLTMahmoud Allam
 
Overview of XSL, XPath and XSL-FO
Overview of XSL, XPath and XSL-FOOverview of XSL, XPath and XSL-FO
Overview of XSL, XPath and XSL-FOSuite Solutions
 
Extensible stylesheet language (Transformation) or XSLT
Extensible stylesheet language (Transformation) or XSLTExtensible stylesheet language (Transformation) or XSLT
Extensible stylesheet language (Transformation) or XSLTAshikur Rahman
 
Introduction of xml and xslt
Introduction of xml and xsltIntroduction of xml and xslt
Introduction of xml and xsltTUSHAR VARSHNEY
 
Xml transformation language
Xml transformation languageXml transformation language
Xml transformation languagereshmavasudev
 
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
 
Integrative Programming and Technology Chapter 4- Dr. J. VijiPriya
Integrative Programming and Technology Chapter 4- Dr. J. VijiPriyaIntegrative Programming and Technology Chapter 4- Dr. J. VijiPriya
Integrative Programming and Technology Chapter 4- Dr. J. VijiPriyaVijiPriya Jeyamani
 
eXtensible Markup Language
eXtensible Markup LanguageeXtensible Markup Language
eXtensible Markup LanguageAditya Raj
 
You Want to Go XML-First: Now What? Building an In-House XML-First Workflow -...
You Want to Go XML-First: Now What? Building an In-House XML-First Workflow -...You Want to Go XML-First: Now What? Building an In-House XML-First Workflow -...
You Want to Go XML-First: Now What? Building an In-House XML-First Workflow -...BookNet Canada
 

Ähnlich wie Extensible Stylesheet Language (20)

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 ...
 
Extensible Stylesheet Language
Extensible Stylesheet LanguageExtensible Stylesheet Language
Extensible Stylesheet Language
 
Introduction to XSLT
Introduction to XSLTIntroduction to XSLT
Introduction to XSLT
 
Overview of XSL, XPath and XSL-FO
Overview of XSL, XPath and XSL-FOOverview of XSL, XPath and XSL-FO
Overview of XSL, XPath and XSL-FO
 
Xslt
XsltXslt
Xslt
 
Xslt
XsltXslt
Xslt
 
Extensible stylesheet language (Transformation) or XSLT
Extensible stylesheet language (Transformation) or XSLTExtensible stylesheet language (Transformation) or XSLT
Extensible stylesheet language (Transformation) or XSLT
 
XSLT
XSLTXSLT
XSLT
 
XML/XSLT
XML/XSLTXML/XSLT
XML/XSLT
 
Introduction of xml and xslt
Introduction of xml and xsltIntroduction of xml and xslt
Introduction of xml and xslt
 
26xslt
26xslt26xslt
26xslt
 
Xml transformation language
Xml transformation languageXml transformation language
Xml transformation language
 
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...
 
Integrative Programming and Technology Chapter 4- Dr. J. VijiPriya
Integrative Programming and Technology Chapter 4- Dr. J. VijiPriyaIntegrative Programming and Technology Chapter 4- Dr. J. VijiPriya
Integrative Programming and Technology Chapter 4- Dr. J. VijiPriya
 
CTDA Workshop on XSL
CTDA Workshop on XSLCTDA Workshop on XSL
CTDA Workshop on XSL
 
eXtensible Markup Language
eXtensible Markup LanguageeXtensible Markup Language
eXtensible Markup Language
 
XML XSLT
XML XSLTXML XSLT
XML XSLT
 
You Want to Go XML-First: Now What? Building an In-House XML-First Workflow -...
You Want to Go XML-First: Now What? Building an In-House XML-First Workflow -...You Want to Go XML-First: Now What? Building an In-House XML-First Workflow -...
You Want to Go XML-First: Now What? Building an In-House XML-First Workflow -...
 
03 x files
03 x files03 x files
03 x files
 
XSL - XML STYLE SHEET
XSL - XML STYLE SHEETXSL - XML STYLE SHEET
XSL - XML STYLE SHEET
 

Mehr von Jussi Pohjolainen

libGDX: Screens, Fonts and Preferences
libGDX: Screens, Fonts and PreferenceslibGDX: Screens, Fonts and Preferences
libGDX: Screens, Fonts and PreferencesJussi Pohjolainen
 
libGDX: User Input and Frame by Frame Animation
libGDX: User Input and Frame by Frame AnimationlibGDX: User Input and Frame by Frame Animation
libGDX: User Input and Frame by Frame AnimationJussi Pohjolainen
 
Intro to Building Android Games using libGDX
Intro to Building Android Games using libGDXIntro to Building Android Games using libGDX
Intro to Building Android Games using libGDXJussi Pohjolainen
 
Advanced JavaScript Development
Advanced JavaScript DevelopmentAdvanced JavaScript Development
Advanced JavaScript DevelopmentJussi Pohjolainen
 
libGDX: Simple Frame Animation
libGDX: Simple Frame AnimationlibGDX: Simple Frame Animation
libGDX: Simple Frame AnimationJussi Pohjolainen
 
libGDX: Simple Frame Animation
libGDX: Simple Frame AnimationlibGDX: Simple Frame Animation
libGDX: Simple Frame AnimationJussi Pohjolainen
 
Implementing a Simple Game using libGDX
Implementing a Simple Game using libGDXImplementing a Simple Game using libGDX
Implementing a Simple Game using libGDXJussi Pohjolainen
 
Building Android games using LibGDX
Building Android games using LibGDXBuilding Android games using LibGDX
Building Android games using LibGDXJussi Pohjolainen
 
Creating Asha Games: Game Pausing, Orientation, Sensors and Gestures
Creating Asha Games: Game Pausing, Orientation, Sensors and GesturesCreating Asha Games: Game Pausing, Orientation, Sensors and Gestures
Creating Asha Games: Game Pausing, Orientation, Sensors and GesturesJussi Pohjolainen
 
Creating Games for Asha - platform
Creating Games for Asha - platformCreating Games for Asha - platform
Creating Games for Asha - platformJussi Pohjolainen
 

Mehr von Jussi Pohjolainen (20)

Moved to Speakerdeck
Moved to SpeakerdeckMoved to Speakerdeck
Moved to Speakerdeck
 
Java Web Services
Java Web ServicesJava Web Services
Java Web Services
 
Box2D and libGDX
Box2D and libGDXBox2D and libGDX
Box2D and libGDX
 
libGDX: Screens, Fonts and Preferences
libGDX: Screens, Fonts and PreferenceslibGDX: Screens, Fonts and Preferences
libGDX: Screens, Fonts and Preferences
 
libGDX: Tiled Maps
libGDX: Tiled MapslibGDX: Tiled Maps
libGDX: Tiled Maps
 
libGDX: User Input and Frame by Frame Animation
libGDX: User Input and Frame by Frame AnimationlibGDX: User Input and Frame by Frame Animation
libGDX: User Input and Frame by Frame Animation
 
Intro to Building Android Games using libGDX
Intro to Building Android Games using libGDXIntro to Building Android Games using libGDX
Intro to Building Android Games using libGDX
 
Advanced JavaScript Development
Advanced JavaScript DevelopmentAdvanced JavaScript Development
Advanced JavaScript Development
 
Introduction to JavaScript
Introduction to JavaScriptIntroduction to JavaScript
Introduction to JavaScript
 
Introduction to AngularJS
Introduction to AngularJSIntroduction to AngularJS
Introduction to AngularJS
 
libGDX: Scene2D
libGDX: Scene2DlibGDX: Scene2D
libGDX: Scene2D
 
libGDX: Simple Frame Animation
libGDX: Simple Frame AnimationlibGDX: Simple Frame Animation
libGDX: Simple Frame Animation
 
libGDX: Simple Frame Animation
libGDX: Simple Frame AnimationlibGDX: Simple Frame Animation
libGDX: Simple Frame Animation
 
libGDX: User Input
libGDX: User InputlibGDX: User Input
libGDX: User Input
 
Implementing a Simple Game using libGDX
Implementing a Simple Game using libGDXImplementing a Simple Game using libGDX
Implementing a Simple Game using libGDX
 
Building Android games using LibGDX
Building Android games using LibGDXBuilding Android games using LibGDX
Building Android games using LibGDX
 
Android Threading
Android ThreadingAndroid Threading
Android Threading
 
Creating Asha Games: Game Pausing, Orientation, Sensors and Gestures
Creating Asha Games: Game Pausing, Orientation, Sensors and GesturesCreating Asha Games: Game Pausing, Orientation, Sensors and Gestures
Creating Asha Games: Game Pausing, Orientation, Sensors and Gestures
 
Creating Games for Asha - platform
Creating Games for Asha - platformCreating Games for Asha - platform
Creating Games for Asha - platform
 
Intro to Asha UI
Intro to Asha UIIntro to Asha UI
Intro to Asha UI
 

Kürzlich hochgeladen

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 2024The Digital Insurer
 
HTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation StrategiesHTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation StrategiesBoston Institute of Analytics
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024Rafal Los
 
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...Martijn de Jong
 
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 Scriptwesley chun
 
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 productivityPrincipled Technologies
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)Gabriella Davis
 
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...apidays
 
Manulife - Insurer Innovation Award 2024
Manulife - Insurer Innovation Award 2024Manulife - Insurer Innovation Award 2024
Manulife - Insurer Innovation Award 2024The Digital Insurer
 
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 educationjfdjdjcjdnsjd
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘RTylerCroy
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...apidays
 
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...Neo4j
 
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 RobisonAnna Loughnan Colquhoun
 
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 WorkerThousandEyes
 
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 Takeoffsammart93
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024The Digital Insurer
 
Top 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live StreamsTop 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live StreamsRoshan Dwivedi
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?Igalia
 

Kürzlich hochgeladen (20)

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
 
HTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation StrategiesHTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation Strategies
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
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...
 
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
 
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
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
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...
 
Manulife - Insurer Innovation Award 2024
Manulife - Insurer Innovation Award 2024Manulife - Insurer Innovation Award 2024
Manulife - Insurer Innovation Award 2024
 
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
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
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...
 
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
 
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
 
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
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024
 
Top 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live StreamsTop 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live Streams
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?
 

Extensible Stylesheet Language

  • 1. Extensible  Stylesheet  Language   Jussi  Pohjolainen   TAMK  University  of  Applied  Sciences  
  • 2. XSL   •  Extensible  Stylesheet  Language  (XSL)   –  family  of  transforma-on  languages   •  To  format  and  /  or  transform  XML  –   documents   •  XSL  Family  consists  of  three  languages   –  XSL  TransformaHons  (XSLT)   –  XSL  FormaIng  Objects  (XSL-­‐FO)   –  XML  Path  Language  (XPath)   •  All  languages  are  W3C  recommendaHons  
  • 3. RelaHonships  with  the  Languages   Extensible  Stylesheet  Language   XSL  TransformaHons   XSL  FormaIng  Objects   uses   XML  Path  Language  
  • 4. Languages   1.  XSL  Transforma0ons  (XSLT)   –  XML  language  for  transforming  XML  documents   2.  XSL  Forma8ng  Objects   –  XML  language  for  specifying  visual  forma8ng   3.  XML  Path  Language   –  A  non-­‐XML  language  used  by  XSLT,  addressing  the   parts  of  an  XML  document.  Also  available  for  use   in  non-­‐XSLT  contexts  
  • 5. Main  Idea  of  XSLT   XSLT   Processor   The  XSLT  Processor  can  be  client-­‐ side  (browser)  or  server-­‐side  (php,   java..)  
  • 7. With  XSLT  -­‐  link   Now  the  XML   document  is   linked  to  an   external  xslt   document   Browser  is  used   as  an  XSLT   processor.  (client-­‐ side)    
  • 8. XSLT   •  XSLT  is  an  transforma0on  language.   •  With  XSLT  you  can  make  transformaHons:   –  XML  -­‐>  XML  in  General:   •  XML  -­‐>  XHTML   •  XML  -­‐>  SVG   •  ...   –  XML  -­‐>  HTML   –  XML  -­‐>  TEXT   •  With  XSLT  you  can  transform  a  XML  document  to   other  text  format  (can  be  any).  
  • 9. XSL-­‐FO   •  XSL-­‐FO  is  a  W3C  Specified  XML  language  for   defining  visual  presentaHon.   •  Unified  presentaHon  language   •  No  semanHc  markup  
  • 10. Example  of  an  XSL-­‐FO  Document   <?xml version="1.0"?>! <fo:root xmlns:fo="http://www.w3.org/1999/XSL/Format">! <fo:layout-master-set>! <fo:simple-page-master master-name="only">! <fo:region-body/>! </fo:simple-page-master>! </fo:layout-master-set>! <fo:page-sequence master-reference="only">! <fo:flow flow-name="xsl-region-body">! <fo:block font-size="20pt" font-family="serif" line- height="30pt">! Jussi Pohjolainen! </fo:block>! <fo:block color="red" font-size="30pt" font-family="serif">! jussi.pohjolainen(at)tamk.fi! </fo:block>! </fo:flow>! </fo:page-sequence>! </fo:root>! !
  • 11. Transforming  XSL-­‐FO  -­‐  document   •  Once  XSL-­‐FO  document  is  generated,  it  is   passed  to  a  FO  processor.   •  FO  Processor  converts  the  document  into   something  that  is  readible,  printable  or  both.   –  Most  common  output  is  PDF,  PS,  RTF.   •  FO  Processors?   –  XEP,  XSLForma_er,  XINC  and  FOP  
  • 12. Example:  XSL-­‐FO  and  Processor   XS  Processor   The  possible  output  formats   depends  of  the  features  of  the  XS   processor.  For  example,  Apache   FOP  supports  only  PDF  
  • 13. GeneraHng  FO  documents   •  XSL-­‐FO  Documents  are  not  meant  to  be   implemented  by  the  programmer.   •  XSL-­‐FO  Documents  are  generated   •  Well  Who  /  What  generates  XSL  FO   Documents?   –  It's  result  of  an  XSLT  –  transformaHon  
  • 14. Main  Idea  of  XSLT:   XML  -­‐>  XHTML   XSLT   Processor   The  XSLT  Processor  can  be  client-­‐ side  (browser)  or  server-­‐side  (php,   java..)  
  • 15. Main  Idea  of  XSLT:   XML  -­‐>  FO   XSLT   Processor   Now  the  books.xml  is  transformed   into  XSL  FO  language...  
  • 16. Example:  XSL-­‐FO  and  Processor   XS  Processor   And  if  you  have  an  fo-­‐document,   you  can  transform  it  to  pdf  (for   example)    
  • 17. XSL-­‐FO  Process  in  Whole   XSLT   Processor   XS  Processor  
  • 18. Example   •  ConverHng  XML  to  PDF  using  PHP  and  Apache   FOP   •  Apache  FOP   –  h_p://xmlgraphics.apache.org/fop/   •  Must  be  installed  in  your  server   –  It  is  NOT  installed  in  TAMK  Environment  
  • 19. XSL-­‐FO  Process  in  Whole   PHP   FOP  
  • 20. PHP  Code   <?php! // load xslt-file! $xslDoc = new DOMDocument();! $xslDoc->load("books_to_fo.xslt");! ! // load source xml-file! $xmlDoc = new DOMDocument();! $xmlDoc->load("books.xml");! ! // Make transformation! $proc = new XSLTProcessor();! $proc->importStylesheet($xslDoc);! $booksFo = $proc->transformToXML($xmlDoc);! ! // Save the fo document to a file! file_put_contents("books.fo", $booksFo);! ! // Use fop to create the pdf! shell_exec("fop books.fo books.pdf");! ?>!
  • 22. RelaHonships  with  the  Languages   Extensible  Stylesheet  Language   XSL  TransformaHons   XSL  FormaIng  Objects   uses   XML  Path  Language  
  • 23. XPath   •  Before  learning  the  basics  of  XSLT,  let's  look  at   XPath   –  XPath  is  a  non-­‐XML  language  that  is  used  with   XSLT.   –  XPath  is  used  also  in  other  languages,  like   XPointer   •  XPath  is  a  language  for  selec0ng  elements,  or   nodes,  from  an  XML  –  document    
  • 24. SelecHng  Nodes?   <?xml version="1.0"?>! <A>! <B>! <C></C>! </B>! </A>! ! <!-- Let's select C -->! /A/B/C! ! XPath  
  • 25. SelecHng  Nodes  (W3schools)   Expression   Descrip0on   nodename   Selects  all  child  nodes  of  the  named  node   /   Selects  from  the  root  node   //   Selects  nodes  in  the  document  from  the  current  node  that  match   the  selecHon  no  ma_er  where  they  are     .   Selects  the  current  node   ..   Selects  the  parent  of  the  current  node   @   Selects  a_ributes  
  • 26. Examples  (W3schools)   Expression   Descrip0on   /bookstore   Selects  the  root  element  bookstore   bookstore/book   Selects  all  book  elements  that  are  children  of  bookstore   //book   Selects  all  book  elements  no  ma_er  where  they  are  in  the   document   bookstore//book   Selects  all  book  elements  that  are  descendant  of  the  bookstore   element,  no  ma_er  where  they  are  under  the  bookstore  element   //@lang   Selects  all  a_ributes  that  are  named  lang  
  • 27. More  Examples   /bookstore/book[1] ! /bookstore/book[last()]! /bookstore/book[last()-1]! /bookstore/book[position()<3]! //title[@lang]! //title[@lang='eng']! /bookstore/book[price>35.00]! /bookstore/book[price>35.00]/title!
  • 28. Example  of  an  XSLT-­‐transformaHon:   XML-­‐file   <?xml version="1.0" encoding="utf-8"?>! <?xml-stylesheet type="text/xsl" href="transform.xslt"?>! <book>! <title>Programming with Java</title>! </book>!
  • 29. Example  of  an  XSLT-­‐transformaHon:   XSLT-­‐file   <?xml version="1.0"?>! <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/ XSL/Transform">! ! <xsl:output method="text" indent="yes" encoding="utf-8"/>! ! <xsl:template match="/">! Title: <xsl:value-of select="/book/title"/>! </xsl:template>! ! </xsl:stylesheet> !
  • 30. Result:   Simple  text  –  file..   Title: Programming with Java!
  • 31. Making  the  TransformaHon   1.  Implement  a  xml-­‐document   2.  Implement  a  xslt-­‐document   3.  Link  these  two  together   4.  Output  the  result  with  some  processor   –  Browser,  XML-­‐editor,  PHP,  Java..  
  • 32. XSLT-­‐transformaHon  with  PHP  5   <?php! // Load the transformation file! $xslt = new domDocument();! $xslt->load("transformation.xslt");! ! // Load the source xml file! $myXML = new DomDocument();! $myXML->load("original.xml");! ! // Add the transformation file to XSLTProcessor! $proc = new XSLTProcessor();! $proc->importStylesheet($xslt);! ! // Transform the xml and output the result! print $proc->transformToXml($myXML);! ?>!
  • 33. Examples  of  XSLT   <?xml version="1.0"?>! <xsl:stylesheet version="1.0" xmlns:xsl="http:// www.w3.org/1999/XSL/Transform">! ! <xsl:output method="text" indent="yes" encoding="utf-8"/>! ! <xsl:template match="/">! Title: <xsl:value-of select="/book/title"/>! </xsl:template>! ! </xsl:stylesheet> !
  • 34. Examples  of  XSLT   <?xml version="1.0"?>! <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/ XSL/Transform">! ! <xsl:output method="html" indent="yes" encoding="utf-8"/>! ! <xsl:template match="/">! <html><head><title></title></head>! <body> ! <h1>Title: <xsl:value-of select="/book/title"/></h1>! </body>! </html>! </xsl:template>! </xsl:stylesheet> !
  • 35. Result  of  Previous  XSLT   <html><head><title></title></head>! <body> ! <h1>Title: Programming with Java</h1>! </body>! </html>   Is  this  valid  xhtml?  
  • 36. Be_er  Version   <?xml version="1.0" encoding="iso-8859-1"?>! <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/ Transform">! <xsl:output method="xml" indent="yes" encoding="utf-8"! doctype-system="http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"! doctype-public="-//W3C//DTD XHTML 1.0 Strict//EN" />! ! <xsl:template match="/">! <html><head><title>Example</title></head>! <body>! <h1>Title: <xsl:value-of select="/book/title"/></h1>! </body>! </html>! </xsl:template>! </xsl:stylesheet>!
  • 37. <xsl:value-­‐of  select="XPath"/>   •  With  <xsl:value-­‐of>  you  can  select  an  element   from  the  source  file   •  The  value  of  the  select  a_ribute  is  XPath   expression   –  <xsl:value-­‐of  select="books/book/name"/>  
  • 38. for-­‐each   <?xml version="1.0" encoding="iso-8859-1"?>! <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/ Transform">! <xsl:output method="xml" indent="yes" encoding="utf-8"! doctype-system="http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"! doctype-public="-//W3C//DTD XHTML 1.0 Strict//EN" />! ! <xsl:template match="/">! <html><head><title>Example</title></head>! <body>! <xsl:for-each select="/books/book">! <p><xsl:value-of select="title"/></p>! Repeat  for  every   </xsl:for-each>! book..   </body>! </html>! </xsl:template>! </xsl:stylesheet>!
  • 39. sort   <?xml version="1.0" encoding="iso-8859-1"?>! <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/ Transform">! <xsl:output method="xml" indent="yes" encoding="utf-8"! doctype-system="http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"! doctype-public="-//W3C//DTD XHTML 1.0 Strict//EN" />! ! <xsl:template match="/">! <html><head><title>Example</title></head>! Repeat  for  every   <body>! book..   <xsl:for-each select="/books/book">! <xsl:sort select="price" order="ascending"/>! <p><xsl:value-of select="title"/></p>! </xsl:for-each>! </body>! ..and  sort  them  by   </html>! price   </xsl:template>! </xsl:stylesheet>!
  • 40. Why  this  doesn't  work?   <?xml version="1.0" encoding="iso-8859-1"?>! <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/ Transform">! <xsl:output method="xml" indent="yes" encoding="utf-8"! doctype-system="http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"! doctype-public="-//W3C//DTD XHTML 1.0 Strict//EN" />! ! <xsl:template match="/">! <html><head><title>Example</title></head>! <body>! <img src="<xsl:value-of select="books/book/url"/>" />! </body>! </html>! </xsl:template>! What's  wrong  with   </xsl:stylesheet>! this  line?  
  • 41. Using  a_ribute   <?xml version="1.0" encoding="iso-8859-1"?>! <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/ Transform">! <xsl:output method="xml" indent="yes" encoding="utf-8"! doctype-system="http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"! doctype-public="-//W3C//DTD XHTML 1.0 Strict//EN" />! ! <xsl:template match="/">! <html><head><title>Example</title></head>! <body>! <img>! <xsl:attribute name="src">! <xsl:value-of select="books/book/url"/>! </xsl:attribute>! </img> ! </body>! </html>! </xsl:template>! </xsl:stylesheet>!