为xml文件创建个性化样式表

时间:2017-04-23 06:52:20

标签: xml xslt

我有xml文件,看起来像

<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" href="jats-html.xsl"?>
<article article-type="proceedings">
    <front>
        <journal-meta>
            <journal-id journal-id-type="publisher-id"/>
        </journal-meta>
        <article-meta>
            <article-id pub-id-type="doi">10.1117/12.2049309</article-id>
            <title-group>
                <article-title>POLARIZATION-INDUCED ANGULAR MOMENTUM OF ARBITRARY LIGHT-SCATTERING PARTICLE</article-title>
            </title-group>
            <contrib-group>
                <contrib contrib-type="author">
                    <name>
                        <surname>Sakhnovskii</surname>
                        <given-names>M.Yu.</given-names>
                    </name>
                </contrib>
                <contrib contrib-type="author">
                    <name>
                        <surname>Rudeychuk</surname>
                        <given-names>V.M.</given-names>
                    </name>
                </contrib>
                <contrib contrib-type="author" corresp="yes">
                    <name>
                        <surname>Polyanskii</surname>
                        <given-names>P.V.</given-names>
                    </name>
                </contrib>
            </contrib-group>
        </article-meta>
    </front>
</article>

我希望以表格格式查看给定的姓名和姓氏。我是XSLT的新手,下面是我制作的样式表,但它不起作用。

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    <xsl:template match="/">
        <html>
            <head>
                <title>Sample</title>
            </head>
            <body>
                <table border="1">
                    <tr bgcolor="#9acd32">
                        <th>Name</th>
                        <th>Surname</th>
                    </tr>
                    <xsl:for-each select="article/front/article-meta/contrib-group/contrib">
                        <tr bgcolor="red">
                            <td><xsl:value-of select="given-names"/></td>
                            <td><xsl:value-of select="surname"/></td>
                        </tr>
                    </xsl:for-each>
                </table>
            </body>
        </html>

    </xsl:template>
</xsl:stylesheet>

有人能告诉我xsl文件有什么问题吗? 预期输出类似于expected output

我得到的实际结果是 actual output

1 个答案:

答案 0 :(得分:0)

  

有谁能告诉我xsl文件中有什么问题?

您在选择中缺少位置步骤。变化:

<xsl:for-each select="article/front/article-meta/contrib-group/contrib">

为:

<xsl:for-each select="article/front/article-meta/contrib-group/contrib/name">