简体   繁体   English

如何从xml元素检索属性的值

[英]How can I retrieve the value of an attribute from a xml element

I want to know how I can retrive the url in "supervisor" to use it as a link. 我想知道如何在“主管”中检索URL并将其用作链接。 I have this xml file. 我有这个xml文件。

<pr>
<meta>
    <id>AAAAAAAAAAAA</id>
    <title>AAAAAAAA</title>
    <subtitle>BBBBB</subtitle>
    <bdate>OCCCCCCCC</bdate>
    <edate>DDDDDDDDDD</edate>
    <supervisor url="http://wwww.teacherwWEbpage.com">teacher NAME 
 </meta>
 </pr>
</meta>
<team>
    <student>
        <name>Rhghfghf</name>
        <nr>fghfgh5</nr>
        <email>hgghfht</email>
    </student>
</team>
<abstract>
</abstract>
<deliverables>
    <deliverable url="."></deliverable>
</deliverables>

And this xsl, im trying to put the XML information on a table, which is fine, but now I'm unable to set the teachers name as a link to the address in the url attribute... 这个xsl,我试图将XML信息放在一个表上,这很好,但是现在我无法将教师姓名设置为url属性中地址的链接...

How can I use that attribute as the link on the resultant HTML file? 如何使用该属性作为结果HTML文件上的链接?

</supervisor>
</meta>
<team>
    <student>
        <name>hrhshs</name>
        <nr>48648</nr>

    <xsl:template match="/">
    <html>
        <head>
            <meta charset="UTF-8"></meta>
        </head>
        <body>
            <h1 align="center"> Projecto Record</h1>
            <xsl:apply-templates/>
        </body>
    </html>
</xsl:template>

<xsl:template match="meta">
    <table>
        <tr  >
            <td width="50%"><b>name key:</b><xsl:value-of select="id"/></td>
            <td><b>Begin date:</b><xsl:value-of select="bdate"/></td>
        </tr>
        <tr>
            <td><b>Title:</b><xsl:value-of select="title"/></td>
            <td><b>End date:</b><xsl:value-of select="edate"/></td>
        </tr>
        <tr>
            <td><b>Subtitle:</b><xsl:value-of select="subtitle"/></td>
            <td><b>Supervisor:</b><a href="./supervisor/{@url}" ><xsl:value-of select="supervisor"/> </a></td>
        </tr>

    </table>
</xsl:template>

您与当前的尝试相距不远,但是您想要的语法是...

<a href="{supervisor/@url}" >

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

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