XSLT 1.0:日期节点的最大值 [英] XSLT 1.0: max value of a date node

查看:70
本文介绍了XSLT 1.0:日期节点的最大值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

给出以下xml:

<Ergebnisse>
    <Spiel>
        <Datum>2013-10-02</Datum>
    </Spiel>
    <Spiel>
        <Datum>2013-10-03</Datum>
    </Spiel>
    <Spiel>
        <Datum>2013-10-03</Datum>
    </Spiel>
    <Spiel>
        <Datum>2013-10-03</Datum>
    </Spiel>
    <Spiel>
        <Datum>2013-10-06</Datum>
    </Spiel>
    <Spiel>
        <Datum>2013-10-06</Datum>
    </Spiel>
    <Spiel>
        <Datum>2013-10-06</Datum>
    </Spiel>
    <Spiel>
        <Datum>2013-10-06</Datum>
    </Spiel>
    <Spiel>
        <Datum>2014-05-01</Datum>
    </Spiel>
    <Spiel>
        <Datum>2014-05-01</Datum>
    </Spiel>
    <Spiel>
        <Datum>2014-04-27</Datum>
    </Spiel>
</Ergebnisse>

现在我需要知道,这是基准"中的最高日期值.我正在使用Python和lxml,所以我只能使用Xpath 1.0. 我试过了:

Now I need to know, which is the highest date-value in "Datum". I'm using Python and lxml, so I can only work with Xpath 1.0. I tried:

//Spiel[not (Datum < preceding::Spiel/Datum) and not (Datum < following::Spiel/Datum)]/Datum

,但它返回所有值.我能做些什么? 谢谢!

but it returns all values. What can I do? Thanks!

推荐答案

在XSLT 1.0中,您可以对值进行排序并取最后一个.

In XSLT 1.0 you can sort the values and take the last.

<xsl:for-each select="Speil/Datum">
  <xsl:sort select="."/>
  <xsl:if test="position()=last()"><xsl:value-of select="."/></xsl:if>
</xsl:for-each>

我不会仅在XPath中尝试它-如果您拥有XPath 1.0,请返回所有值并以Python宿主语言进行提取.

I wouldn't attempt it in XPath alone - if XPath 1.0 is all you have, return all the values and do the extraction in the Python host language.

这篇关于XSLT 1.0:日期节点的最大值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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