2016-01-24 64 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

相關問題