简体   繁体   中英

Using <xsl: param> on <xsl: for-each> doesn't work

I'm a student on a vocational course and I was told to make a HTML webpage out of a XML. I need tu use JavaScript with a XSLProcessor, as well as an XSL. The problem comes when I need to use the xsl parameter on the for each. The puropose is to make a table with XML info depending of which parameter the XSL gets. Here's my 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="ciclo"/>
<xsl:template match="/">
<table>
  <xsl:for-each select="/ies/modulos/modulo/[ciclo=$ciclo]">
      <tr>
        <td><xsl:value-of select="./nombre"/></td>
        <td><xsl:value-of select="./horasSemanales"/></td>
      </tr>
  </xsl:for-each>
</table>
</xsl:template>
</xsl:stylesheet>

Here's a fragment of the XML I'm using :

<ies>
 <modulos>
    <modulo id="0221">
        <nombre>Montaje y Mantenimiento de equipos</nombre>
        <curso>1</curso>
        <horasSemanales>7</horasSemanales>
        <ciclo>SMR</ciclo>
    </modulo>
    <modulo id="0225">
        <nombre>Redes locales</nombre>
        <curso>1</curso>
        <horasSemanales>7</horasSemanales>
        <ciclo>ASIR</ciclo>
    </modulo>
</modulos>
</ies>

The JavaScript function for loading the parameter into the XSL works fine, is I check it with xslProcessor.getParameter() and all the HTML id's are correct.

Thank in advance for your time to help a beginner. :P

Use

select="/ies/modulos/modulo[ciclo=$ciclo]"

instead of

select="/ies/modulos/modulo/[ciclo=$ciclo]"
                           ^

as your attempt is not correct XPath syntax.

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