ls-a/xsl-core
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.
ls-a/xsl-core 适用场景与选型建议
ls-a/xsl-core 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 65 次下载、GitHub Stars 达 0, 最近一次更新时间为 2025 年 11 月 13 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「pdf」 「W3C」 「xsl」 「specification」 「fo」 「fop」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 ls-a/xsl-core 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 ls-a/xsl-core 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 ls-a/xsl-core 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Easily disable HTML5 validation errors.
Symfony 2 / 3 Apache FOP Bundle
Pleasantly work with asynchronous code.
xslt template engine for laravel
php library for faster development
Provides TCPDF integration for Symfony
统计信息
- 总下载量: 65
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 45
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: GPL-3.0-or-later
- 更新时间: 2025-11-13