2011-12-17 121 views
1
有很多的麻煩修整,以顯示我的網頁 這裏開始XSL形式我的XML文件是網頁

IM euroFixtureshtml頁面上顯示的XSL文件

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

和I T不認爲這很重要,但這裏是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> 

。我一直在努力嘗試,但我無法得到這個東西的工作。 誰能HEPL我將不勝感激

回答

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> 
+0

我修復了錯誤,但我仍然遇到問題 – user1085773 2011-12-17 04:27:23