racztiborzoltan/stex
Composer 安装命令:
composer require racztiborzoltan/stex
包简介
Simple Template Xslt
README 文档
README
- extended from PHP built in \XSLTProcessor class.
- support all \XSLTProcessor features
- PSR-11 container support
- some new small syntax
PSR-11 Container support
<!-- new xslt function syntax -->
this:container(...)
this:container('CONTAINER_SCALAR_ITEM_NAME')
this:container('CONTAINER_FUNCTION_ITEM_NAME', 'PARAMETER_1', 'PARAMETER_2', '...')
this:container('CONTAINER_OBJECT_ITEM_NAME', 'METHOD_NAME', 'FIRST_PARAMETER', 'SECOND_PARAMETER', '...')
Usage example:
<xsl:value-of select="this:container('scalar_item_name')/> <xsl:value-of select="this:container('function_item_name', 'foobar', 123)/> <xsl:value-of select="this:container('object_item_name', 'method_name', 'arg_1', 'arg2')/>
This example code works only with \Stex\StexXsltProcessor class!
$xml = <<<EOB
<allusers>
<user>
<uid>bob</uid>
</user>
<user>
<uid>joe</uid>
</user>
</allusers>
EOB;
$xsl = <<<EOB
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:php="http://php.net/xsl">
<xsl:output method="html" encoding="utf-8" indent="yes"/>
<xsl:template match="allusers">
<html><body>
<h2>Users</h2>
<table border="1" cellspacing="0" cellpadding="5">
<tr>
<th>
Name <br />(php:function)
</th>
<th>
foobar text <br />(this:container)
</th>
<th>
formatted datetime <br />(this:container)
</th>
</tr>
<xsl:for-each select="user">
<tr>
<td>
<xsl:value-of
select="php:function('ucfirst',string(uid))"/>
</td>
<td>
<xsl:value-of
select="this:container('foo')"/>
</td>
<td>
<xsl:value-of
select="this:container('datetime', 'format', 'Y-m-d')"/>
</td>
</tr>
</xsl:for-each>
</table>
</body></html>
</xsl:template>
</xsl:stylesheet>
EOB;
$xmldoc = new \DOMDocument();
$xmldoc->loadXML($xml);
$xsldoc = new \DOMDocument();
$xsldoc->loadXML($xsl);
// define container and container items
$container = new Container();
$container->add('foo', 'bar');
$container->add('datetime', function(){
return new \DateTime();
});
$proc = new StexXsltProcessor();
$proc->setContainer($container);
$proc->registerPHPFunctions();
$proc->importStyleSheet($xsldoc);
echo $proc->transformToXML($xmldoc);
CSS Select Example
$xml = <<<EOB
<!DOCTYPE html>
<html lang="en">
<head><title>stex css select demo</title></head>
<body>
<section class="first">
<header>
<h1 class="title">First section title</h1>
</header>
<article>Lorem ipsum...</article>
</section>
<section class="second">
<header>
<h1 class="title">Second section title</h1>
</header>
<article>Dolor it...</article>
</section>
</body>
</html>
EOB;
$xsl = <<<EOB
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="html" encoding="utf-8" indent="yes"/>
<xsl:template match="/">
<xsl:value-of select="@css['section.first .title']"></xsl:value-of>
<xsl:text>
</xsl:text>
<xsl:value-of select="@css['section.second .title']"></xsl:value-of>
<xsl:text>
</xsl:text>
<xsl:for-each select="@css['section article']">
<xsl:value-of select="."></xsl:value-of>
<xsl:text>
</xsl:text>
</xsl:for-each>
</xsl:template>
</xsl:stylesheet>
EOB;
$xmldoc = new \DOMDocument();
$xmldoc->loadXML($xml);
$xsldoc = new \DOMDocument();
$xsldoc->loadXML($xsl);
$proc = new StexXsltProcessor();
$proc->registerPHPFunctions();
$proc->importStyleSheet($xsldoc);
echo $proc->transformToXML($xmldoc);
other examples
in examples directory!
racztiborzoltan/stex 适用场景与选型建议
racztiborzoltan/stex 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 14 次下载、GitHub Stars 达 0, 最近一次更新时间为 2018 年 07 月 13 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「xslt」 「PSR-11」 「xslt-transform」 「xslt-processor」 「container-support」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 racztiborzoltan/stex 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 racztiborzoltan/stex 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 racztiborzoltan/stex 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Symfony 2 / 3 Apache FOP Bundle
Facilitates the routine step of bootstrapping PHP applications.
PSR-11 Aura.DI container configurator for Laminas and Mezzio applications. Drop-in replacement for the archived laminas/laminas-auradi-config with PHP 8.4 and 8.5 support.
Symfony compiler pass that allows to use service providers as defined in container-interop/service-provider
Extends TYPO3 with a new content object XSLT for flexible XML transformations
Routing, logging, templating… small code for big texts
统计信息
- 总下载量: 14
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 10
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2018-07-13