问题
Given following 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>
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!
回答1:
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>
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.
来源:https://stackoverflow.com/questions/19133038/xslt-1-0-max-value-of-a-date-node