在 html 页面上显示 xsl 文件

发布于 2024-12-21 18:58:34 字数 5391 浏览 0 评论 0原文

我在网页上以 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>

。我一直在尝试,但我无法让这件事发挥作用。 谁能帮助我,我将不胜感激

im having a lot of trouble truing to display the my xml file in xsl form on my web page
here is the web page 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>

here is the xml file fixtures

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

and here is the xsl file fixtures

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

and i dont think that it is important but here is the html file frame

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

. i have been trying and trying but i cannot get this thing to work.
Can anyone hepl me it would be highly appreciated

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

酷到爆炸 2024-12-28 18:58:34

这段代码包含一个明显的语法错误

    <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的子级:应用模板。这里它是 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>

This code contains an obvious syntactic error:

    <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 can only be child of xsl:for-each or child of xsl:apply-templates. Here it is child of td.

There is a second, semantic error:

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

The body of xsl:for-each above will not be applied to any node, because the current node (fixture) doesn't have any children named fixture.

You probably want:

<xsl:template match="fixtures">

The complete corrected code is:

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

and when applied to the provided XML document:

<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>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文