xml - How to get maximum value under same node in xslt -


i have xml below :

<report xmlns:xsi="http://www.w3.org/2001/xmlschema-instance" xmlns:xsd="http://www.w3.org/2001/xmlschema">   <name>hourlyreport</name>   <id>8</id>   <totalresults>1</totalresults>   <totalpages>1</totalpages>   <items>     <item>       <id>1</id>       <hour0>23</hour0>       <hour1>12</hour1>       <hour2>7</hour2>       <hour3>18</hour3>       <hour4>32</hour4>       .       .       .       <hour20>28</hour20>       <hour21>39</hour21>       <hour22>51</hour22>       <hour23>49</hour23>     </item>   </items> </report> 

i need maximum value above xml using xslt . in above case maximum value 51. how can that? possible maximum value in xslt variable, can use else. not getting way. can use xslt version 1.0 or 2.0 .

given xslt 2.0 should suffice use

<xsl:variable name="max" select="max(/report/items/item/*[starts-with(local-name(), 'hour')]/xs:integer(.)"/> 

(where stylesheet need declare xmlns:xs="http://www.w3.org/2001/xmlschema").

and xslt 1.0 sort , take maximum value in

<xsl:variable name="max">   <xsl:for-each select="/report/items/item/*[starts-with(local-name(), 'hour')]">     <xsl:sort select="." data-type="number" order="descending"/>     <xsl:if test="position() = 1"><xsl:value-of select="."/></xsl:if>   </xsl:for-each> </xsl:variable> 

Comments

Popular posts from this blog

basic authentication with http post params android -

vb.net - Virtual Keyboard commands -

css - Firefox for ubuntu renders wrong colors -