XSL if test starts-with [英] XSL if test starts-with

查看:23
本文介绍了XSL if test starts-with的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

给定这段 XML

<dc:date>info:eu-repo/date/embargoEnd/2013-06-12</dc:date>
<dc:date>2012-07-04</dc:date>

我应该需要使用 XSL 仅输出字符串不以开头的年份 info:eu-repo.我正在尝试这种方式,但它不起作用.我对 for-each 的理解有误?

I should need with XSL to output only the year of the string not starting with info:eu-repo. I'm trying this way, but it doesn't work. I'm wrong with the 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>

推荐答案

我猜你不需要 ' 在你的 start-with 查询中,你可能想要以稍微不同的方式迭代日期:

I guess you don't need ' in your start-with query, and you may want to iterate over dates slightly differently:

    <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>

这篇关于XSL if test starts-with的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆