genkgo/xsl
Composer 安装命令:
composer require genkgo/xsl
包简介
XSL 2.0 Transpiler in PHP
README 文档
README
XSL 2.0 Transpiler in PHP.
Installation
Requires supported PHP version. It is installable and autoloadable via Composer as genkgo/xsl.
Quality
To run the unit tests at the command line, issue ./vendor/bin/phpunit -c phpunit.xml. This library attempts to comply with
PSR-1, PSR-2, and PSR-4. If you notice compliance oversights, please send a patch via pull request.
Getting Started
Replace XSLTProcessor with Genkgo\Xsl\XsltProcessor, change version="1.0" in version="2.0" and you are done!
<?php use Genkgo\Xsl\XsltProcessor; use Genkgo\Xsl\Cache\NullCache; $xslDoc = new DOMDocument(); $xslDoc->load('Stubs/collection.xsl'); $xmlDoc = new DOMDocument(); $xmlDoc->load('Stubs/collection.xml'); $transpiler = new XsltProcessor(new NullCache()); $transpiler->importStylesheet($xslDoc); echo $transpiler->transformToXML($xmlDoc);
Create your own extenions
You can also register your own extensions. Just implement the XmlNamespaceInterface and you
are ready to use your own element transformations and xpath functions. See the example below and the integration
test to understand how it works.
<?php // use omitted for readability class MyExtension implements XmlNamespaceInterface { const URI = 'https://github.com/genkgo/xsl/tree/master/tests/Stubs/Extension/MyExtension'; public function register(TransformerCollection $transformers, FunctionCollection $functions) { $functions->set( self::URI, new class extends AbstractLazyFunctionMap { public function newFunctionList(): array { return [ 'hello-world' => ['newStringFunction', MyExtension::class], ]; } } ); } public static function helloWorld(Arguments $arguments) { return 'Hello World was called and received ' . count($arguments->unpack()) . ' arguments!'; } } $factory = new ProcessorFactory(new NullCache(), [new MyExtension()]); $processor = $factory->newProcessor();
and then call the function in your style sheet.
<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:my="https://github.com/genkgo/xsl/tree/master/tests/Stubs/Extension/MyExtension"> <xsl:output omit-xml-declaration="yes" /> <xsl:template match="/"> <xsl:value-of select="my:hello-world(1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10)" /> </xsl:template> </xsl:stylesheet>
will yield: Hello World was called and received 20 arguments!.
Caching: transpile once
Depending on the complexity of your stylesheet, the transpiling process could slow down the processing of your
document. Therefore, you probably want to cache the result stylesheet. By adding
psr/simple-cache to your composer.json, you will add the possibility to enable caching.
See the example below, or the integration test
to see how it works.
<?php use Genkgo\Xsl\Cache\ArrayCache; use Genkgo\Xsl\ProcessorFactory; $factory = new ProcessorFactory(new ArrayCache()); $processor = $factory->newProcessor();
Contributing
- Found a bug? Please try to solve it yourself first and issue a pull request. If you are not able to fix it, at least give a clear description what goes wrong. We will have a look when there is time.
- Want to see a feature added, issue a pull request and see what happens. You could also file a bug of the missing feature and we can discuss how to implement it.
genkgo/xsl 适用场景与选型建议
genkgo/xsl 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 99.06k 次下载、GitHub Stars 达 51, 最近一次更新时间为 2015 年 10 月 08 日, 在 PHP 生态内属于活跃度较高的组件。
我们在过去多个企业项目中使用过 genkgo/xsl 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 genkgo/xsl 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
统计信息
- 总下载量: 99.06k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 54
- 点击次数: 18
- 依赖项目数: 5
- 推荐数: 1
其他信息
- 授权协议: Unknown
- 更新时间: 2015-10-08