xsl:for-each不循环内部元素

时间:2015-04-19 17:16:15

标签: xml xslt xml-parsing xslt-1.0 xslt-2.0

XML

    <authors>
        <author url="http://dl.acm.org/">Chung-Hwan Lim</author>
        <author url="http://dl.acm.org/">Seog Park</author>
        <author url="http://dl.acm.org/">Sang H. Son</author>
    </authors>

XSLT

<div class="authors">
    <xsl:for-each select="authors">
        <a style="vertical-align:middle">
            <xsl:attribute name="href">
                <xsl:value-of select="@url"/>
            </xsl:attribute>
            <xsl:value-of select="."/>
        </a>
    </xsl:for-each>
</div>

O / P

   <div class="authors"><a style="vertical-align:middle" href="">
                Chung-Hwan Lim
                Seog Park
                Sang H. Son
            </a></div>

问题是我期待三个<a>标签,但我只得到一个。这是为什么?为什么`xsl:for-each'不循环内部元素?我该如何解决这个问题?

2 个答案:

答案 0 :(得分:2)

如果您要处理author元素,则需要select="authors/author"

答案 1 :(得分:2)

您正在选择foreach中的每个authors标记。您应该选择author。与<xsl:for-each select="authors/author">

一样