在html页面上显示xsl文件

时间:2011-12-17 04:05:57

标签: html xml xslt

我很难在我的网页上以xsl形式显示我的xml文件 这是网页euroFixtures

   <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org   /TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<!-- TemplateBeginEditable name="doctitle" -->
<title>Fixtures</title>
<!-- TemplateEndEditable -->
<!-- TemplateBeginEditable name="head" -->
<!-- TemplateEndEditable -->
<link href="oneColElsCtr.css" rel="stylesheet" type="text/css" />
</head>

<body class="oneColElsCtr">
<div id="header">
<h1><a href="home.html"><img src="euro2012.jpg" alt="" width="713" height="146" /></a></h1>
  <div id="links" align="middle">
    <table width="711" height="59" border="1">
      <!-- TemplateBeginEditable name="EditRegion4" -->
      <tr>
        <td width="177"><a href="euroHome.html">News</a></td>
        <td width="177"><a href="euroWeather.html"> Weather</a></td>
        <td width="160"><a href="euroCurrency.html">Currency Converter</a></td>
        <td width="169"><a href="euroFixtures.html">Fixtures</a></td>
      </tr>
      <!-- TemplateEndEditable -->
    </table>
  </div>

</div>
<div id="container">
  <div id="mainContent" ><!-- TemplateBeginEditable name="hujhjhj" -->


<frameset columns="45%,55%" cols="*,*" >
     <frame src="fixtures.xml"  frameborder="1"/>
    <frame src="frame.html" frameborder="1"/>

</frameset> 


  <!-- TemplateEndEditable -->
  <!-- end #mainContent --></div>
<!-- end #container --></div>
</body>
</html>

这里是xml文件夹具

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


<fixtures>
    <fixture>   
        <match>Ireland vs. Poland</match>
        <date>05-06-12</date>
        <ground>Apatov</ground>
        <group>A</group>
    </fixture>

    <fixture>   
        <match>France vs. Germany</match>
        <date>05-06-012</date>
        <ground>Krakow</ground>
        <group>A</group>
    </fixture>

    <fixture>   
        <match>Italy vs. Spain</match>
        <date>06-06-12</date>
        <ground>Kiev</ground>
        <group>B</group>
    </fixture>

    <fixture>   
        <match>Portugal vs. Croatia</match>
        <date>06-06-12</date>
        <ground>Warsaw</ground>
        <group>B</group>
    </fixture>

    <fixture>   
        <match>Austria vs. Greece</match>
        <date>07-06-12</date>
        <ground>Flam</ground>
        <group>C</group>
    </fixture>

    <fixture>   
        <match>Lithuania vs. Latvia</match>
        <date>07-06-12</date>
        <ground>Gameu</ground>
        <group>C</group>
    </fixture>

    <fixture>   
        <match>England vs. Sweden</match>
        <date>08-06-12</date>
        <ground>Hanaas</ground>
        <group>D</group>
    </fixture>

    <fixture>   
        <match>Norway vs. Denmark</match>
        <date>08-06-12</date>
        <ground>Olam</ground>
        <group>D</group>
    </fixture>

</fixtures> 

这里是xsl文件夹具

    <?xml version="1.0"?>
<xsl:stylesheet 
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    version="1.0">


<xsl:template match="/">
<html><head> <title>Output document</title></head> 
<body><xsl:apply-templates /></body></html>
</xsl:template>     

<xsl:template match="fixture">

<table width="100%" border="2">
<tr bgcolor="silver"><td>match</td><td>date</td><td>ground</td><td>group</td></tr>
    <xsl:for-each select="fixture">
    <tr>
        <td><xsl:value-of select="match"/></td>
        <td><xsl:sort select="date"
                    order="ascending" data-type="text"/></td>
        <td><xsl:value-of select="ground"/></td>
        <td><xsl:value-of select="group"/></td>
    </tr>
    </xsl:for-each>
    </table>
</xsl:template>

</xsl:stylesheet>

我不认为这很重要,但这里是html文件框架

 <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>

<head>
<meta content="text/html; charset=utf-8" http-equiv="Content-Type">
<title>Untitled 2</title>
</head>

<body>
frame_a.htm
</body>

</html>

。我一直在尝试和尝试,但我不能让这件事工作。 任何人都可以对我表示高度赞赏

1 个答案:

答案 0 :(得分:1)

此代码包含明显的语法错误

    <xsl:for-each select="fixture">
    <tr>
        <td><xsl:value-of select="match"/></td>
        <td><xsl:sort select="date"
                    order="ascending" data-type="text"/></td>
        <td><xsl:value-of select="ground"/></td>
        <td><xsl:value-of select="group"/></td>
    </tr>
    </xsl:for-each>

xsl:sort只能是xsl:for-each的孩子或xsl:apply-templates的孩子。这是td的孩子。

存在第二个语义错误

<xsl:template match="fixture">

<table width="100%" border="2">
<tr bgcolor="silver"><td>match</td><td>date</td><td>ground</td><td>group</td></tr>
    <xsl:for-each select="fixture">

上面xsl:for-each的正文将不会应用于任何节点,因为当前节点(fixture)没有任何名为fixture的子节点。

您可能需要

<xsl:template match="fixtures">

完整更正的代码为

<xsl:stylesheet
        xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
        version="1.0">


    <xsl:template match="/">
    <html><head> <title>Output document</title></head>
    <body><xsl:apply-templates /></body></html>
    </xsl:template>

    <xsl:template match="fixtures">

    <table width="100%" border="2">
    <tr bgcolor="silver"><td>match</td><td>date</td><td>ground</td><td>group</td></tr>
        <xsl:for-each select="fixture">
             <xsl:sort select="date"
                        order="ascending" data-type="text"/>        <tr>
            <td><xsl:value-of select="date"/></td>
            <td><xsl:value-of select="match"/></td>
            <td><xsl:value-of select="ground"/></td>
            <td><xsl:value-of select="group"/></td>
        </tr>
        </xsl:for-each>
        </table>
    </xsl:template>

</xsl:stylesheet>

并应用于提供的XML文档

<html>
   <head>
      <meta http-equiv="Content-Type" content="text/html; charset=utf-8">

      <title>Output document</title>
   </head>
   <body>
      <table width="100%" border="2">
         <tr bgcolor="silver">
            <td>match</td>
            <td>date</td>
            <td>ground</td>
            <td>group</td>
         </tr>
         <tr>
            <td>France vs. Germany</td>
            <td>05-06-012</td>
            <td>Krakow</td>
            <td>A</td>
         </tr>
         <tr>
            <td>Ireland vs. Poland</td>
            <td>05-06-12</td>
            <td>Apatov</td>
            <td>A</td>
         </tr>
         <tr>
            <td>Italy vs. Spain</td>
            <td>06-06-12</td>
            <td>Kiev</td>
            <td>B</td>
         </tr>
         <tr>
            <td>Portugal vs. Croatia</td>
            <td>06-06-12</td>
            <td>Warsaw</td>
            <td>B</td>
         </tr>
         <tr>
            <td>Austria vs. Greece</td>
            <td>07-06-12</td>
            <td>Flam</td>
            <td>C</td>
         </tr>
         <tr>
            <td>Lithuania vs. Latvia</td>
            <td>07-06-12</td>
            <td>Gameu</td>
            <td>C</td>
         </tr>
         <tr>
            <td>England vs. Sweden</td>
            <td>08-06-12</td>
            <td>Hanaas</td>
            <td>D</td>
         </tr>
         <tr>
            <td>Norway vs. Denmark</td>
            <td>08-06-12</td>
            <td>Olam</td>
            <td>D</td>
         </tr>
      </table>
   </body>
</html>
相关问题