ls-a/xsl-core
最新稳定版本:1.0.0
Composer 安装命令:
composer require ls-a/xsl-core
包简介
Port of XSL 1.1 specification (W3C Recommendation 05 December 2006).
README 文档
README
This documentation is also available in these languages:
This library provides a simple and readable interface for easily generating and validating your XSL-FO documents.
Code sample:
<?php $foNamespace = new XmlNamespace('fo', 'http://www.w3.org/1999/XSL/Format'); $generatedDocument = new XmlDocument(); $generatedDocument->setGlobalNamespace($foNamespace); $root = (new Root()) ->namespace($foNamespace) ->child((new LayoutMasterSet()) ->child((new SimplePageMaster()) ->attributes([ new Attribute('master-name', 'simple'), new Attribute('page-height', '29.7cm'), new Attribute('page-width', '21cm'), new Attribute('margin', '2cm'), ]) ->child(new RegionBody()))) ->child((new PageSequence()) ->attribute(new Attribute('master-reference', 'simple')) ->child((new Flow()) ->attribute(new Attribute('flow-name', 'xsl-region-body')) ->child((new Block()) ->attributes([ new Attribute('font-size', '12pt'), new Attribute('line-height', '14pt'), ]) ->content('XSL-FO (Extensible Stylesheet Language Formatting Objects) is an XML language used to describe the layout of printed documents.') ) ->child((new Block()) ->content('It is commonly used with XSLT to transform XML data into printable files using tools such as Apache FOP.') ) ->child((new Block()) ->child((new BasicLink()) ->attribute(new Attribute('external-destination', "url('http://exemple.com/xsl-fo-docs')")) ->content('FOP documentation') ) ) ) );
Features
This library follows the XSL-FO 1.1 specification: https://www.w3.org/TR/xsl11/.
It supports:
- The various XSL-FO tags (
fo:block,fo:instream-foreign-object, ...) - The different possible properties for each tag
- The various possible values for each property
- The use of expressions such as
floor(1.25): https://www.w3.org/TR/xsl11/#d0e5032 - The use of XSL-FO functions, known as the Core Function Library: https://www.w3.org/TR/xsl11/#d0e5857
- References to inherited properties
For each structure, you can use the validate method to check whether the generated structure is correct.
Why?
The XSL-FO specification and its implementations offer many advantages in an era where PDFs are generated by a web rendering engine:
- XSL-FO correctly handles bookmarks
- XSL-FO natively supports form-related controls
- XSL-FO integrates digital accessibility, making it easier to generate accessible PDF documents
- XSL-FO does not require installing a browser rendering engine such as Puppeteer
Beyond these advantages, this package:
- Is well tested, with its 7,500 test files (and counting!)
- Is performance-oriented, maintaining XSL-FO’s advantages over browser-based rendering
- Follows modern coding conventions and is fully documented
- Is designed to work with PHP 8.0 🚀
Generate PDF documents with XSL Core
XSL Core is not an implementation, meaning it does not create PDF documents with XSL-FO. It is a library designed to validate and simplify document creation.
To generate a document, you need to use one of the available implementations:
- Apache FOP (open source, free): https://xmlgraphics.apache.org/fop/
- AntennaHouse (proprietary, paid): https://www.antennahouse.com/
- RenderX (proprietary, paid): https://www.renderx.com/
Apache FOP Example
Download Apache FOP: https://xmlgraphics.apache.org/fop/download.html or apt install fop (depending on your distribution)
Generate a document with XSL Core:
<?php use Lsa\Xml\Utils\Xml\XmlDocument; use Lsa\Xml\Utils\Xml\XmlNamespace; use Lsa\Xsl\Core\Tags\Layout\Root; require_once __DIR__.'/../vendor/autoload.php'; $foNamespace = new XmlNamespace('fo', 'http://www.w3.org/1999/XSL/Format'); $generatedDocument = new XmlDocument(); $generatedDocument->setGlobalNamespace($foNamespace); // Build structure $root = (new Root()) ->namespace($foNamespace); // Write in a file file_put_contents('my-document.fo', $root->asXml()); // Call Apache FOP, with any mean you wish to shell_exec('fop my-document.fo my-pdf.pdf');
Installation
This library is available on Composer. Install it with:
composer require ls-a/xsl-core
Changelog
Please refer to the CHANGELOG file to see the latest changes.
Support
We put our heart into delivering high-quality products that are accessible to everyone. If you like our work, don’t hesitate to reach out to us for your next project!
Contributing
Contributions are governed by the CONTRIBUTING file.
Security
If you’ve found a bug or vulnerability, please contact us by email at contact@ls-a.fr instead of opening an issue, in order to protect the security of other users.
Credits
- Renaud Berthier
License
The MIT License (MIT). Please see License File for more information.
统计信息
- 总下载量: 12
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 0
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: GPL-3.0-or-later
- 更新时间: 2025-11-13