html - 从 .HTML 文件链接到 .XSL 文件

标签 html xml xslt

我确信这真的很简单,我只是错过了一些简单的东西,但是......

我有一个主页 (index.html),我想链接到另一个 .xsl 文件页面(以显示一些 xml 数据)。我正在使用这段代码来做到这一点:

<h1><a href="catalogue_overview.xsl">VIEW CATALOGUE</a></h1>

当我单独打开 .xsl 文件(我使用 Dreamweaver)时,它会正常打开并显示数据(来自 xml 文件)。

当我从index.html页面上的链接打开它时,它只显示 <h> 中包含的未格式化文本。和<p>标签等。没有格式化,也没有 xml 数据。

我做错了什么?

我是否需要告诉index.html 文件一些信息,以便它了解.xsl 文件?

我这样做错了吗?

我以同样的方式链接到 PHP 文件,这似乎工作正常。

如果有帮助,我会发布我的代码!

XML 文件

<?xml version="1.0" encoding="utf-8"?>
<?xml-stylesheet type="text/xsl" href="catalogue_overview.xsl"?>

<catalogue>
    <record>
        <catId>001</catId>
        <title>Fungus</title>
        <location>NP</location>
        <photographer>Me</photographer>
        <equipment>Canon EOS 40D</equipment>
        <caption>Small fungus of the genus Fungaroidiae on a log</caption>
        <notes>This is a very rare species of fungus</notes>
        <date>10/8/2012</date>
        <imageUrl>images/IMG_1684.jpg</imageUrl>
    </record>
</catalogue>

XSL 文件

<?xml version="1.0" encoding="UTF-8"?><!-- DWXMLSource="catalogue.xml" -->

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="html" encoding="UTF-8"/>
<xsl:template match="catalogue">
    <html> 
      <head> 
        <title>Photo Catalogue</title>

        <link rel="stylesheet" type="text/css" href="css/style.css"/>

     </head>
     <body>

     <h1 align="center"> Photo Catalogue</h1>
     <h2 align="center"> Catalogue Overview </h2>
     <p align="center"> This is an overview of the photo catalogue. It enables the user to have a quick and easy browse through the images and their information.</p>
     <hr/>

      <xsl:apply-templates/>

     </body>
    </html>

   </xsl:template>

    <xsl:template match="catId">
        <h2> Catalogue ID: <span style="color:2A588F"><xsl:apply-templates/>  </span> </h2>
    </xsl:template>

    <xsl:template match="title">
        <h3> Title: <span style="color:2A588F"><xsl:apply-templates/>  </span> </h3>
    </xsl:template>

    <xsl:template match="location">
        <p> Location: <span style="color:2A588F"><xsl:apply-templates/>  </span> </p>
    </xsl:template>

    <xsl:template match="photographer">
        <p> Photographer: <span style="color:2A588F"><xsl:apply-templates/>  </span> </p>
    </xsl:template>

    <xsl:template match="equipment">
        <p> Equipment: <span style="color:2A588F"><xsl:apply-templates/>  </span> </p>
    </xsl:template> 

    <xsl:template match="caption">
        <p> Caption: <span style="color:2A588F"><xsl:apply-templates/>  </span> </p>
    </xsl:template>

    <xsl:template match="notes">
        <p> Notes: <span style="color:2A588F"><xsl:apply-templates/>  </span> </p>
    </xsl:template>

    <xsl:template match="date">
        <p> Date: <span style="color:2A588F"><xsl:apply-templates/>  </span> </p>
    </xsl:template>

    <xsl:template match="imageUrl">
        <p>Image:<br/><img src="{.}" width="250"/></p>
        <hr/>
    </xsl:template>


 </xsl:stylesheet>

INDEX.HTML 文件

<!doctype html>
<html>
<head>
<meta charset="UTF-8">
<title>Photo Catalogue - HOME</title>

 <link rel="stylesheet" type="text/css" href="css/style.css"/


</head>

<body>

<div class="container">
<div class="content">
    <h1>Photo Catalogue</h1>
    <h2>Welcome to the Photo Catalogue</h2>
    <p>It is intended to be a simple tool to store you favourite photos for easy viewing. It uses XML to store the image details and this is retrieved, displayed and edited using a combination of XSL and PHP.</p>
    <h2>Navigation</h2>
    <p>Select the option you would like below to see its functionality...</p>

    <h1><a href="catalogue_overview.xsl">VIEW CATALOGUE</a></h1>
    <h1><a href="catalogueupdate.php">EDIT CATALOGUE</a></h1>

</div>
</div>
</body>
</html>

希望这有帮助

注意 .php 文件的链接似乎工作正常。我正在运行 XAMPP。

谢谢

最佳答案

您应该链接到应呈现数据的 XML 文件。这意味着在您的 INDEX.HTML 中进行更改

<h1><a href="catalogue_overview.xsl">VIEW CATALOGUE</a></h1>

<h1><a href="catalogue.xml">VIEW CATALOGUE</a></h1>

然后 XML 文件通过

引用 XSL 样式表
<?xml-stylesheet type="text/xsl" href="catalogue_overview.xsl"?>

关于html - 从 .HTML 文件链接到 .XSL 文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19528769/

相关文章:

html - 将图像拖放到网页中并使用 HTML 文件 API 自动调整它们的大小

html 和 css 背景 url 图像压缩

xml - PowerShell ConvertTo-XML 错误

xml - XSL - 复制树,复制一些节点两次并更改第二个副本中的属性

xml - 如何获取 xslt 文件的日期

javascript - 尝试实现 javascript 弹出窗口

php - 如何通过一个提交按钮提交两个值?

java - 对于无效登录,应该在 xml 中传递哪些字符

java - 如何通过*默认*命名空间进行 XmlObject.selectPath()?

xml - 在 XSL 中,如何根据多个属性选择一个值?