XML和XSL参考。我该怎么做?

时间:2019-12-13 18:30:12

标签: xml xslt

自从我被要求输入xslt以来,我已经编辑了代码。我真的不知道该怎么做,我尝试了C:

我现在正在尝试用xsl列出我创建的学生名单。 问题是...我在xml中有ID,指的是我需要的东西。

但是现在我想按XSL列出所有学生的学历(学习名称)...。即使如此,我也不知道它在XSL中如何工作...

请帮助:) 这是代码的一部分:

    <student>
        <info name="Layla Engles" birthday="01-06-1995" number="12345" />
        <studyinginformation refid="s1" />
    </student>
    <student>
        <info name="Ann Thai" birthday="03-02-1992" number="12344" />
        <studyinginformation refid="s2" />
    </student>
    <student>
        <info name="Laira Moorse" birthday="11-10-1999" number="12343" />
        <studyinginformation refid="s2" />
    </student>

如您所见,我参考的是学习信息。

    <studyinfos>
    <studyinginformation id="s1" name="Medicine" faculty="1"/>
    <studyinginformation id="s2" name="Computer Science" faculty="4"/>
    </studyinfos>

Xslt:

<xsl:output method="html"/>
<xsl:template match="/">
    <head> 
        <title><xsl:value-of select="./titel"/></title> 
    </head>
    <body>  
             <xsl:apply-templates select="studies"  />  
       <h1><xsl:value-of select="./titel"/></h1>
       <h2 id="headtext"></h2>
        <table border="1" id="designtable" bgcolor="#b3b3b3">
            <tr>
                <th>Name of Subject</th>
                <th>Faculty</th>
                <th>Student</th>
            </tr>
            <xsl:call-template name="students">
                <xsl:with-param name="sorted">Student</xsl:with-param>
            </xsl:call-template>
            <xsl:apply-templates select="sort_students"/>
        </table>   
    </body>
</xsl:template>
<xsl:template name="students">
    <xsl:param name="sorted"/>  
    <xsl:for-each select="//studyinfos/studyinformation[$sorted='Student']">
        <xsl:call-template name="output_studyinformation"/>
    </xsl:for-each>
</xsl:template>
<xsl:template name="output_studyinformation">
    <tr>
        <td>

            <div class="university_subjectname">
                <xsl:value-of select="./@name"/>
            </div>
        </td>
        <td>
            <xsl:value-of select="./@faculty"/>


        </td>
            <xsl:call-template name="output_Students">
                <xsl:with-param name="sorted">Try</xsl:with-param>
            </xsl:call-template>    
    </tr>
</xsl:template>
    <xsl:template name="output_Students" >
    <xsl:param name="sorted"/>  
    <td class="StudentSort">
        <xsl:choose>
            <xsl:when test="$sorted='Try'">
                <xsl:for-each select="//students/student">
                <br><xsl:value-of select="./info/@name"/></br>
                </xsl:for-each>
            </xsl:when>
        </xsl:choose>       
    </td>   
</xsl:template>

所有操作都有效,仅最后一部分是有问题的。我需要以某种方式使学生与学习信息进行交流。我就是不知道 现在的输出是所有学生都对所有学科都感兴趣。 如果这是一个奇怪的代码,我感到非常抱歉,这是我第一次尝试这样的事情……

0 个答案:

没有答案