SlideShare a Scribd company logo
1 of 11
Media IT :: Dr Serge Linckels :: http://www.linckels.lu/ :: serge@linckels.lu ::
Faculty of Science, Technology and Communication (FSTC)
Bachelor en informatique (professionnel)
-- Media IT -–
¯_(ツ)_/¯
Unit 9
XML
Transformation
Media IT :: Dr Serge Linckels :: http://www.linckels.lu/ :: serge@linckels.lu ::
9. XML Transformation
2
9.1 XSLT overview
9.2 XSLT transformation principle
9.3 XML + XSLT References
9.4 Exercise
Media IT :: Dr Serge Linckels :: http://www.linckels.lu/ :: serge@linckels.lu ::
9. XML Transformation
9.1 XSLT overview
3
Picture created by Harald Sack
Media IT :: Dr Serge Linckels :: http://www.linckels.lu/ :: serge@linckels.lu ::
9. XML Transformation
9.1 XSLT overview
4
XSLT overview
Extensible Stylesheet Language Transformations (XSLT) is an XML-based language used to
specify rules by which one XML document is transformed into another (XML) document
The resulting document may be XML syntax or another format, such as HTML or plain text
Examples of applications of XSLT:
- convert data between different XML schemas
- convert XML data into HTML or XHTML documents for web pages (e.g., with CSS)
- creating a dynamic web page
- convert into an intermediate XML format that can be converted to PDF documents
Such a transformation is based on the following languages:
- XSLT: specifies the transformation rules
- XSL-FO: describes how to transform layout
- XPath: access to specific parts of an XML document
Media IT :: Dr Serge Linckels :: http://www.linckels.lu/ :: serge@linckels.lu ::
9. XML Transformation
9.2 XSLT transformation principle
5
XML
documents
DTD/XML-S
XSL
document 1
XSL
document 2
PDF document
HTML
WML
XSLT
processor
Media IT :: Dr Serge Linckels :: http://www.linckels.lu/ :: serge@linckels.lu ::
9. XML Transformation
9.2 XSLT transformation principle
6
XSL stylesheet
tree representation of XML
document
XSL works on the abstract tree representation of the XML document
A set of transformation rules are required in form a an XSLT document, e.g., template (XSL
stylesheet)
output
document
+
The structure tree is browsed and for each node the appropriate template from the XSL
stylesheet is applied
Media IT :: Dr Serge Linckels :: http://www.linckels.lu/ :: serge@linckels.lu ::
9. XML Transformation
9.2 XSLT transformation principle
7
<data>
<row num="1">toto 1</row>
<row num="2">toto 2</row>
<row num="3">toto 3</row>
</data>
XML document
<?xml version="1.0" encoding="ISO-8859-1"?>
<html xsl:version="1.0"
xmlns:xsl="http://www.w3.org/
1999/XSL/Transform">
<body>
<h1>Demo</h1>
<xsl:for-each select="row">
<br/>Row:
<xsl:value-of select="@num"/>
- Data:
<xsl:value-of select="."/>
</xsl:for-each>
</body>
</html>
XSL stylesheet
<html><body>
<h1>Demo</h1>
<br/>Row: 1 - Data: toto 1
<br/>Row: 2 - Data: toto 2
<br/>Row: 3 - Data: toto 3
</body></html>
HTML document
XSLT
processor
Media IT :: Dr Serge Linckels :: http://www.linckels.lu/ :: serge@linckels.lu ::
9. XML Transformation
9.2 XSLT transformation principle
8
Perform XSL transformation using a stylesheet
<?xml version="1.0" encoding="ISO-8859-1"?>
<?xml-stylesheet type="text/xsl" href="stylesheet.xsl" ?>
<data>
<row num="1">toto 1</row>
<row num="2">toto 2</row>
<row num="3">toto 3</row>
</data>
Media IT :: Dr Serge Linckels :: http://www.linckels.lu/ :: serge@linckels.lu ::
9. XML Transformation
9.2 XSLT transformation principle
9
import java.io.FileReader;
import javax.xml.transform.Result;
import javax.xml.transform.Source;
import javax.xml.transform.Transformer;
import javax.xml.transform.TransformerFactory;
import javax.xml.transform.stream.StreamResult;
import javax.xml.transform.stream.StreamSource;
public class TestTransformation {
public static void main(String[] args)
throws Exception {
Source sourceXSL = new StreamSource(new FileReader("stylesheet.xsl"));
Source sourceXML = new StreamSource(new FileReader("data.xml"));
TransformerFactory trFac = TransformerFactory.newInstance();
Transformer tf;
Result resultOnScreen = new StreamResult(System.out);
tf = trFac.newTransformer(sourceXSL);
tf.transform(sourceXML, resultOnScreen);
}
}
Perform XSL transformation using a Java programme
Media IT :: Dr Serge Linckels :: http://www.linckels.lu/ :: serge@linckels.lu ::
9. XML Transformation
9.3 XML + XSLT References
10
XML in a Nutshell
Elliotte R. Harold, W. Scott Means, W. Scott Means
E-Librarian Service
User-Friendly Semantic Search in Digital Libraries
Serge Linckels, Christoph Meinel
Media IT :: Dr Serge Linckels :: http://www.linckels.lu/ :: serge@linckels.lu ::
9. XML Transformation
9.4 Exercise

More Related Content

Similar to Media IT - XML and XML Transformation (XSLT)

eXtensible Markup Language
eXtensible Markup LanguageeXtensible Markup Language
eXtensible Markup Language
Aditya Raj
 

Similar to Media IT - XML and XML Transformation (XSLT) (20)

Xml part5
Xml part5Xml part5
Xml part5
 
Xslt
XsltXslt
Xslt
 
Xslt
XsltXslt
Xslt
 
Introduction of xml and xslt
Introduction of xml and xsltIntroduction of xml and xslt
Introduction of xml and xslt
 
Xslt
XsltXslt
Xslt
 
eXtensible Markup Language (XML)
eXtensible Markup Language (XML)eXtensible Markup Language (XML)
eXtensible Markup Language (XML)
 
XML Prague 2005 EXSLT
XML Prague 2005 EXSLTXML Prague 2005 EXSLT
XML Prague 2005 EXSLT
 
Xsl xslt
Xsl  xsltXsl  xslt
Xsl xslt
 
Working With XML in IDS Applications
Working With XML in IDS ApplicationsWorking With XML in IDS Applications
Working With XML in IDS Applications
 
Session 4
Session 4Session 4
Session 4
 
Full xml
Full xmlFull xml
Full xml
 
Unit 10: XML and Beyond (Sematic Web, Web Services, ...)
Unit 10: XML and Beyond (Sematic Web, Web Services, ...)Unit 10: XML and Beyond (Sematic Web, Web Services, ...)
Unit 10: XML and Beyond (Sematic Web, Web Services, ...)
 
Why XML is important for everyone, especially technical communicators
Why XML is important for everyone, especially technical communicatorsWhy XML is important for everyone, especially technical communicators
Why XML is important for everyone, especially technical communicators
 
XML/XSLT
XML/XSLTXML/XSLT
XML/XSLT
 
2001: Bridging the Gap between RSS and Java Old School Style
2001: Bridging the Gap between RSS and Java Old School Style2001: Bridging the Gap between RSS and Java Old School Style
2001: Bridging the Gap between RSS and Java Old School Style
 
Making WorkFlows XML Report Output Work For You
Making WorkFlows XML Report Output Work For YouMaking WorkFlows XML Report Output Work For You
Making WorkFlows XML Report Output Work For You
 
Service Oriented Architecture - Unit II
Service Oriented Architecture - Unit IIService Oriented Architecture - Unit II
Service Oriented Architecture - Unit II
 
eXtensible Markup Language
eXtensible Markup LanguageeXtensible Markup Language
eXtensible Markup Language
 
The need of Interoperability in Office and GIS formats
The need of Interoperability in Office and GIS formatsThe need of Interoperability in Office and GIS formats
The need of Interoperability in Office and GIS formats
 
Introduction to XSLT
Introduction to XSLTIntroduction to XSLT
Introduction to XSLT
 

More from Serge Linckels (12)

Media IT - author rights
Media IT - author rightsMedia IT - author rights
Media IT - author rights
 
Media IT - Images
Media IT - ImagesMedia IT - Images
Media IT - Images
 
Media IT - Entropy
Media IT - EntropyMedia IT - Entropy
Media IT - Entropy
 
Media IT - Natural Language Processing
Media IT - Natural Language ProcessingMedia IT - Natural Language Processing
Media IT - Natural Language Processing
 
Media IT - Coding
Media IT - CodingMedia IT - Coding
Media IT - Coding
 
Semantic Web - Search engines
Semantic Web - Search enginesSemantic Web - Search engines
Semantic Web - Search engines
 
Semantic Web - OWL
Semantic Web - OWLSemantic Web - OWL
Semantic Web - OWL
 
Semantic Web - Ontologies
Semantic Web - OntologiesSemantic Web - Ontologies
Semantic Web - Ontologies
 
Semantic Web - RDF
Semantic Web - RDFSemantic Web - RDF
Semantic Web - RDF
 
Semantic Web - Overview
Semantic Web - OverviewSemantic Web - Overview
Semantic Web - Overview
 
Semantic Web - Introduction
Semantic Web - IntroductionSemantic Web - Introduction
Semantic Web - Introduction
 
E-Librarian Service
E-Librarian ServiceE-Librarian Service
E-Librarian Service
 

Recently uploaded

Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Safe Software
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
panagenda
 

Recently uploaded (20)

Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
 
MS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectorsMS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectors
 
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...
 
Exploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with MilvusExploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with Milvus
 
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdfRising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
 
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
 
Introduction to Multilingual Retrieval Augmented Generation (RAG)
Introduction to Multilingual Retrieval Augmented Generation (RAG)Introduction to Multilingual Retrieval Augmented Generation (RAG)
Introduction to Multilingual Retrieval Augmented Generation (RAG)
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a Fresher
 
Platformless Horizons for Digital Adaptability
Platformless Horizons for Digital AdaptabilityPlatformless Horizons for Digital Adaptability
Platformless Horizons for Digital Adaptability
 
Understanding the FAA Part 107 License ..
Understanding the FAA Part 107 License ..Understanding the FAA Part 107 License ..
Understanding the FAA Part 107 License ..
 
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
 
DEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 AmsterdamDEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : Uncertainty
 
DBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor Presentation
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024
 
[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf
 
Six Myths about Ontologies: The Basics of Formal Ontology
Six Myths about Ontologies: The Basics of Formal OntologySix Myths about Ontologies: The Basics of Formal Ontology
Six Myths about Ontologies: The Basics of Formal Ontology
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
 

Media IT - XML and XML Transformation (XSLT)

  • 1. Media IT :: Dr Serge Linckels :: http://www.linckels.lu/ :: serge@linckels.lu :: Faculty of Science, Technology and Communication (FSTC) Bachelor en informatique (professionnel) -- Media IT -– ¯_(ツ)_/¯ Unit 9 XML Transformation
  • 2. Media IT :: Dr Serge Linckels :: http://www.linckels.lu/ :: serge@linckels.lu :: 9. XML Transformation 2 9.1 XSLT overview 9.2 XSLT transformation principle 9.3 XML + XSLT References 9.4 Exercise
  • 3. Media IT :: Dr Serge Linckels :: http://www.linckels.lu/ :: serge@linckels.lu :: 9. XML Transformation 9.1 XSLT overview 3 Picture created by Harald Sack
  • 4. Media IT :: Dr Serge Linckels :: http://www.linckels.lu/ :: serge@linckels.lu :: 9. XML Transformation 9.1 XSLT overview 4 XSLT overview Extensible Stylesheet Language Transformations (XSLT) is an XML-based language used to specify rules by which one XML document is transformed into another (XML) document The resulting document may be XML syntax or another format, such as HTML or plain text Examples of applications of XSLT: - convert data between different XML schemas - convert XML data into HTML or XHTML documents for web pages (e.g., with CSS) - creating a dynamic web page - convert into an intermediate XML format that can be converted to PDF documents Such a transformation is based on the following languages: - XSLT: specifies the transformation rules - XSL-FO: describes how to transform layout - XPath: access to specific parts of an XML document
  • 5. Media IT :: Dr Serge Linckels :: http://www.linckels.lu/ :: serge@linckels.lu :: 9. XML Transformation 9.2 XSLT transformation principle 5 XML documents DTD/XML-S XSL document 1 XSL document 2 PDF document HTML WML XSLT processor
  • 6. Media IT :: Dr Serge Linckels :: http://www.linckels.lu/ :: serge@linckels.lu :: 9. XML Transformation 9.2 XSLT transformation principle 6 XSL stylesheet tree representation of XML document XSL works on the abstract tree representation of the XML document A set of transformation rules are required in form a an XSLT document, e.g., template (XSL stylesheet) output document + The structure tree is browsed and for each node the appropriate template from the XSL stylesheet is applied
  • 7. Media IT :: Dr Serge Linckels :: http://www.linckels.lu/ :: serge@linckels.lu :: 9. XML Transformation 9.2 XSLT transformation principle 7 <data> <row num="1">toto 1</row> <row num="2">toto 2</row> <row num="3">toto 3</row> </data> XML document <?xml version="1.0" encoding="ISO-8859-1"?> <html xsl:version="1.0" xmlns:xsl="http://www.w3.org/ 1999/XSL/Transform"> <body> <h1>Demo</h1> <xsl:for-each select="row"> <br/>Row: <xsl:value-of select="@num"/> - Data: <xsl:value-of select="."/> </xsl:for-each> </body> </html> XSL stylesheet <html><body> <h1>Demo</h1> <br/>Row: 1 - Data: toto 1 <br/>Row: 2 - Data: toto 2 <br/>Row: 3 - Data: toto 3 </body></html> HTML document XSLT processor
  • 8. Media IT :: Dr Serge Linckels :: http://www.linckels.lu/ :: serge@linckels.lu :: 9. XML Transformation 9.2 XSLT transformation principle 8 Perform XSL transformation using a stylesheet <?xml version="1.0" encoding="ISO-8859-1"?> <?xml-stylesheet type="text/xsl" href="stylesheet.xsl" ?> <data> <row num="1">toto 1</row> <row num="2">toto 2</row> <row num="3">toto 3</row> </data>
  • 9. Media IT :: Dr Serge Linckels :: http://www.linckels.lu/ :: serge@linckels.lu :: 9. XML Transformation 9.2 XSLT transformation principle 9 import java.io.FileReader; import javax.xml.transform.Result; import javax.xml.transform.Source; import javax.xml.transform.Transformer; import javax.xml.transform.TransformerFactory; import javax.xml.transform.stream.StreamResult; import javax.xml.transform.stream.StreamSource; public class TestTransformation { public static void main(String[] args) throws Exception { Source sourceXSL = new StreamSource(new FileReader("stylesheet.xsl")); Source sourceXML = new StreamSource(new FileReader("data.xml")); TransformerFactory trFac = TransformerFactory.newInstance(); Transformer tf; Result resultOnScreen = new StreamResult(System.out); tf = trFac.newTransformer(sourceXSL); tf.transform(sourceXML, resultOnScreen); } } Perform XSL transformation using a Java programme
  • 10. Media IT :: Dr Serge Linckels :: http://www.linckels.lu/ :: serge@linckels.lu :: 9. XML Transformation 9.3 XML + XSLT References 10 XML in a Nutshell Elliotte R. Harold, W. Scott Means, W. Scott Means E-Librarian Service User-Friendly Semantic Search in Digital Libraries Serge Linckels, Christoph Meinel
  • 11. Media IT :: Dr Serge Linckels :: http://www.linckels.lu/ :: serge@linckels.lu :: 9. XML Transformation 9.4 Exercise