xsl:import和xsl:include在样式表中不适用于Google Chrome
-
06-07-2019 - |
题
我正在构建一个使用xsl样式表的网站,我正在一个util样式表中构建一个有用函数的小库,其他表单导入
<xsl:import href="util" />
位于每张纸的顶部。这在Google Chrome中不起作用,因为它还不支持xsl:import。有人可以给我写一个样式表,我可以在服务器端运行,它将读取xsl:import行并在发送到客户端之前导入相关的样式表吗?
解决方案
我会做类似以下的事情,它会在样式表服务器端到达Chrome之前将其组合在一起。第一步是因为xsl:import
与使用导入的样式表替换所有场所不同。
- 将所有
xsl:include
替换为<=>(导入优先级不适用于<=>,因此您可能需要更改代码并使用优先级) - 使用下面的服务器端样式表将其合并为一个,然后再提供
- 等几周(可能是几个月)。我已经为Chrome创建了一个修复程序,目前我正在与开发人员团队合作,将修复程序包含在构建中。 醇>
<xsl:template match="node()">
<xsl:copy>
<xsl:copy-of select="@*"/>
<xsl:apply-templates select="node()"/>
</xsl:copy>
</xsl:template>
<xsl:template match="xsl:include">
<!-- you'll probably want to be a bit more restrictive here -->
<xsl:copy-of select="document(@href)/xsl:stylesheet/*" />
</xsl:template>
更新:注意:Chrome中也会出现Chrome错误。
其他提示
您可以使用libxml2和libxslt模块在Python中执行此操作...不是为您完成所有工作,而是从以下内容开始:
import libxml2, libxslt
styledoc = libxml2.parseFile("page.xsl")
style = libxslt.parseStylesheetDoc(styledoc)
doc = libxml2.parseFile("somefile.xml")
result = style.applyStylesheet(doc, None)
然后把东西送回去。
在php中尝试这样的事情:
<?php
$sXml = "<xml>";
$sXml .= "<testtag>hello tester</testtag>";
$sXml .= "</xml>";
# LOAD XML FILE
$XML = new DOMDocument();
$XML->loadXML( $sXml );
# START XSLT
$xslt = new XSLTProcessor();
$XSL = new DOMDocument();
$XSL->load( 'xsl/index.xsl', LIBXML_NOCDATA);
$xslt->importStylesheet( $XSL );
#PRINT
print $xslt->transformToXML( $XML );
?>
http://www.w3.org/TR/xslt#literal -result-element 显示了在编写XSL样式表时如何解决duplicate-xsl-namespace问题,该样式表将现有的XSL样式表转换为扩展了<xsl:import>
的XSL样式表。
但要注意<xsl:include>
和<=>之间的区别。
不隶属于 StackOverflow