简体   繁体   中英

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

So I have an XML, XSL and Javascript file. I won't copy my entire XML file as it is far too big, but here is the code in question:

<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

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

Then in my XSL file, I have these lines:

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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