2012-08-02 33 views
2

我已经用XSLT将XHTML文件转换为其他XHTML文件。它已成功转换并且输出看起来与所需的相同,但转换后的输出在浏览器中打开时并不显示任何内容,并且在Dreamweaver中,所有标记的颜色也始终为黑色,而不是通常的多标记(标记为</head>) -colors。找到我的输出附加的屏幕截图以及我的代码。请帮我解决这个问题。 感谢你!使用XSLT转换XHTML代码时出错

输入文件

<?xml version="1.0" encoding="utf-8"?> 
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" 
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> 

<html xmlns="http://www.w3.org/1999/xhtml"> 
<head> 
    <meta name="generator" content= 
    "HTML Tidy for Linux/x86 (vers 11 February 2007), see www.w3.org" /> 
    <meta http-equiv="Content-type" content="text/html; charset=us-ascii" /> 
    <script type="t/j" src="abc.js"> 
</script> 
    <title></title> 
</head> 
<body> 
    <div id="o"> 
    <div id="m"> 
     <div id="nD"> 
     <p id="nT">Part 1</p> 
     </div> 

     <div class="TF" id="123"> 
     <script type="t/j" src="xyz.js"></script> 
     <script type="t/j" src="abc.js"></script> 

     <div class="iD"> 
      <img alt="" src="ic.gif" /> <span class="iDe">ABC</span><br /> 

      <div class="iDev"> 
      <div id="ta12" class="bl" style="dis:bl"></div> 

      <div class="q"> 
       <div id="t0b" class="block"> 
       1<span style="color">TEXT1</span> 
       </div><br /> 
       T <input type="radio" name="o0" id="t0" onclick="getFeedback()" /> 
       F <input type="radio" name="op0" id="f0" onclick="getFeedback()" /> 

       <div id="18">C</div> 
       <div id="sfb"></div> 
      </div><br /> 
      </div> 
     </div> 
     </div> 
    </div> 
    </div> 
</body> 
</html> 

我的XSLT:

<?xml version="1.0"?> 
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:xhtml="http://www.w3.org/1999/xhtml" xmlns="http://www.w3.org/1999/xhtml" version="1.0" exclude-result-prefixes="xhtml"> 
    <xsl:output method="xml" indent="yes" encoding="UTF-8"/> 
    <xsl:strip-space elements="*"/> 
    <xsl:template match="@*|node()"> 
    <xsl:copy> 
     <xsl:apply-templates select="@*|node()"/> 
    </xsl:copy> 
    </xsl:template> 
    <xsl:template match="xhtml:body"> 
    <script type="t/j" src="pqr.js" xml:space="preserve"/> 
    <script type="t/j" src="stu.js" xml:space="preserve"/> 
    <body onload="loadPage()" onunload="unloadPage()"> 
     <xsl:apply-templates select="@*|node()"/> 
    </body> 
    </xsl:template> 
    <xsl:template match="xhtml:div[@id='123']/@*"> 
    <xsl:attribute name="class">QT</xsl:attribute> 
    <xsl:attribute name="id">456</xsl:attribute> 
    </xsl:template> 
    <xsl:template match="xhtml:script[@src='xyz.js']"> 
    <xsl:copy> 
     <xsl:apply-templates select="@*[not(@src)]"/> 
     <xsl:attribute name="src">lmn.js</xsl:attribute> 
     <xsl:apply-templates select="node()"/> 
    </xsl:copy> 
    </xsl:template> 
    <xsl:template match="xhtml:body//xhtml:script[@src='abc.js']"/> 
    <xsl:template match="@onclick"/> 
    <xsl:template match="xhtml:body//xhtml:div[@id='19']"/> 
    <xsl:template match="xhtml:div[@class='iD']"> 
    <form name="form"> 
     <xsl:copy> 
     <xsl:apply-templates select="@*|node()"/> 
     </xsl:copy> 
     <xsl:apply-templates select="following-sibling::xhtml:div[1]" mode="inside-form"/> 
     <br/> 
     <input type="submit" name="sub" value="Done"/> 
    </form> 
    </xsl:template> 
    <xsl:template match="xhtml:div[@id='ta12']"> 
    <xsl:copy> 
     <xsl:attribute name="class">pa</xsl:attribute> 
     <xsl:attribute name="value">10</xsl:attribute> 
    </xsl:copy> 
    </xsl:template> 
    <xsl:template match="xhtml:div[@id='t0b']"> 
    <xsl:copy> 
     <xsl:copy-of select="@*"/> 
     <xsl:attribute name="id">ta0b8</xsl:attribute> 
     <xsl:apply-templates select="node()"/> 
    </xsl:copy> 
    </xsl:template> 
    <xsl:template match="xhtml:input[@name='o0']"> 
    <xsl:copy> 
     <xsl:copy-of select="@*"/> 
     <xsl:attribute name="name">key0b8</xsl:attribute> 
     <xsl:attribute name="class">block</xsl:attribute> 
     <xsl:apply-templates select="node()"/> 
    </xsl:copy> 
    </xsl:template> 
    <xsl:template match="xhtml:input[@name='op0']"> 
    <xsl:copy> 
     <xsl:copy-of select="@*"/> 
     <xsl:attribute name="name">key0b8</xsl:attribute> 
     <xsl:attribute name="class">block</xsl:attribute> 
     <xsl:apply-templates select="node()"/> 
    </xsl:copy> 
    </xsl:template> 
</xsl:stylesheet> 

输出Screenshot-

Output of the code

请在上图中看到所有标签从关闭头标签开始都是黑色的,并且设计部分也是空白的。

回答

2

我得到的输出,如果我改变:

<xsl:output method="xml" indent="yes" encoding="UTF-8"/> 

到:

<xsl:output method="html" indent="yes" encoding="UTF-8"/> 
+0

太谢谢你了!它的作品完美.. :) – RahulD 2012-08-02 03:57:30

+0

@rahuldwivedi:不客气。 – 2012-08-02 03:57:50