gpt4 book ai didi

PHP XSLTProcessor 剥离样式属性和标签

转载 作者:行者123 更新时间:2023-11-28 15:07:35 24 4
gpt4 key购买 nike

我有这个 XSLT

<?xml version="1.0" encoding="ISO-8859-1"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output encoding="iso-8859-1" method="html"/>
<xsl:template match="/">
<img src='http://www.acentroservices.it/wp-content/uploads/2018/02/document.jpg' style="border: 1px solid black"/>
<style>
img {
width: 100%
}
</style>
<xsl:if test="count(list/*) &gt; 0">
<h2>Ci sono <xsl:value-of select="count(list/element)" /> elementi!</h2>
</xsl:if>
<xsl:if test="count(list/*) = 0">
<h2>Niente!</h2>
</xsl:if>
</xsl:template>
</xsl:stylesheet>

我用来转换这个 XML

<list><element><id>2</id><uuid>96506f09-eb04-46a2-af86-42fe9c6767ce</uuid><langcode>it</langcode><type>stu_pratica</type><user_id>1</user_id><name>a</name><status>1</status><created>1552053309</created><changed>1552053331</changed><unique_key>a</unique_key><users>admin</users><xml_content></xml_content><default_langcode>1</default_langcode><field_stu_pratica_classe_proc></field_stu_pratica_classe_proc><field_stu_pratica_data_atto></field_stu_pratica_data_atto><field_stu_pratica_data_fine></field_stu_pratica_data_fine><field_stu_pratica_data_inizio></field_stu_pratica_data_inizio><field_stu_pratica_d_protocollo></field_stu_pratica_d_protocollo><field_stu_pratica_ente></field_stu_pratica_ente><field_stu_pratica_esito></field_stu_pratica_esito><field_stu_pratica_indirizzo></field_stu_pratica_indirizzo><field_stu_pratica_lat></field_stu_pratica_lat><field_stu_pratica_lon></field_stu_pratica_lon><field_stu_pratica_nome_proc></field_stu_pratica_nome_proc><field_stu_pratica_num_atto></field_stu_pratica_num_atto><field_stu_pratica_n_protocollo></field_stu_pratica_n_protocollo><field_stu_pratica_primo_int></field_stu_pratica_primo_int><field_stu_pratica_resp_unico></field_stu_pratica_resp_unico><field_stu_pratica_stato></field_stu_pratica_stato><field_stu_pratica_wkid></field_stu_pratica_wkid><field_stu_pratica_x></field_stu_pratica_x><field_stu_pratica_y></field_stu_pratica_y></element></list>

但是,我尝试以任何方式执行转换: - 样式属性从每个可能的标签中剥离 - 样式标签被移除,但它的内容没有

这只发生在 PHP XSLTProcessor 中,我使用的任何在线工具都保留了 CSS 指令。

如何在输出中保留 CSS 指令?为什么这只发生在 PHP XSLTProcessor 而不是在线工具中?

感谢大家的帮助。

编辑:

这是我用来操作转换的 PHP 代码片段:

    $output = new \DOMDocument();
$output->loadXML(utf8_encode($body)); // For the XML

$xslt = new \XSLTProcessor();
$xsl = new \DOMDocument(); // For the XSLT Template

$xsl->load($xslt_path, LIBXML_NOCDATA);
$xsl->formatOutput = TRUE;
$xslt->importStylesheet($xsl);
// Setting some parameters, shouldn't have to do with the css problems i think...
$xslt->setParameter('', 'base_url', $base_url);
$auth_url = Url::fromRoute('stu_botfo.view_authenticated_element', ['bundle' => $bundle, 'id' => ''], ['absolute' => TRUE]);
$xslt->setParameter('', 'view_authenticated_element_link', $auth_url->toString() . '/');
$anon_url = Url::fromRoute('stu_botfo.view_anonymous_element', ['bundle' => $bundle, 'id' => ''], ['absolute' => TRUE]);
$xslt->setParameter('', 'view_anonymous_element_link', $anon_url->toString() . '/');
$xslt->setParameter('', 'map_url', $map_url);
return $xslt->transformToXML($output);

最佳答案

解决了,非常感谢大家。事实证明这不是 XSLTProcessor 错误,而是一些我不知道的 HTML 过滤器发生在渲染过程的后期,我很抱歉之前没有考虑到它。

关于PHP XSLTProcessor 剥离样式属性和标签,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55068253/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com