Jump to content

xpath


silverbux
 Share

Recommended Posts

It depends. Will that maxum number always be equal to the number of <records> elements? If so, then it's simple:

records[id=count(../records)]

Link to comment
Share on other sites

This will return the max (or min if you change the order to 'ascending') using XSLT

<xsl:for-each select="//records/id">	<xsl:sort select="." data-type="number" order="descending"/>	<xsl:if test="position()=1">		<xsl:value-of select="."/><br/>	</xsl:if>	</xsl:for-each>

Link to comment
Share on other sites

no the <id> is auto generated like auto increment in mysql.
My point was if the highest ID is always the same as the amount of elements. The answer to this question would have been "no" if a possible look of your document was:
<test><records><id>1</id></records><records><id>3</id></records><records><id>2</id></records><records><id>5</id></records><records><id>6</id></records></test>

The number of <records> is 5, but the highest ID is 6. So my above XPath expression wouldn't have worked properly scince it would return 5 instead of 6.However, you say that this ID is automatically incremented for every new element, right? In that case, the above situation will be impossible, and thus, my suggested expression will do the trick.aalbetski's idea is good too, if you don't mind the extra lines, for the sake of a single value.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...