2

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

输入文件

<?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>

输出截图-

代码的输出

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

4

1 回答 1

2

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

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

到:

  <xsl:output method="html" indent="yes" encoding="UTF-8"/>
于 2012-08-02T03:26:00.210 回答