我正在使用撒克逊人JS,并且在Chrome中遇到编译/观看的问题

发布于 2025-02-03 10:20:17 字数 4174 浏览 2 评论 0原文

XSL将编译到.sef文件中,但是在检查Firefox时,我将获得“转换失败:错误xpdy0002在第34行pocut。(dot)不存在”。

据我的知识非常有限,这个撒克逊人的错误是由于没有使模板成为主要模板,那么为什么会在for-each上绊倒呢?

XSL文件

<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet 
  xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  xmlns:xs="http://www.w3.org/2001/XMLSchema"
  xmlns:ixsl="http://saxonica.com/ns/interactiveXSLT"
  xmlns:saxon="http://saxon.sf.net/"
  xmlns:js="http://saxonica.com/ns/globalJS"
  xmlns:fn="http://www.w3.org/2005/xpath-functions"
  xmlns:math="http://www.w3.org/2005/xpath-functions/math"
  xmlns:map="http://www.w3.org/2005/xpath-functions/map"
  xmlns:array="http://www.w3.org/2005/xpath-functions/array"
    exclude-result-prefixes="#all"
    version="2.0">
  <xsl:mode on-no-match="shallow-copy"/>
  <xsl:output method="html" encoding="utf-8" indent="yes" />
  <xsl:template name="xsl:initial-template" match="/">
    <h1 align="center">Pack Schedule</h1>
    <table border="3" align="center" >
      <tr>
        <th>Complete by</th>
        <th>How Many Days Past</th>
      </tr>
      <xsl:for-each select="order/job">
        <xsl:sort select="Complete_by"/>
        <xsl:variable name="dueDateOP" select="xs:date(Complete_by)"/>
        <xsl:variable name="daysOut" select="(current-date() - $dueDateOP)"/> 
        <xsl:variable name="daysOutDated" select="fn:days-from-duration($daysOut)"/>              
        <xsl:choose>
          <xsl:when test="$daysOutDated &gt;= 14">
            <tr bgcolor="red">
              <td><xsl:value-of select="Complete_by"/></td>
              <td><xsl:value-of select="$daysOutDated" /></td>
            </tr>
          </xsl:when>
          <xsl:otherwise>
            <tr bgcolor="yellow">
              <td><xsl:value-of select="Complete_by"/></td>
              <td><xsl:value-of select="$daysOutDated" /></td>
            </tr>
          </xsl:otherwise>
        </xsl:choose> 
      </xsl:for-each>
    </table>
  </xsl:template>
</xsl:stylesheet>

XML

<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" href="pack3.xsl" ?>
<order>
  <job> 
    <Complete_by> 2022-05-17</Complete_by>
    <Comments> </Comments>
    <Updated> 5/26/2022 10:05:31 AM</Updated>
  </job> 
  <job> 
    <Complete_by> 2022-05-27</Complete_by>>
    <Comments> </Comments>
    <Updated> 5/26/2022 10:05:31 AM</Updated>
  </job> 
  <job> 
    <Complete_by> 2022-05-24</Complete_by>
    <Comments> </Comments>
    <Updated> 5/26/2022 10:05:31 AM</Updated>
  </job> 
    <job> 
    <Complete_by> 2022-06-17</Complete_by>
    <Comments> </Comments>
    <Updated> 5/26/2022 10:05:31 AM</Updated>
  </job> 
    <job> 
    <Complete_by> 2022-04-17</Complete_by>
    <Comments> </Comments>
    <Updated> 5/26/2022 10:05:31 AM</Updated>
  </job> 
</order>

HTML

<!DOCTYPE html>
<html lang="en">
  <head>
    
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    
    <title>Days spent</title>
    
    <script type="text/javascript" src="saxon-js/SaxonJS2.rt.js"></script>
    <script type="text/javascript">
      window.onload = function() {
        SaxonJS.transform({
          stylesheetLocation: "pack3.sef.json"
        }, "async");
      }  
    </script>    
    <script>console.log(SaxonJS.getProcessorInfo())</script>
  </head>
  <body id="body">
    <h1>There is an error</h1>
  </body>
</html>

The XSL will compile to the .sef file but in the inspect of firefox I get "Transformation failure: Error XPDY0002 at line #34 Focus for . (dot) is absent".

From my very limited knowledge, this saxon error is from not making a template the main template so why would it be tripped on a for-each?

The XSL file

<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet 
  xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  xmlns:xs="http://www.w3.org/2001/XMLSchema"
  xmlns:ixsl="http://saxonica.com/ns/interactiveXSLT"
  xmlns:saxon="http://saxon.sf.net/"
  xmlns:js="http://saxonica.com/ns/globalJS"
  xmlns:fn="http://www.w3.org/2005/xpath-functions"
  xmlns:math="http://www.w3.org/2005/xpath-functions/math"
  xmlns:map="http://www.w3.org/2005/xpath-functions/map"
  xmlns:array="http://www.w3.org/2005/xpath-functions/array"
    exclude-result-prefixes="#all"
    version="2.0">
  <xsl:mode on-no-match="shallow-copy"/>
  <xsl:output method="html" encoding="utf-8" indent="yes" />
  <xsl:template name="xsl:initial-template" match="/">
    <h1 align="center">Pack Schedule</h1>
    <table border="3" align="center" >
      <tr>
        <th>Complete by</th>
        <th>How Many Days Past</th>
      </tr>
      <xsl:for-each select="order/job">
        <xsl:sort select="Complete_by"/>
        <xsl:variable name="dueDateOP" select="xs:date(Complete_by)"/>
        <xsl:variable name="daysOut" select="(current-date() - $dueDateOP)"/> 
        <xsl:variable name="daysOutDated" select="fn:days-from-duration($daysOut)"/>              
        <xsl:choose>
          <xsl:when test="$daysOutDated >= 14">
            <tr bgcolor="red">
              <td><xsl:value-of select="Complete_by"/></td>
              <td><xsl:value-of select="$daysOutDated" /></td>
            </tr>
          </xsl:when>
          <xsl:otherwise>
            <tr bgcolor="yellow">
              <td><xsl:value-of select="Complete_by"/></td>
              <td><xsl:value-of select="$daysOutDated" /></td>
            </tr>
          </xsl:otherwise>
        </xsl:choose> 
      </xsl:for-each>
    </table>
  </xsl:template>
</xsl:stylesheet>

The XML

<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" href="pack3.xsl" ?>
<order>
  <job> 
    <Complete_by> 2022-05-17</Complete_by>
    <Comments> </Comments>
    <Updated> 5/26/2022 10:05:31 AM</Updated>
  </job> 
  <job> 
    <Complete_by> 2022-05-27</Complete_by>>
    <Comments> </Comments>
    <Updated> 5/26/2022 10:05:31 AM</Updated>
  </job> 
  <job> 
    <Complete_by> 2022-05-24</Complete_by>
    <Comments> </Comments>
    <Updated> 5/26/2022 10:05:31 AM</Updated>
  </job> 
    <job> 
    <Complete_by> 2022-06-17</Complete_by>
    <Comments> </Comments>
    <Updated> 5/26/2022 10:05:31 AM</Updated>
  </job> 
    <job> 
    <Complete_by> 2022-04-17</Complete_by>
    <Comments> </Comments>
    <Updated> 5/26/2022 10:05:31 AM</Updated>
  </job> 
</order>

HTML

<!DOCTYPE html>
<html lang="en">
  <head>
    
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    
    <title>Days spent</title>
    
    <script type="text/javascript" src="saxon-js/SaxonJS2.rt.js"></script>
    <script type="text/javascript">
      window.onload = function() {
        SaxonJS.transform({
          stylesheetLocation: "pack3.sef.json"
        }, "async");
      }  
    </script>    
    <script>console.log(SaxonJS.getProcessorInfo())</script>
  </head>
  <body id="body">
    <h1>There is an error</h1>
  </body>
</html>

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

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

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文