cancel
Showing results for 
Search instead for 
Did you mean: 

pick latest date from all the dates

Former Member
0 Kudos

Hi Friends,

My requirement is like this.

for one employee id there are multiple check dates. what i need is i will get latest check date in the output. please tell me logic

i am using java XSLT.

plz help me out. ponts also rewarded.

Thanks

Anil M

Accepted Solutions (1)

Accepted Solutions (1)

udo_martens
Active Contributor
0 Kudos

Hi Anil,

take this as example:

XML:

<?xml version="1.0" encoding="UTF-8"?>
<root>
	<datum>20081231</datum>
	<datum>20081201</datum>
                <datum>20080101</datum>
</root>

And the stylesheet:

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
	<xsl:template match="*">
		<root>
			<xsl:for-each select="//datum">
				<xsl:sort order="descending" select="."/>
				<xsl:if test="position()=1">
					<xsl:copy-of select="."/>
				</xsl:if>
			</xsl:for-each>
		</root>
	</xsl:template>
</xsl:stylesheet>

will give you the result:

<?xml version="1.0" encoding="UTF-8"?>
<root>
	<datum>20081231</datum>
</root>

Regards,

Udo

Former Member
0 Kudos

Hi Udo,

what is your message type? I didnt find any message type in the code.can you please elobrate the solution.

Thanks

Anil.M

Former Member
0 Kudos

Hi Udo,

what ever the code you provided for me was counting all dates in the file and display the latest one.

but i need in one record i have more than 2 to 3 date fields, among that i need latest one.

Thanks

Anil M

VijayKonam
Active Contributor
0 Kudos

Hi,

You can not expect one to give complete solution here. Udo has given proper example. It is up to you to change it according to your requirements. The way he mentioned the diffrent dates is considering they are in different records. Assume that they are in the same record and try to modify the code.

Or write an udf which take the entire context of the dates and returns you the max number (Convert date to yyyymmdd format) and then return this to the target.

VJ

udo_martens
Active Contributor
0 Kudos

Hi Anil,

the stylesheet picks the latest datum of my test xml, definitively.

Of course your xml might look a bit different, therefore you have to adapt the stylesheet for your challenge. If this is too much for you you could post your xml. In general it is not bad to provide the requirements by posting questions.

Regards,

Udo

Answers (0)