【问题标题】:xsl:for-each does not loop inner elementsxsl:for-each 不循环内部元素
【发布时间】:2015-04-19 17:16:14
【问题描述】:

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>

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

【问题讨论】:

  • 你写的是authors,你的意思可能是author

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


【解决方案1】:

您正在选择 foreach 中的每个 authors 标记。您应该选择author。赞&lt;xsl:for-each select="authors/author"&gt;

【讨论】:

    【解决方案2】:

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-11-02
      • 2012-10-22
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多