XSL如果测试开始 - 用

rob*_*ing 9 xslt xpath xpath-2.0

鉴于这篇XML

<dc:date>info:eu-repo/date/embargoEnd/2013-06-12</dc:date>
<dc:date>2012-07-04</dc:date>
Run Code Online (Sandbox Code Playgroud)

我需要使用XSL只输出字符串的年份而不是以 info:eu-repo.我正在尝试这种方式,但它不起作用.我错了for-each

<xsl:if test="not(starts-with('dc:date', 'info:eu-repo'))">
                <xsl:for-each select="dc:date">
                    <publicationYear>
                        <xsl:variable name="date" select="."/>
                        <xsl:value-of select="substring($date, 0, 5)"/>
                    </publicationYear>
                </xsl:for-each>
</xsl:if>
Run Code Online (Sandbox Code Playgroud)

DRC*_*RCB 19

我猜您'start-with查询中不需要,并且您可能希望以稍微不同的方式迭代日期:

    <xsl:for-each select="dc:date">
         <xsl:variable name="date" select="."/>
         <xsl:if test="not(starts-with($date, 'info:eu-repo'))">
                <publicationYear>
                    <xsl:value-of select="substring($date, 0, 5)"/>
                </publicationYear>
        </xsl:if>
    </xsl:for-each>
Run Code Online (Sandbox Code Playgroud)

  • 请注意,您可以将条件**xsl:if**与**xsl:for-each**本身结合起来以简化操作....`<xsl:for-each select ="dc:date [not(starts) -with(.,'info:eu-repo'))]">` (3认同)