加载样式表

时间:2018-01-31 10:44:21

标签: xml xslt-1.0

我正在尝试在xsl 1.0中使用日期和时间 我尝试遵循此解决方案:Can an XSLT insert the current date?

但我收到一条错误消息:Error loading stylesheet: An unknown error has occurred (805303f4) 它没有告诉我错误在哪里,所以我有点卡住了。

在我的xml文件中,这是我对命名空间的声明:

    <?xml version="1.0" encoding="UTF-8"?>
<!-- xsl stylesheet declaration with xsl namespace:
Namespace tells the xlst processor about which element is to be processed and
which is used for output purpose only
-->
   <xsl:stylesheet version="1.0"
        xmlns:date="http://exslt.org/dates-and-times"
        extension-element-prefixes="date"
        xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
  <xsl:import href="date.xsl" />

这就是我试图获取时间和日期的方式:

<xsl:message terminate="no"> here: <xsl:value-of select="date:date-time()"/> </xsl:message>

我在github上下载了日期和时间包。

我不确定我做错了什么。我没有更改从Github下载的文件中的任何内容

----------------------------更新-------------- 这是整个xml文件:

 <?xml version="1.0" encoding="UTF-8"?>
<!-- xsl stylesheet declaration with xsl namespace:
Namespace tells the xlst processor about which element is to be processed and
which is used for output purpose only
-->
<xsl:stylesheet version="1.0"
        xmlns:date="http://exslt.org/dates-and-times"
        extension-element-prefixes="date"
        xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
  <xsl:import href="date.xsl" />
  <!-- xsl template declaration:
       template tells the xlst processor about the section of xml document which is to be
       formatted. It takes an XPath expression.
       In our case, it is matching document root element and will tell processor to
       process the entire document with this template.
  -->
  <xsl:template match="/">
    <!-- HTML tags
     Used for formatting purpose. Processor will skip them and browser will simply
     render them.
    -->
    <html>
      <body>
    <h2>Students</h2>
    <table border="1">
      <tr bgcolor="#9acd32">
        <th>Roll No</th>
        <th>First Name</th>
        <th>Last Name</th>
        <th>Nick Name</th>
        <th>Marks</th>
      </tr>
      <!-- for-each processing instruction
           Looks for each element matching the XPAth expression
      -->
      <xsl:message terminate="no"> hello </xsl:message>
      <xsl:for-each select="class/student">
        <xsl:sort select="@rollno"/>
        <xsl:if test="marks >= 85">
          <xsl:message terminate="no"> her: <xsl:value-of select="date:date-time()"/> </xsl:message>
        <tr>
          <td>
        <!-- value-of processing instruction
             process the value of the element matching the XPath expression
        -->
        <xsl:value-of select="@rollno"/>
          </td>
          <td><xsl:value-of select="firstname"/></td>
          <td><xsl:value-of select="lastname"/></td>
          <td><xsl:value-of select="nickname"/></td>
          <td><xsl:value-of select="marks"/></td>
        </tr>
        </xsl:if>
      </xsl:for-each>
    </table>
      </body>
    </html>
  </xsl:template>
</xsl:stylesheet>

这是date.xsl文件:

    <?xml version="1.0" encoding="utf-8"?>
<stylesheet xmlns="http://www.w3.org/1999/XSL/Transform" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:date="http://exslt.org/Dates and Times" version="1.0" extension-element-prefixes="date" date:doc="http://www.exslt.org/date">
   <import href="functions/date-time/date.date-time.xsl"/>
   <import href="functions/date/date.date.xsl"/>
   <import href="functions/time/date.time.xsl"/>
   <import href="functions/year/date.year.xsl"/>
   <import href="functions/leap-year/date.leap-year.xsl"/>
   <import href="functions/month-in-year/date.month-in-year.xsl"/>
   <import href="functions/month-name/date.month-name.xsl"/>
   <import href="functions/month-abbreviation/date.month-abbreviation.xsl"/>
   <import href="functions/week-in-year/date.week-in-year.xsl"/>
   <import href="functions/day-in-year/date.day-in-year.xsl"/>
   <import href="functions/day-in-month/date.day-in-month.xsl"/>
   <import href="functions/day-of-week-in-month/date.day-of-week-in-month.xsl"/>
   <import href="functions/day-in-week/date.day-in-week.xsl"/>
   <import href="functions/day-name/date.day-name.xsl"/>
   <import href="functions/day-abbreviation/date.day-abbreviation.xsl"/>
   <import href="functions/hour-in-day/date.hour-in-day.xsl"/>
   <import href="functions/minute-in-hour/date.minute-in-hour.xsl"/>
   <import href="functions/second-in-minute/date.second-in-minute.xsl"/>
   <import href="functions/format-date/date.format-date.xsl"/>
   <import href="functions/parse-date/date.parse-date.xsl"/>
   <import href="functions/week-in-month/date.week-in-month.xsl"/>
   <import href="functions/difference/date.difference.xsl"/>
   <import href="functions/add/date.add.xsl"/>
   <import href="functions/add-duration/date.add-duration.xsl"/>
   <import href="functions/sum/date.sum.xsl"/>
   <import href="functions/seconds/date.seconds.xsl"/>
   <import href="functions/duration/date.duration.xsl"/>
</stylesheet>

1 个答案:

答案 0 :(得分:1)

您的错误明确指出:

  

“加载样式表时出错”。

因此,您的样式表正在导入许多其他样式表。

您需要做的是验证它们的存在并验证路径。至少其中一个必须失败。

相关问题