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

时间:2013-10-22 21:32:21

标签: 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数据。< / p>

我做错了什么?

我是否需要告诉index.html文件,以便了解.xsl文件?

我这样做错了吗?

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

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

XML FILE

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

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

<!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。

由于

1 个答案:

答案 0 :(得分:2)

您应该链接到应该呈现数据的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"?>