SlideShare una empresa de Scribd logo
1 de 32
Make Your Data Pretty with
XSL-FO
Extensible Stylesheet LanguageFormatting Objects
What We Will Cover
•
•
•
•
•
•
•
•

What is XSL-FO?
Different formatting engines
Introduction to XSL
Introduction to FO
Examples of using FO to create a PDF
Examples of using FO including XSL/XML to create a PDF
Example of using NFop in C# to create a PDF
Why our project switch from SSRS to XSL-FO
What is XSL-FO?
XSL (eXtensible Stylesheet Language)
A language written to provide formatting for XML
documents.
FO (Formatting Objects)
Containers of content that preserve structure and associate
presentational information.
What do you use it for?
XSL-FO is a markup language for XML document
formatting which is most often used to generate PDFs.
What is XSL-FO?
The XSL-FO language was designed for paged media.
FO works best for what could be called "content-driven" design.
This is the standard method of layout for books, articles, legal
documents, and so forth. It involves a single flowing span of
fairly contiguous text, with various repeating information built into
the margins of a page. This is as opposed to "layout-driven"
design, which is used in newspapers or magazines. If content in
those documents does not fit in the required space, some of it is
trimmed away until it does fit. XSL-FO does not easily handle the
tight restrictions of magazine layout; indeed, in many cases, it
lacks the ability to express some forms of said layout.
How XSL-FO Works
XML Document

XSLT Document

XSLT
Engine

FO Document

FO Engine

PDF Document

1. XML document and XSLT
document are fed into an
XSLT engine.
2. Using the rules in the
XSLT document, the XSLT
engine tranforms the XML
into a FO Document.
3. The FO document is fed
into the FO engine.
4. The FO engine uses rules
in the FO document to
render the PDF.
What can XSL-FO do?
• Multiple columns
• Lists - XSL-FO handles the numbering
• Pagination controls - widows and orphans of text and what is
kept together on a page
• Footnotes
• Tables - much like HTML
• Text orientation - different languages have different text
orientations
• Page numbers - XSL-FO handles the numbering
• Include images
• Indexing - XSL-FO 1.1 supports creation of an index
• Flows - XSL-FO 1.1 supports more than 1 flow
Advantages
XML language – Because it is an XML language, only an XSLT transform
(and an XSLT processor) is required to generate XSL-FO code from any
XML language.
Ease of use – Another advantage of XSL-FO is the relative ease of use.
Much of the functionality of the language is based on work from CSS.
Low cost – Compared with commercial typesetting and page layout
products, XSL-FO can offer a much lower cost solution. The initial cost of
ownership is low (zero if the free implementations, such as Apache FOP,
meet your requirements), especially compared to the cost of commercial
composition tools.
Multi-lingual – XSL-FO has been designed to work for all written human
languages.
Mature standard – With the publication of XSL-FO 1.1, XSL-FO is proving
to be a mature standard with a number of solid commercial and noncommercial implementations.
Drawbacks
Limited capabilities – XSL-FO was specifically designed to meet the
requirements of "lightly designed" documents typified by technical
manuals, business documents, invoices, and so on. In particular, XSLFO does not provide a direct way to get formatting effects that depend
on knowing the page position relationship of two formatting objects.
Missing features - there are important layout features that are simply
not in XSL-FO.
Extension dependency – one must consider proprietary extensions
provided by the different XSL-FO implementations. These extensions
add features that are not part of the core specification.
Different FOPs
(Formatting Objects Processors)
Commercial Versions
•
•
•
•

Works with .Net
Good documentation and support
Can support things not in the FOP spec
Up to date with the spec

Examples
• Ibex PDF Creator
• AntennaHouse
• RenderX
• ASPOSE
Free Versions
Apache.org Project's FOP - http://xmlgraphics.apache.org/fop/
• Good documentation
• Java app - need the open-source IKVM.NET project to run Java
apps on .NET. It is a Java virtual machine (JVM) on top of .NET.
• 'THE' standard in the open source processors
• Always being updated

NFop - http://sourceforge.net/projects/nfop/
• Ported to .Net via J#
• Last update was in 2010
• Easy to use (I'll show examples later)
Intro to XSL
Intro to XSL
XSL (eXtensible Stylesheet Language)
A language written to provide formatting for XML documents.
XSL consists of two parts:
• A method for transforming XML documents
• A method for formatting XML documents

XSLT (eXtensible Stylesheet Language for Transformations)
This language takes existing XML documents and transforms them into
other XML documents. For example, change XML into HTML, plain
text or another XML document.
XSLT Example
Take a simple XML document:
<?xml version="1.0"?>
<name>Brian</name>
An XSLT document:
<?xml version="1.0"?>
<html xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xsl:version="1.0">
<body>
<p>Hello <xsl:value-of select="name" /></p>
</body>
</html>
XSLT Example
<xsl:value-of select="name" /> indicates to replace this tag with the text
at the node "name". "name" is referred to as the XPath expression. An
XPath expression works like navigating a file system; where a forward
slash (/) selects subdirectories.
Output:
<html xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xsl:version="1.0">
<body>
<p>Hello Brian</p>
</body>
</html>
XSLT Example 2
<?xml version="1.0"?>
<root>
<person>

|<fname>Brian</fname>|

|<lname>Landers</lname>|
</person>
<person>
|<fname>Michelle</fname>|

|<lname>Landers</lname>|
</person>
</root>
XSLT Example 2
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="html" indent="yes" doctype-public="-//W3C//DTD HTML 4.0 Transitional//EN" />
<xsl:template match="/">

|<html><body>|

||
|<xsl:for-each select="root/person">|

|

<p>Hello <xsl:value-of select="fname"/></p>|

|</xsl:for-each>|

|</body></html>|
XSLT Example 2
The <xsl:template> element contains rules to apply when a specified node is matched. match="/"
defines the whole document.
<xsl:for-each select="root/person"> indicates a loop and to do what is between the <xsl:for-each> tags
for each instance of what is selected.
output:
<html><body>
||
|<p>Hello Brian</p>|

||
|<p>Hello Michelle</p>|
</body></html>
XSLT if Test Example
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="html" indent="yes" doctype-public="-//W3C//DTD HTML 4.0 Transitional//EN" />
<xsl:template match="/">
|<html><body>|

||
|<xsl:for-each select="root/person">|

|<xsl:if test="root/person/fname = 'Brian' ">|

|

|

|<p>Hello <xsl:value-of select="fname"/></p>|

|</xsl:if>|

|</xsl:for-each>|
XSLT if Test Example
<xsl:if test="root/person/name = 'Brian' "> is an if statement. if the condition is true you
can continue, otherwise you skip to the </xsl:if>
output:
<html><body>
||
|<p>Hello Brian</p>|
</body></html>
Some Other XSL Functions
Functions on numeric values: abs, ceiling, floor, round, format-number
|<xsl:value-of select="round(Total)" />|

|<Total>123456.7</Total>|

|<xsl:value-of select="format-number(Total, '###,##0.00')" />|

|123,456.70|

functions on strings: compare, concat, substring, upper-case, lower-case, replace
|<xsl:value-of select="concat(fname,lname)" />|
Intro to FO
Document Layout
The page is divided into regions.

region-before

region
start

region-body

region-after

region
end
Documents Parts
An XSL-FO document is divided into two main parts:

• One layout master set (layout-master-set), which specifies one or
more page master templates (simple-page-master) to be used in the
document.
• One or more page sequences, which contain the content of the
document.
Documents Parts
<?xml version="1.0" encoding="utf-8"?>
<fo:root xmlns:fo="http://www.w3.org/1999/XSL/Format">
<fo:layout-master-set>
<fo:simple-page-master master-name="hello"> <!--name of page is "hello"-->
<!-- Page template goes here - define your regions-->
</fo:simple-page-master>
</fo:layout-master-set>
<fo:page-sequence master-reference="hello"> <!-- matches name of page from above->
<!-- Page content goes here -->
</fo:page-sequence>
</fo:root>
Hello World Example
<?xml version="1.0" encoding="utf-8"?>
<fo:root xmlns:fo="http://www.w3.org/1999/XSL/Format">

<fo:layout-master-set>
<fo:simple-page-master master-name="hello" page-height="8.5in" page-width="11in"
margin-top="1in" margin-bottom="1in" margin-left="1in" margin-right="1in">
<fo:region-body margin-top="1in" margin-bottom=".5in"/> <!-- Page template goes here -->
</fo:simple-page-master>
</fo:layout-master-set>
<fo:page-sequence master-reference="hello">
<fo:flow flow-name="xsl-region-body">
<!-- Page content goes here -->
<fo:block font-size="18pt" text-align="center" font-weight="bold">
Hello World!
</fo:block>
</fo:flow>
</fo:page-sequence>
</fo:root>
Page-Sequence
The layout-master-set FO is followed by one or more page-sequence
FOs, which must reference one of the simple-page-master templates
by name. The page-sequence FOs contain the contents of the page or
pages.
<fo:page-sequence master-reference="hello">
<!--Page contents-->
</fo:page-sequence>
Notice that the value of the master-reference attribute matches the
master-name defined in the simple-page-master FO.
Flow and Static-Content
The contents of the page inside the page-sequence FO are either
static, meaning they appear the same on each page or flowing,
meaning they flow from one page to the next. Static content is
contained in static-content FOs and flowing content is contained in flow
FOs.
<fo:page-sequence master-reference="hello">
<fo:flow flow-name="xsl-region-body">
<!--flowing content-->
</fo:flow>
</fo:page-sequence>
This example only has a flow FO. In most cases, the region-body has
flowing content and the other regions have static content.
<fo:block>
The block FO is used for separating and formatting generic blocks,
such as paragraphs, tables or lists. Blocks can be nested.
Why Our Projects Switched From
SSRS to XSL-FO
SSRS to XSL-FO
SSRS wasn't able to do what we wanted easily and as precisely.
SSRS made some decisions on placement on it's own. The client has
premade paper forms and needed placement to be exact.
We needed one flow to go top-to-bottom and another flow to go bottomto-top. SSRS couldn't do that.
Here's what we also got out of switching:
• Needed to use custom DLL we created to help with reports. This dll
isn't needed in the new XSL-FO reports.
• 3 RDL files that were very similar (about 90% the same) were
condensed to 1 XSL file that used data from XML file to determine
which sections changed. Now 1 file only needs to be updated and
all 3 reports stay in sync.
Make Your Data Pretty With XSL-FO (Extensible Stylesheet Language)

Más contenido relacionado

Último

+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
Health
 
%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...
%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...
%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...
masabamasaba
 
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
masabamasaba
 
%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...
%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...
%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...
masabamasaba
 
Abortion Pills In Pretoria ](+27832195400*)[ 🏥 Women's Abortion Clinic In Pre...
Abortion Pills In Pretoria ](+27832195400*)[ 🏥 Women's Abortion Clinic In Pre...Abortion Pills In Pretoria ](+27832195400*)[ 🏥 Women's Abortion Clinic In Pre...
Abortion Pills In Pretoria ](+27832195400*)[ 🏥 Women's Abortion Clinic In Pre...
Medical / Health Care (+971588192166) Mifepristone and Misoprostol tablets 200mg
 
%+27788225528 love spells in Toronto Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Toronto Psychic Readings, Attraction spells,Brin...%+27788225528 love spells in Toronto Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Toronto Psychic Readings, Attraction spells,Brin...
masabamasaba
 

Último (20)

%in kempton park+277-882-255-28 abortion pills for sale in kempton park
%in kempton park+277-882-255-28 abortion pills for sale in kempton park %in kempton park+277-882-255-28 abortion pills for sale in kempton park
%in kempton park+277-882-255-28 abortion pills for sale in kempton park
 
Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...
Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...
Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...
 
%in ivory park+277-882-255-28 abortion pills for sale in ivory park
%in ivory park+277-882-255-28 abortion pills for sale in ivory park %in ivory park+277-882-255-28 abortion pills for sale in ivory park
%in ivory park+277-882-255-28 abortion pills for sale in ivory park
 
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
 
VTU technical seminar 8Th Sem on Scikit-learn
VTU technical seminar 8Th Sem on Scikit-learnVTU technical seminar 8Th Sem on Scikit-learn
VTU technical seminar 8Th Sem on Scikit-learn
 
OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...
OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...
OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...
 
WSO2CON 2024 Slides - Open Source to SaaS
WSO2CON 2024 Slides - Open Source to SaaSWSO2CON 2024 Slides - Open Source to SaaS
WSO2CON 2024 Slides - Open Source to SaaS
 
%in Rustenburg+277-882-255-28 abortion pills for sale in Rustenburg
%in Rustenburg+277-882-255-28 abortion pills for sale in Rustenburg%in Rustenburg+277-882-255-28 abortion pills for sale in Rustenburg
%in Rustenburg+277-882-255-28 abortion pills for sale in Rustenburg
 
Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...
Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...
Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...
 
Artyushina_Guest lecture_YorkU CS May 2024.pptx
Artyushina_Guest lecture_YorkU CS May 2024.pptxArtyushina_Guest lecture_YorkU CS May 2024.pptx
Artyushina_Guest lecture_YorkU CS May 2024.pptx
 
%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...
%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...
%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...
 
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
 
%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...
%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...
%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...
 
WSO2CON 2024 - Navigating API Complexity: REST, GraphQL, gRPC, Websocket, Web...
WSO2CON 2024 - Navigating API Complexity: REST, GraphQL, gRPC, Websocket, Web...WSO2CON 2024 - Navigating API Complexity: REST, GraphQL, gRPC, Websocket, Web...
WSO2CON 2024 - Navigating API Complexity: REST, GraphQL, gRPC, Websocket, Web...
 
%in tembisa+277-882-255-28 abortion pills for sale in tembisa
%in tembisa+277-882-255-28 abortion pills for sale in tembisa%in tembisa+277-882-255-28 abortion pills for sale in tembisa
%in tembisa+277-882-255-28 abortion pills for sale in tembisa
 
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain
 
WSO2Con2024 - Enabling Transactional System's Exponential Growth With Simplicity
WSO2Con2024 - Enabling Transactional System's Exponential Growth With SimplicityWSO2Con2024 - Enabling Transactional System's Exponential Growth With Simplicity
WSO2Con2024 - Enabling Transactional System's Exponential Growth With Simplicity
 
WSO2CON 2024 - Cloud Native Middleware: Domain-Driven Design, Cell-Based Arch...
WSO2CON 2024 - Cloud Native Middleware: Domain-Driven Design, Cell-Based Arch...WSO2CON 2024 - Cloud Native Middleware: Domain-Driven Design, Cell-Based Arch...
WSO2CON 2024 - Cloud Native Middleware: Domain-Driven Design, Cell-Based Arch...
 
Abortion Pills In Pretoria ](+27832195400*)[ 🏥 Women's Abortion Clinic In Pre...
Abortion Pills In Pretoria ](+27832195400*)[ 🏥 Women's Abortion Clinic In Pre...Abortion Pills In Pretoria ](+27832195400*)[ 🏥 Women's Abortion Clinic In Pre...
Abortion Pills In Pretoria ](+27832195400*)[ 🏥 Women's Abortion Clinic In Pre...
 
%+27788225528 love spells in Toronto Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Toronto Psychic Readings, Attraction spells,Brin...%+27788225528 love spells in Toronto Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Toronto Psychic Readings, Attraction spells,Brin...
 

Destacado

How Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental HealthHow Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental Health
ThinkNow
 
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie Insights
Kurio // The Social Media Age(ncy)
 

Destacado (20)

2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by Hubspot2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by Hubspot
 
Everything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPTEverything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPT
 
Product Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage EngineeringsProduct Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage Engineerings
 
How Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental HealthHow Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental Health
 
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfAI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
 
Skeleton Culture Code
Skeleton Culture CodeSkeleton Culture Code
Skeleton Culture Code
 
PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024
 
Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)
 
How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024
 
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie Insights
 
Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024
 
5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary
 
ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd
 
Getting into the tech field. what next
Getting into the tech field. what next Getting into the tech field. what next
Getting into the tech field. what next
 
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentGoogle's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search Intent
 
How to have difficult conversations
How to have difficult conversations How to have difficult conversations
How to have difficult conversations
 
Introduction to Data Science
Introduction to Data ScienceIntroduction to Data Science
Introduction to Data Science
 
Time Management & Productivity - Best Practices
Time Management & Productivity -  Best PracticesTime Management & Productivity -  Best Practices
Time Management & Productivity - Best Practices
 
The six step guide to practical project management
The six step guide to practical project managementThe six step guide to practical project management
The six step guide to practical project management
 
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
 

Make Your Data Pretty With XSL-FO (Extensible Stylesheet Language)

  • 1. Make Your Data Pretty with XSL-FO Extensible Stylesheet LanguageFormatting Objects
  • 2. What We Will Cover • • • • • • • • What is XSL-FO? Different formatting engines Introduction to XSL Introduction to FO Examples of using FO to create a PDF Examples of using FO including XSL/XML to create a PDF Example of using NFop in C# to create a PDF Why our project switch from SSRS to XSL-FO
  • 3. What is XSL-FO? XSL (eXtensible Stylesheet Language) A language written to provide formatting for XML documents. FO (Formatting Objects) Containers of content that preserve structure and associate presentational information. What do you use it for? XSL-FO is a markup language for XML document formatting which is most often used to generate PDFs.
  • 4. What is XSL-FO? The XSL-FO language was designed for paged media. FO works best for what could be called "content-driven" design. This is the standard method of layout for books, articles, legal documents, and so forth. It involves a single flowing span of fairly contiguous text, with various repeating information built into the margins of a page. This is as opposed to "layout-driven" design, which is used in newspapers or magazines. If content in those documents does not fit in the required space, some of it is trimmed away until it does fit. XSL-FO does not easily handle the tight restrictions of magazine layout; indeed, in many cases, it lacks the ability to express some forms of said layout.
  • 5. How XSL-FO Works XML Document XSLT Document XSLT Engine FO Document FO Engine PDF Document 1. XML document and XSLT document are fed into an XSLT engine. 2. Using the rules in the XSLT document, the XSLT engine tranforms the XML into a FO Document. 3. The FO document is fed into the FO engine. 4. The FO engine uses rules in the FO document to render the PDF.
  • 6. What can XSL-FO do? • Multiple columns • Lists - XSL-FO handles the numbering • Pagination controls - widows and orphans of text and what is kept together on a page • Footnotes • Tables - much like HTML • Text orientation - different languages have different text orientations • Page numbers - XSL-FO handles the numbering • Include images • Indexing - XSL-FO 1.1 supports creation of an index • Flows - XSL-FO 1.1 supports more than 1 flow
  • 7. Advantages XML language – Because it is an XML language, only an XSLT transform (and an XSLT processor) is required to generate XSL-FO code from any XML language. Ease of use – Another advantage of XSL-FO is the relative ease of use. Much of the functionality of the language is based on work from CSS. Low cost – Compared with commercial typesetting and page layout products, XSL-FO can offer a much lower cost solution. The initial cost of ownership is low (zero if the free implementations, such as Apache FOP, meet your requirements), especially compared to the cost of commercial composition tools. Multi-lingual – XSL-FO has been designed to work for all written human languages. Mature standard – With the publication of XSL-FO 1.1, XSL-FO is proving to be a mature standard with a number of solid commercial and noncommercial implementations.
  • 8. Drawbacks Limited capabilities – XSL-FO was specifically designed to meet the requirements of "lightly designed" documents typified by technical manuals, business documents, invoices, and so on. In particular, XSLFO does not provide a direct way to get formatting effects that depend on knowing the page position relationship of two formatting objects. Missing features - there are important layout features that are simply not in XSL-FO. Extension dependency – one must consider proprietary extensions provided by the different XSL-FO implementations. These extensions add features that are not part of the core specification.
  • 10. Commercial Versions • • • • Works with .Net Good documentation and support Can support things not in the FOP spec Up to date with the spec Examples • Ibex PDF Creator • AntennaHouse • RenderX • ASPOSE
  • 11. Free Versions Apache.org Project's FOP - http://xmlgraphics.apache.org/fop/ • Good documentation • Java app - need the open-source IKVM.NET project to run Java apps on .NET. It is a Java virtual machine (JVM) on top of .NET. • 'THE' standard in the open source processors • Always being updated NFop - http://sourceforge.net/projects/nfop/ • Ported to .Net via J# • Last update was in 2010 • Easy to use (I'll show examples later)
  • 13. Intro to XSL XSL (eXtensible Stylesheet Language) A language written to provide formatting for XML documents. XSL consists of two parts: • A method for transforming XML documents • A method for formatting XML documents XSLT (eXtensible Stylesheet Language for Transformations) This language takes existing XML documents and transforms them into other XML documents. For example, change XML into HTML, plain text or another XML document.
  • 14. XSLT Example Take a simple XML document: <?xml version="1.0"?> <name>Brian</name> An XSLT document: <?xml version="1.0"?> <html xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xsl:version="1.0"> <body> <p>Hello <xsl:value-of select="name" /></p> </body> </html>
  • 15. XSLT Example <xsl:value-of select="name" /> indicates to replace this tag with the text at the node "name". "name" is referred to as the XPath expression. An XPath expression works like navigating a file system; where a forward slash (/) selects subdirectories. Output: <html xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xsl:version="1.0"> <body> <p>Hello Brian</p> </body> </html>
  • 16. XSLT Example 2 <?xml version="1.0"?> <root> <person> |<fname>Brian</fname>| |<lname>Landers</lname>| </person> <person> |<fname>Michelle</fname>| |<lname>Landers</lname>| </person> </root>
  • 17. XSLT Example 2 <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl:output method="html" indent="yes" doctype-public="-//W3C//DTD HTML 4.0 Transitional//EN" /> <xsl:template match="/"> |<html><body>| || |<xsl:for-each select="root/person">| | <p>Hello <xsl:value-of select="fname"/></p>| |</xsl:for-each>| |</body></html>|
  • 18. XSLT Example 2 The <xsl:template> element contains rules to apply when a specified node is matched. match="/" defines the whole document. <xsl:for-each select="root/person"> indicates a loop and to do what is between the <xsl:for-each> tags for each instance of what is selected. output: <html><body> || |<p>Hello Brian</p>| || |<p>Hello Michelle</p>| </body></html>
  • 19. XSLT if Test Example <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl:output method="html" indent="yes" doctype-public="-//W3C//DTD HTML 4.0 Transitional//EN" /> <xsl:template match="/"> |<html><body>| || |<xsl:for-each select="root/person">| |<xsl:if test="root/person/fname = 'Brian' ">| | | |<p>Hello <xsl:value-of select="fname"/></p>| |</xsl:if>| |</xsl:for-each>|
  • 20. XSLT if Test Example <xsl:if test="root/person/name = 'Brian' "> is an if statement. if the condition is true you can continue, otherwise you skip to the </xsl:if> output: <html><body> || |<p>Hello Brian</p>| </body></html>
  • 21. Some Other XSL Functions Functions on numeric values: abs, ceiling, floor, round, format-number |<xsl:value-of select="round(Total)" />| |<Total>123456.7</Total>| |<xsl:value-of select="format-number(Total, '###,##0.00')" />| |123,456.70| functions on strings: compare, concat, substring, upper-case, lower-case, replace |<xsl:value-of select="concat(fname,lname)" />|
  • 23. Document Layout The page is divided into regions. region-before region start region-body region-after region end
  • 24. Documents Parts An XSL-FO document is divided into two main parts: • One layout master set (layout-master-set), which specifies one or more page master templates (simple-page-master) to be used in the document. • One or more page sequences, which contain the content of the document.
  • 25. Documents Parts <?xml version="1.0" encoding="utf-8"?> <fo:root xmlns:fo="http://www.w3.org/1999/XSL/Format"> <fo:layout-master-set> <fo:simple-page-master master-name="hello"> <!--name of page is "hello"--> <!-- Page template goes here - define your regions--> </fo:simple-page-master> </fo:layout-master-set> <fo:page-sequence master-reference="hello"> <!-- matches name of page from above-> <!-- Page content goes here --> </fo:page-sequence> </fo:root>
  • 26. Hello World Example <?xml version="1.0" encoding="utf-8"?> <fo:root xmlns:fo="http://www.w3.org/1999/XSL/Format"> <fo:layout-master-set> <fo:simple-page-master master-name="hello" page-height="8.5in" page-width="11in" margin-top="1in" margin-bottom="1in" margin-left="1in" margin-right="1in"> <fo:region-body margin-top="1in" margin-bottom=".5in"/> <!-- Page template goes here --> </fo:simple-page-master> </fo:layout-master-set> <fo:page-sequence master-reference="hello"> <fo:flow flow-name="xsl-region-body"> <!-- Page content goes here --> <fo:block font-size="18pt" text-align="center" font-weight="bold"> Hello World! </fo:block> </fo:flow> </fo:page-sequence> </fo:root>
  • 27. Page-Sequence The layout-master-set FO is followed by one or more page-sequence FOs, which must reference one of the simple-page-master templates by name. The page-sequence FOs contain the contents of the page or pages. <fo:page-sequence master-reference="hello"> <!--Page contents--> </fo:page-sequence> Notice that the value of the master-reference attribute matches the master-name defined in the simple-page-master FO.
  • 28. Flow and Static-Content The contents of the page inside the page-sequence FO are either static, meaning they appear the same on each page or flowing, meaning they flow from one page to the next. Static content is contained in static-content FOs and flowing content is contained in flow FOs. <fo:page-sequence master-reference="hello"> <fo:flow flow-name="xsl-region-body"> <!--flowing content--> </fo:flow> </fo:page-sequence> This example only has a flow FO. In most cases, the region-body has flowing content and the other regions have static content.
  • 29. <fo:block> The block FO is used for separating and formatting generic blocks, such as paragraphs, tables or lists. Blocks can be nested.
  • 30. Why Our Projects Switched From SSRS to XSL-FO
  • 31. SSRS to XSL-FO SSRS wasn't able to do what we wanted easily and as precisely. SSRS made some decisions on placement on it's own. The client has premade paper forms and needed placement to be exact. We needed one flow to go top-to-bottom and another flow to go bottomto-top. SSRS couldn't do that. Here's what we also got out of switching: • Needed to use custom DLL we created to help with reports. This dll isn't needed in the new XSL-FO reports. • 3 RDL files that were very similar (about 90% the same) were condensed to 1 XSL file that used data from XML file to determine which sections changed. Now 1 file only needs to be updated and all 3 reports stay in sync.