简体   繁体   English

使用Javascript ID的XSL“ for-each”将不会输出任何内容

[英]XSL “for-each” using Javascript ID won't output anything

So I have an XML, XSL and Javascript file. 所以我有一个XML,XSL和Javascript文件。 I won't copy my entire XML file as it is far too big, but here is the code in question: 我不会复制整个XML文件,因为它太大了,但这是有问题的代码:

<courses>
  <course>
    <c_info>
      <c_code>U65</c_code>
      <c_title>Computer Science</c_title>
    </c_info>

I then have a Javascript file that has these parameters 然后,我有一个包含这些参数的Javascript文件

function transform(message) {
transformXML("xml_courseinfo.xml", "course_menu.xsl", "main_body", "sid", message)
}

Then in my XSL file, I have these lines: 然后在我的XSL文件中,这些行如下:

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0"
                xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
  <xsl:param name="sid" />

  <xsl:template match="/">
    <html>
      <head> 
        <meta http-equiv="content-type" content="text/html; charset=utf-8" /> 
        <title>Cross Browser Compatible Parameter Passing</title>

        <!-- javascript processor for loading the xslts with the xml-->
        <script language="javascript" type="text/javascript" src="processxml.js"></script>
      </head>
      <body>
        <div id="main_body">
          <h1>Course Main Menu</h1>
          <xsl:for-each select="courses/course/c_info[c_code=$sid]"> 
            <Strong>Course Name:</Strong> <xsl:value-of select="c_title"/> <hr /> 
          </xsl:for-each> 
        </div>
      </body>  
    </html>    
  </xsl:template>

</xsl:stylesheet>

Nothing displays at all, I am giving it the correct path and the Course code ( c_code ) is unique, can anyone help me understand the problem here? 什么都没显示,我给它正确的路径,并且课程代码( c_code )是唯一的,有人可以帮助我了解这里的问题吗?

Thanks in advance guys! 在此先感谢大家!

If nothing is displaying, then either the XSLT isn't executing at all, or you're supplying the wrong value of $sid. 如果什么也没显示,则说明XSLT根本没有执行,或者您提供了错误的$ sid值。 You can easily discover which of these is true by having the stylesheet output some constant text, eg 您可以通过让样式表输出一些常量文本来轻松发现其中哪一个是正确的,例如

<h1>Transformation output for sid=<xsl:value-of select="$sid"/></h1>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM