【问题标题】:Nothing appears when I apply an XSLT stylesheet to an XML file当我将 XSLT 样式表应用到 XML 文件时,什么也没有出现
【发布时间】:2015-03-17 20:03:50
【问题描述】:

我正在做一个简单的学习 XSLT 语言的教育项目,但是当我尝试将样式表应用于 XML 文件时,转换返回给我一个空白 HTML 页面,您认为是链接代码中的错误之后? (使用 XMLSpear 作为编辑器)

这里是xml代码

<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE TEI SYSTEM "teilite.dtd">
<?xml-stylesheet type="text/xsl" href="stile.xsl"?>
<TEI xmlns="http://www.tei-c.org/ns/1.0">
    <teiHeader>
        <fileDesc>
            <titleStmt>
                <title>Ettore Fieramosca o la disfida di Barletta : racconto</title>
                <respStmt>
                    <resp>Conversione TEI P5 a cura di</resp>
                    <name>V. Caproni</name>
                </respStmt>
            </titleStmt>
            <publicationStmt>
                <publisher>Exercise Press</publisher>
                <date>20-10-2014</date>
            </publicationStmt>
            <sourceDesc>
                <bibl>
                    <title>title</title>
                    <author>author</author>
                    <publisher>publisher</publisher>
                    <date>1856</date>
                    <from>title of the book</from>
                    <licence>link to the licence</licence>
                </bibl>
            </sourceDesc>
        </fileDesc>
        <encodingDesc>
            <styleDefDecl scheme="css"/>
            <tagsDecl>
                <rendition xml:id="blue">color: blue;</rendition>
                <rendition xml:id="red">color: red;</rendition> 
            </tagsDecl>
        </encodingDesc> 
    </teiHeader>
    <text>
       <front>
          <p>author name</p>
            <p>title</p>
       </front>
        <epigraph>
           <p>epigraph n1</p>
        </epigraph>
        <epigraph>
           epigraph n2
        </epigraph>
        <body>
           <div type="Capitolo" xml:id="cap1">
              <h2>Capitolo I</h2>
            <p rendition="#blue">
        sometext
        </p>
    </div>
</body>
</text>
</TEI>

这是xls代码

<xsl:stylesheet
  xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  version="1.0"
  xmlns:tei="http://www.tei-c.org/ns/1.0"
  xmlns="http://www.w3.org/1999/xhtml">
<xsl:output method="html" indent="yes" omit-xml-declaration="yes"/>

<xsl:template match="tei:TEI">
  <html>
   <head>
    <title>Ettore Fieramosca o La Disfida di Barletta</title>
    <link href="stile.css" rel="stylesheet" type="text/css"/>
   </head>
<body>
   <xsl:apply-templates/>
   </body>
  </html>
</xsl:template>

<xsl:template match="tei:teiHeader">
  <br/>
  <h1>Informazioni sul documento</h1>
  <br/>
  <xsl:apply-templates/>
 </xsl:template>


<xsl:template match="tei:front">
    <br/>
    <h1>Frontespizio e prefazione</h1> <br/>
<xsl:apply-templates/>
</xsl:template>

 <xsl:template match="tei:front">
<br/>
<h1>Frontespizio e prefazione</h1> <br/>
<xsl:apply-templates/>
</xsl:template>


</xsl:stylesheet>

编辑 内置浏览器或 Firefox 或 chrome 中均未显示任何内容

编辑 2 根据内置的 xsl 和 xml 验证器,文档格式都很好

【问题讨论】:

  • 哪个浏览器?出于安全原因,Chrome 不允许多个本地文件进行通信。尝试使用 firefox 并检查“空白页”,如果没有错误,您可能会看到 xml 已转换。
  • 那么问题是在 XMLSpear 中运行还是在浏览器中查看时出现的?是否需要 XML 文件使用的 DTD?
  • 发布更新“内置浏览器、firefox 或 chrome in 中均未显示任何内容”
  • 似乎在 Visual Studio 中对我来说工作正常。请尝试删除 DTD,看看是否有帮助。
  • @JLRishe 谢谢,去掉dtd解决了问题,你知道原因吗?

标签: xml xslt


【解决方案1】:

正如 cmets 中所讨论的,源 XML 中存在的 DTD 导致了此故障。通常不需要 DTD 来通过 XSLT 转换 XML,因此除非有特定原因需要 DTD,否则您可以将其从 XML 中删除。

很可能,DTD 与 XML 不在同一个文件夹中,当浏览器尝试加载它时,它并不存在,因此浏览器根本拒绝处理 XML。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-09-23
    • 2023-03-24
    • 2021-03-24
    • 1970-01-01
    • 1970-01-01
    • 2015-04-20
    相关资源
    最近更新 更多