如何为此 xml 创建一个 xslt & 输出是 table with column{name Inscription,nom,prenom,nom Module} & condition etudiant.id_promo=module.id_prom

how to creat an xslt for this xml & the output is table with culomn{numInscription,nom,prenom,nomModule} & condition etudiant.id_promo=module.id_prom

在这里我需要每个学生他的模块摸索 id_promo 但是 我不知道 for each with condition 和 loop in loop

的语法

<?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"
    exclude-result-prefixes="xs"
    version="2.0">
    <xsl:template match="/">
        <html>
            <head>
                
            </head>
            <body>
                <h1>Liste des Etudiants et les module de promo</h1> 
                <ul>
                    <table width="80%" border="1px" cellpadding="10px" cellspacing="0px">
                        <thead>
                            <th>num_et</th><th>nom_et</th><th>prenom_et</th><th>nom_mod</th><th>id_mod</th>
                            
                            
                        </thead>
                        <tbody>
                     
                            
                            <xsl:for-each select="promotion/etudiants/etudiant">
                                
                      
                                <tr>
                                    
                                    <td><xsl:value-of select="@num_et"/></td> 
                                    <td><xsl:value-of select="@nom_et"/></td> 
                                    <td><xsl:value-of select="@prenom_et"/></td>
                            
                                 </tr>     
                                  
                                
                            </xsl:for-each>
                            
                            
                        </tbody>
                    </table>
                </ul>
            </body>
        </html>   
    </xsl:template>
</xsl:stylesheet>

<?xml version="1.0" encoding="iso-8859-1"?> 
<promotion option="MGL" niveau="2" > 
<etudiants>   
  <etudiant numInscription="3666" nom="X" prenom="Y" id_promo="1"/> 
   .....
   ......
</etudiants> 
<modules> 
 <module idModule="E200" nomModule="Web 2.0" id_promo="1"/> 
 <module idModule="E222" nomModule="Web 3.0" id_promo="1"/> 
  ...... 
  ...... 
</modules> 
</promotion> 
在这里我需要每个学生他的模块摸索 id_promo 我不知道语法 id_promo 需要将拖车 table 合二为一 table


Name prename module
X Y Web 2.0
Web 3.0

试试这样的东西:

XSLT 1.0

<xsl:stylesheet version="1.0" 
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

<xsl:key name="module" match="module" use="@id_promo" />

<xsl:template match="/promotion">
    <html>
        <head/>
        <body>
            <h1>Liste des Etudiants et les module de promo</h1> 
            <table border="1">
                <thead>
                    <th>num_et</th>
                    <th>nom_et</th>
                    <th>prenom_et</th>
                    <th>nom_mod</th>
                    <th>id_mod</th>
                </thead>
                <tbody>
                    <xsl:for-each select="etudiants/etudiant">
                        <xsl:variable name="etudiant" select="." />
                        <xsl:for-each select="key('module', @id_promo)">
                            <tr>
                                <xsl:choose>
                                    <xsl:when test="position() =1">
                                        <td>
                                            <xsl:value-of select="$etudiant/@numInscription"/>
                                        </td> 
                                        <td>
                                            <xsl:value-of select="$etudiant/@nom"/>
                                        </td> 
                                        <td>
                                            <xsl:value-of select="$etudiant/@prenom"/>
                                        </td>
                                    </xsl:when>
                                    <xsl:otherwise>
                                        <td/><td/><td/>
                                    </xsl:otherwise>
                                </xsl:choose>
                                <td>
                                    <xsl:value-of select="@nomModule"/>
                                </td> 
                                <td>
                                    <xsl:value-of select="@idModule"/>
                                </td>
                            </tr>     
                        </xsl:for-each>
                    </xsl:for-each>
                </tbody>
            </table>
        </body>
    </html>   
</xsl:template>

</xsl:stylesheet>

将其应用于以下示例输入时:

XML

<promotion option="MGL" niveau="2">
  <etudiants>
    <etudiant numInscription="3666" nom="X" prenom="Y" id_promo="1" />
    <etudiant numInscription="3667" nom="X" prenom="O" id_promo="2" />
  </etudiants>
  <modules>
    <module idModule="E200" nomModule="Web 2.0" id_promo="1" />
    <module idModule="E222" nomModule="Web 3.0" id_promo="1" />
    <module idModule="E223" nomModule="Web 3.1" id_promo="2" />
  </modules>
</promotion>

结果将是:

HTML

<html>
   <head>
      <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
   </head>
   <body>
      <h1>Liste des Etudiants et les module de promo</h1>
      <table border="1">
         <thead>
            <th>num_et</th>
            <th>nom_et</th>
            <th>prenom_et</th>
            <th>nom_mod</th>
            <th>id_mod</th>
         </thead>
         <tbody>
            <tr>
               <td>3666</td>
               <td>X</td>
               <td>Y</td>
               <td>Web 2.0</td>
               <td>E200</td>
            </tr>
            <tr>
               <td></td>
               <td></td>
               <td></td>
               <td>Web 3.0</td>
               <td>E222</td>
            </tr>
            <tr>
               <td>3667</td>
               <td>X</td>
               <td>O</td>
               <td>Web 3.1</td>
               <td>E223</td>
            </tr>
         </tbody>
      </table>
   </body>
</html>

渲染