silverbux Posted October 13, 2006 Share Posted October 13, 2006 <test> <records> <id>1</id> </records> <records> <id>3</id> </records> <records> <id>2</id> </records> </test>is there a way to select the maximum <id> ?? thank you in advance Link to comment Share on other sites More sharing options...
boen_robot Posted October 13, 2006 Share Posted October 13, 2006 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 More sharing options...
silverbux Posted October 16, 2006 Author Share Posted October 16, 2006 no the <id> is auto generated like auto increment in mysql. Link to comment Share on other sites More sharing options...
aalbetski Posted October 16, 2006 Share Posted October 16, 2006 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 More sharing options...
boen_robot Posted October 17, 2006 Share Posted October 17, 2006 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 More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now