2016-01-24 59 views
2

我将xhtml转换为xhtml,但需要将xslt样式表作为生成文档的一部分(样式表将包含在<script type"text/template">元素中,我使用的是xsl:namespace-alias指令,这在IE罚款,但在Chrome和Firefox的失败XSLT命名空间别名在Firefox或Chrome中不起作用

下面是相关代码:

<xsl:output doctype-system="about:legacy-compat" omit-xml-declaration="yes" indent="yes" method="html" media-type="application/xhml" encoding="utf-8"/> 
<xsl:namespace-alias stylesheet-prefix="wxsl" result-prefix="xsl" /> 

    <xsl:template match="head"> 
    <!-- Some code omitted for clarity --> 
     <script type="text/template"> 

     <wxsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns="http://www.w3.org/1999/xhtml" 
      xmlns:xhtml="http://www.w3.org/1999/xhtml" xmlns:eli="local"> 

      <wxsl:template select="/"> 
      <wxsl:apply-templates /> 
     </wxsl:template> 


     </wxsl:stylesheet> 


    </script> 

    </xsl:copy> 
    </xsl:template> 

它输出在IE浏览器所需要的转换,但对于Firefox和Chrome的XSLT处理器不用xsl代替wxsl前缀

回答

3

Mozilla不支持它,有一个开放的bug报告https://bugzilla.mozilla.org/show_bug.cgi?id=213996

至于铬,我写一个短的测试情况下具有XHTML输入是http://home.arcor.de/martin.honnen/xslt/test2016012402.xml(只是用head短XHTML样本添加一些XSLT然后用XSLT)和样式表http://home.arcor.de/martin.honnen/xslt/test2016012401.xsl做XHTML到XHTML转化,使用别名保护任何XSLT和XSLT嵌套XHTML结果的要素:

<?xml version="1.0" encoding="UTF-8" ?> 
<xsl:stylesheet 
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform" 
    version="1.0" 
    xmlns:xhtml="http://www.w3.org/1999/xhtml" 
    xmlns:axsl="http://example.com/xsl-alias" 
    xmlns:axhtml="http://example.com/xhtml-alias" 
    exclude-result-prefixes="xhtml axsl axhtml" 
    xmlns="http://www.w3.org/1999/xhtml"> 

<xsl:output method="xml" indent="yes"/> 

<xsl:namespace-alias stylesheet-prefix="axsl" result-prefix="xsl"/> 
<xsl:namespace-alias stylesheet-prefix="axhtml" result-prefix="#default"/> 

<xsl:template match="@* | node()"> 
    <xsl:copy> 
    <xsl:apply-templates select="@* | node()"/> 
    </xsl:copy> 
</xsl:template> 

<xsl:template match="xhtml:head"> 
    <xsl:copy> 
    <xsl:apply-templates select="@* | node()"/> 
    <axsl:stylesheet version="1.0"> 
     <axsl:template match="/"> 
     <axhtml:p>XSLT created paragraph.</axhtml:p> 
     </axsl:template> 
    </axsl:stylesheet> 
    </xsl:copy> 
</xsl:template> 

</xsl:stylesheet> 

和Chrome似乎变换就好了,就检查控制台显示结果的要素是在正确的命名空间:

<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en"> 
<head> 
<title>Test</title> 
<axsl:stylesheet xmlns:axsl="http://www.w3.org/1999/XSL/Transform" version="1.0"><axsl:template match="/"><axhtml:p xmlns:axhtml="http://www.w3.org/1999/xhtml">XSLT created paragraph.</axhtml:p></axsl:template></axsl:stylesheet></head> 
<body> 
<h1>Test</h1> 
</body> 
</html> 

我已经扩展了测试用例以尝试执行嵌入式样式表,并且Edge和Chrome都能够做到这一点,请参阅http://home.arcor.de/martin.honnen/xslt/test2016012407.xml,但由于我无法识别的原因,Chrome无法在DOMContentLoaded事件侦听器I中执行此操作已经成立。但是,使用XSLT插入XSLT似乎没有问题,当我使用该按钮运行带嵌入式样式表的XSLT的脚本时,它在Chrome中正常工作。显然,Firefox缺乏对xsl:namespace-alias的支持,从未发现样式表根元素能够将一些代码提供给XSLTProcessor

相关问题